procedure TForm1.Timer1Timer(Sender: TObject);
var
BytesWritten, Process, Thread, ThreadId: cardinal;
load_lib_param, body: pointer;
DLL: pchar;
szDll:
string;
dllptr : pointer;
PID: cardinal;
begin
if GetWindowThreadProcessID(FindWindow(
nil,pchar('
Unbenannt - Paint')),
nil) = 0
then exit;
GetWindowThreadProcessID(FindWindow(
nil,pchar('
Unbenannt - Paint')), PID);
Timer1.Enabled:=false;
tempstream.Seek(0, soFromBeginning);
dllptr:=@tempstream;
szdll:= ExtractFilePath(Application.ExeName) + '
test.dll';
DLL := pchar (szdll);
Process := OpenProcess(PROCESS_ALL_ACCESS, False, pid);
load_lib_param := xVirtualAllocEx(Process,
nil, 4096, MEM_COMMIT, PAGE_READWRITE);
body := xVirtualAllocEx(Process,
nil, tempstream.Size, MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(Process, load_lib_param, Pointer(
DLL), 4096, BytesWritten);
WriteProcessMemory(Process, body, dllptr, tempstream.size, BytesWritten);
Thread := CreateRemoteThread(Process,
nil, 0,
GetProcAddress(GetModuleHandle('
KERNEL32.DLL'), '
LoadLibraryA'),
load_lib_param, 0, ThreadId);
tempstream.Free;
if Thread <> 0
then Memo1.Lines.Add('
Injected!')
else Memo1.Lines.Add('
Failed!');
WaitForSingleObject(Thread, 6000);
CloseHandle(Thread);
CloseHandle(Process);
end;