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:
| function LoadRemoteLibrary(Process: THandle; FileName: LPCTSTR): HMODULE; var Size: DWORD; Buffer: Pointer; Written: DWORD; Thread: THandle; ThreadId: DWORD; begin Result := 0; Size := (lstrlen(FileName) + 1) * SizeOf(FileName[0]); Buffer := VirtualAllocEx(Process, nil, Size, MEM_COMMIT, PAGE_READWRITE); if Assigned(Buffer) then try if WriteProcessMemory(Process, Buffer, Addr(FileName[0]), Size, Written) and (Written >= Size) then begin Thread := CreateRemoteThread(Process, nil, 0, TFNThreadStartRoutine( {$IFDEF UNICODE} GetProcAddress(GetModuleHandle(kernel32), 'LoadLibraryW') {$ELSE} GetProcAddress(GetModuleHandle(kernel32), 'LoadLibraryA') {$ENDIF} ), Buffer, 0, ThreadId); if Thread <> 0 then try WaitForSingleObject(Thread, INFINITE); GetExitCodeThread(Thread, Result); finally CloseHandle(Thread); end; end; finally VirtualFreeEx(Process, Buffer, Size, MEM_RELEASE); end; end; |