1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54:
| function Inject: boolean; var ProcessID : Integer; hProcess : THandle; DLLPath : string; pDLLPath : Pointer; BytesWritten : Cardinal; ThreadID : Cardinal; ThreadHandle: THandle; ExitCode: Cardinal; begin Result:= false; DLLPath:= 'C:\Users\Guest\Desktop\Message Box.dll';
ProcessID:= GetProcessID('notepad.exe'); if ProcessID <> 0 then begin hProcess:= GetProcessHandleFromID(ProcessID); if hProcess <> 0 then begin pDLLPath:= VirtualAllocEx(hProcess, nil, Length(DLLPath), MEM_COMMIT, PAGE_EXECUTE_READWRITE); if not Assigned(pDLLPath) then begin Result:= false; exit; end; end else begin Result:= false; exit; end; end else begin Result:= false; exit; end;
if WriteProcessMemory(hProcess, pDLLPath, PChar(DLLPath), Length(DLLPath), BytesWritten) then begin ThreadHandle:= CreateRemoteThread(hProcess, nil, 0, GetProcAddress(GetModuleHandle('kernel32.dll'), 'LoadLibraryA'),pDLLPath, 0, ThreadID); if (ThreadHandle > 0) then begin WaitForSingleObject(ThreadHandle,INFINITE); GetExitCodeThread(ThreadHandle,ExitCode); CloseHandle(ThreadHandle); ThreadHandle:= CreateRemoteThread(hProcess,nil,0,GetProcAddress(GetModuleHandle('kernel32.dll'),'FreeLibrary'), Pointer(ExitCode), 0, ThreadID); if (ThreadHandle > 0) then CloseHandle(ThreadHandle); end; end; end; |