procedure InjectDll(PID: dword;
DLL: pChar);
var
BytesWritten, hProcess, hThread, TID: Cardinal;
Parameters: pointer;
pThreadStartRoutine: Pointer;
begin
hProcess := OpenProcess(PROCESS_ALL_ACCESS, False, PID);
Parameters := VirtualAllocEx( hProcess,
nil, Length(
DLL), MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hProcess,Parameters,Pointer(
DLL),Length(
DLL),BytesWritten);
pThreadStartRoutine := GetProcAddress(GetModuleHandle('
KERNEL32.DLL'), '
LoadLibraryA');
hThread := CreateRemoteThread(Process,
nil, 0, pThreadStartRoutine, Parameters, 0, TID);
CloseHandle(hProcess);
end;