function AttachToProcess(const HostFile, GuestFile: string; const PID: DWORD = 0): DWORD;
var
hRemoteProcess: THandle;
dwRemoteProcessID,cb: DWORD;
pszLibFileRemote: Pointer;
iReturnCode: Boolean;
TempVar: DWORD;
pfnStartAddr: TFNThreadStartRoutine;
pszLibAFilename: PwideChar;
begin
Result := 0;
EnabledDebugPrivilege(True);
Getmem(pszLibAFilename, Length(GuestFile) * 2 + 1);
StringToWideChar(GuestFile, pszLibAFilename, Length(GuestFile) * 2 + 1);
if PID> 0 then
dwRemoteProcessID := PID
else
ShowMessage('注入PID未找到');
hRemoteProcess := OpenProcess(PROCESS_ALL_ACCESS{PROCESS_CREATE_THREAD +
PROCESS_VM_OPERATION +
PROCESS_VM_WRITE},
FALSE,dwRemoteProcessId);
cb := (1 + lstrlenW(pszLibAFilename)) * sizeof(WCHAR);
pszLibFileRemote := PWIDESTRING(VirtualAllocEx(hRemoteProcess, nil, cb, MEM_COMMIT,PAGE_READWRITE));
TempVar := 0;
iReturnCode := WriteProcessMemory(hRemoteProcess, pszLibFileRemote, pszLibAFilename, cb, TempVar);
if iReturnCode then
begin
pfnStartAddr := GetProcAddress(GetModuleHandle('Kernel32'), 'LoadLibraryW');
TempVar := 0;
Result := CreateRemoteThread(hRemoteProcess, nil, 8, pfnStartAddr, pszLibFileRemote, 0, TempVar);
end;
Freemem(pszLibAFilename);
end;
在XE2里WriteProcessMemory最后一个参数不是Dword
CreateRemoteThread最后一个参数必须是Dword
这个程序就没法编译了
OpenProcess也有问题
谁有XE2给我编译下,能够正确运行就可以了,谢谢。
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!