apoer 发表于 2009-10-29 14:51:56

自己写的一个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;

**** Hidden Message *****

mqcoo 发表于 2010-8-11 17:33:17

学无止境。{:3_41:}

hzjzq2000 发表于 2010-8-12 10:51:06

不知道我能用不

花心胡萝卜 发表于 2010-10-6 11:22:15

来学习下,嘿嘿

anplando 发表于 2010-10-23 12:59:35

感谢分享,好东西

a2331975 发表于 2010-10-29 20:53:20

学习学习!!~~~~再感谢下LZ

hanhunhan 发表于 2010-11-7 14:24:48

不错的东西 嘻嘻

wtyi 发表于 2011-1-23 17:55:49

这个不错 很强大
页: [1]
查看完整版本: 自己写的一个delphi远线程注入函数