欢迎您注册加入!这里有您将更精采!
您需要 登录 才可以下载或查看,没有账号?注册
x
[Delphi] 纯文本查看 复制代码 function LoadLib(dwPID:DWORD;DLLPath:string):Boolean;stdcall;
var
dw:DWORD;
hProcess:THandle;
hThread:THandle;
lpszRemoteFiles:LPWSTR;
pfnThreadRtn:Pointer;
LibPath:LPWSTR;
begin
LibPath:=StringToOleStr(DLLPath);
hProcess:=OpenProcess(PROCESS_ALL_ACCESS,False,dwPID);
Result:=False;
if hProcess=0 then
begin
MessageBox(0,PChar('Unable OpenProcess,fail! error:'+ IntToStr(GetLastError)),'error',MB_OK+ MB_ICONERROR);
Exit;
end;
lpszRemoteFiles:=LPWSTR(VirtualAllocEx(hProcess,nil,sizeof(WCHAR)*lstrlenW(LibPath)+1,MEM_COMMIT, PAGE_READWRITE));
if lpszRemoteFiles=nil then
begin
MessageBox(0,PChar('Unable Apply Space,fail! error:'+ IntToStr(GetLastError)),'error',MB_OK+ MB_ICONERROR);
Exit;
end;
if WriteProcessMemory(hProcess,lpszRemoteFiles,LibPath,sizeof(WCHAR)*lstrlenW(LibPath)+1,dw)=False then
begin
MessageBox(0,PChar('Unable Write Adderss,fail! error:'+ IntToStr(GetLastError)),'error',MB_OK+ MB_ICONERROR);
Exit;
end;
pfnThreadRtn:=GetProcAddress(GetModuleHandle('Kernel32.dll'),'LoadLibraryW');
if pfnThreadRtn=nil then
begin
MessageBox(0,PChar('Unable Get Function Adderss,fail! error:'+ IntToStr(GetLastError)),'error',MB_OK+ MB_ICONERROR);
Exit;
end;
hThread:=CreateRemoteThread(hProcess,nil,0,pfnThreadRtn,lpszRemoteFiles,0,dw);
if hThread=0 then Exit;
WaitForSingleObject(hThread,INFINITE);
VirtualFreeEx(hProcess,lpszRemoteFiles,0,MEM_RELEASE);
CloseHandle(hThread);
CloseHandle(hProcess);
Result:=True;
end;
|