我正在使用此代码注入我的64位DLL进入64位进程在Windows 7 64位,CreateRemoteThread返回200但仍然没有注入DLL,我测试我的DLL与另一个来源,它工作正常,进程资源管理器显示我的代码不起作用,这个代码有什么问题,我使用delphi XE3,我已经在64位目标平台上编译代码。德尔福XE3 DLL注入64位DLL到64位进程不起作用
function InjectDLL(dwPID: DWORD; DLLPath: pwidechar): integer;
var
dwThreadID: Cardinal;
hProc, hThread, hKernel: NativeUInt;
BytesWritten: NativeUInt;
pRemoteBuffer, pLoadLibrary: Pointer;
begin
try
hProc := OpenProcess(PROCESS_ALL_ACCESS, False, dwPID);
if hProc = 0 then
begin
Result := 0;
Exit;
end;
pRemoteBuffer := VirtualAllocEx(hProc, nil, Length(DLLPath) + 1, MEM_COMMIT,
PAGE_READWRITE);
if pRemoteBuffer = nil then
begin
Result := 0;
Exit;
end;
if WriteProcessMemory(hProc, Pointer(pRemoteBuffer), lpvoid(DLLPath),
Length(DLLPath) + 1, BytesWritten) = False then
begin
Result := 0;
Exit;
end;
hKernel := GetModuleHandle(pwidechar('kernel32.dll'));
pLoadLibrary := (GetProcAddress(hKernel, pansichar('LoadLibraryA')));
hThread := CreateRemoteThread(hProc, Pointer(nil), 0, Pointer(pLoadLibrary),
Pointer(pRemoteBuffer), 0, dwThreadID);
WaitForSingleObject(hThread, INFINITE);
VirtualFreeEx(hProc, Pointer(pRemoteBuffer), Length(DLLPath) + 1,
MEM_RELEASE);
CloseHandle(hThread);
CloseHandle(hProc);
// ShowMessage(IntToStr(hThread)+' '+ inttostr(dwThreadID));
Result := 1;
except
on d: exception do
begin
end;
end;
end;
@ hvd我看不到任何代码可以引发异常。这些只是一堆WinAPI调用,不会引发。 –
@DavidHeffernan你确定吗?我不会为'EAccessViolation'异常感到惊讶。 – hvd
@ hvd您打算在哪里调用哪个API来提升AV? –