为什么 我用这些 PID 查找的函数 查找指定的进程 然后注入 不成功. 我把PID值指定 是可以成功的 问题肯定出在 这些查找函数上. 但是这个函数 明明 可以 查到PID的啊 望高人给个解答!
function GetProcessID(sProcName: string): Integer;
var
hProcSnap: THandle;
pe32: TProcessEntry32;
begin
Result := -1;
hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
if hProcSnap = INVALID_HANDLE_VALUE then Exit;
pe32.dwSize := SizeOf(ProcessEntry32);
if Process32First(hProcSnap, pe32) = True then
while Process32Next(hProcSnap, pe32) = True do
begin
if AnsiStricomp(PChar(ExtractFilename(pe32.szExefile)), PChar(ExtractFilename(sProcName))) = 0 then
begin
Result := pe32.th32ProcessID;
break;
end;
end;
CloseHandle(hProcSnap);
end;
应该是你的注入写的有问题吧。试试这个。
function InjectLib(dwProcessID: DWORD;DllName: string):Boolean;
var
hProcess,hThread: THandle;
LibRemoteFile: Pointer;
cb: Integer;
threadProc: Pointer;
ByteWrite: Cardinal;
threadID: Cardinal;
begin
Result := false;
hProcess := 0;
hThread := 0;
LibRemoteFile := nil;
threadProc := nil;
try
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_CREATE_THREAD or PROCESS_VM_OPERATION or PROCESS_VM_WRITE,
FALSE,
dwProcessID);
if hProcess = 0 then
exit;
cb := length(DllName);
LibRemoteFile := VirtualAllocEx(hProcess,nil,cb,MEM_COMMIT,PAGE_READWRITE);
if LibRemoteFile = nil then
exit;
if WriteProcessMemory(hProcess,LibRemoteFile,PChar(DllName),cb,ByteWrite) = false then
exit;
threadProc := Pointer(GetProcAddress(GetModuleHandle(PChar('Kernel32')),'LoadLibraryA'));
if threadProc = nil then
exit;
hThread := CreateRemoteThread(hProcess,nil,0,threadProc,LibRemoteFile,0,threadID);
if hThread = 0 then
exit;
WaitForSingleObject(hThread,INFINITE);
Result := false;
finally
if LibRemoteFile <> nil then
VirtualFreeEx(hProcess,LibRemoteFile,0,MEM_RELEASE);
if hThread <> 0 then
CloseHandle(hThread);
if hProcess <> 0 then
CloseHandle(hProcess);
end;
end;