I have an old injector that I made in Delphi 7, and I tried to change it so that it still works in XE2, but I failed. - The new test DLL works with my old injector without problems, so I'm sure that my injector has an error.
here is the code i made:
procedure TForm1.InjectDLL(const ADLLName: String; targetproc: Cardinal); var dllname: String; pDLLname, pStartAddr: Pointer; bw: NativeUInt; hProcess, hRemoteThread: THandle; TID: Cardinal; begin hProcess := OpenProcess(PROCESS_ALL_ACCESS, false, targetproc); pDLLname := VirtualAllocEx(hProcess, 0, length(dllname) + 1, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE); WriteProcessMemory(hProcess, pDLLname, Pointer(dllname), length(dllname) + 1, bw); pStartAddr := GetProcAddress(GetModuleHandle('kernel32.dll'), 'LoadLibraryA'); hRemoteThread := CreateRemoteThread(hProcess, nil, 0, pStartAddr, pDLLname, 0, TID); WaitForSingleObject(hRemoteThread, INFINITE); showmessage('Fehler ' + IntToStr(GetLastError) + ': ' + SysErrorMessage(GetLastError)); CloseHandle(hProcess); end;
I just needed to change hProcess and hRemoteThread to THandle and bw to NativeUInt. The show just tells me that everything works. There should be a slight difference as the String type has changed from d7 to XE2. I also tried using the dll name as PAnsiChar, but that didn't change anything for me.
I hope that I have posted enough information for you.
source share