问题很简单, ( 积分: 100 )

  • 主题发起人 主题发起人 52253831
  • 开始时间 开始时间
5

52253831

Unregistered / Unconfirmed
GUEST, unregistred user!
翻译这段C++代码成DELPHI
int WINAPI EjectLib(DWORD process_id, char *lib_name)
{
PTHREAD_START_ROUTINE pfnRemote =(PTHREAD_START_ROUTINE)
GetProcAddress(GetModuleHandle("Kernel32"), "FreeLibrary");

if(pfnRemote ==NULL)
{
WriteLog("EjectLib:GetProcAddress FreeLibrary failed!");
return -1;
}
HANDLE hProcess =OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
if(hProcess ==NULL)
{
// WriteLog("EjectLib:OpenProcess %d failed!", process_id);
return -1;
}
CProcessModule pm;
HANDLE hmod =pm.GetProcessModuleHandle(process_id, lib_name);
if(hmod ==NULL)
{
CloseHandle(hProcess);
//WriteLog("EjectLib(), not found lib:%s", lib_name);
return 0;
}
// WriteLog("EjectLib(), found lib:%s, mod handle:0x%x", lib_name, hmod);
HANDLE hThread =CreateRemoteThread(hProcess, NULL, 0,
pfnRemote, hmod, 0, NULL);
if(hThread ==NULL)
{
WriteLog("EjectLib():CreateRemoteThread failed! process_id:%d", process_id);
CloseHandle(hProcess);
return -1;
}
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hProcess);
CloseHandle(hThread);
return 0;
}
 
function WINAPI EjectLib(process_id:DWORD;lib_name^:char):integer;
var
hmod:HANDLE ;
pm:CProcessModule;
begin
PTHREAD_START_ROUTINE pfnRemote :=(PTHREAD_START_ROUTINE)
GetProcAddress(GetModuleHandle("Kernel32"), "FreeLibrary");

if pfnRemote=nil then
begin
showmessage("EjectLib:GetProcAddress FreeLibrary failed!");
return -1;
end;
HANDLE hProcess :=OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
if (hProcess =nil) then
begin
return -1;
end;

hmod =pm.GetProcessModuleHandle(process_id, lib_name);
if (hmod =NIL) then
begin
CloseHandle(hProcess);
return 0;
end
HANDLE hThread :=CreateRemoteThread(hProcess, Nil, 0,
pfnRemote, hmod, 0, nil);
if (hThread =NULL) then
begin
CloseHandle(hProcess);
return -1;
endl
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hProcess);
CloseHandle(hThread);
return 0;
end;
 
不对,楼上的不要瞎搞。
 
是不是这段代码没法翻译成DELPHI啊。
 

Similar threads

后退
顶部