delphi 注入指定进程


本文整理自网络,侵删。

 {delphi 注入指定进程。 }
function InjectToSpecificProcess(AProcess: string): BOOLEAN;
var
Module, NewModule: Pointer;
Size, BytesWritten, TID, PID: LongWord;
ProcessHandle: LongWord;
hRemoteThread: Cardinal;
begin
Module := Pointer(GetModuleHandle(0)); //这句偶尔会出错。获得自身模块句柄
Size := PImageOptionalHeader(Pointer(Integer(Module) +
PImageDosHeader(Module)._lfanew + SizeOf(DWORD) +
SizeOf(TImageFileHeader))).SizeOfImage;

//GetWindowThreadProcessId(FindWindow('Shell_TrayWnd', nil), @PID);
//ProcessHandle为需要注入的进程 PID
PID := GetProcessIDFromExename(AProcess);
ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, False, PID); //打开进程

VirtualFreeEx(ProcessHandle, Module, 0, MEM_RELEASE);
NewModule := VirtualAllocEx(ProcessHandle, Module, Size, MEM_COMMIT or
MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if NewModule <> nil then
begin
WriteProcessMemory(ProcessHandle, NewModule, Module, Size,
BytesWritten);
//远程打开进程,传递注入函数入口地址@CodeToRunAfterInjection
hRemoteThread := CreateRemoteThread(ProcessHandle, nil, 0,
@CodeToRunAfterInjection,
Module, 0, TID);
if BOOLEAN(hRemoteThread) then Result := True else Result := False;
end else
Result := False;
CloseHandle(ProcessHandle); //关闭线程句柄
end;

相关阅读 >>

Delphi android-api 开发常用函数

Delphi 取得当前运行窗口的标题

Delphi 官方 processmessages 用法代码例子

Delphi winapi: windowfrompoint- 获取指定点所在窗口的句柄

Delphi android应用程序的关闭退出

Delphi tstream 详细介绍

Delphi中使用ado连接带密码的access

Delphi 解决“richedit line insertion error”错误

Delphi dblookupcombobox组件的使用方法

Delphi 判断端口(port)是否被占用

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...