下面这段c++,哪位高手能帮我翻译成delphi?不好意思加了一点代码? (100分)

  • 主题发起人 主题发起人 nine_day
  • 开始时间 开始时间
N

nine_day

Unregistered / Unconfirmed
GUEST, unregistred user!
typedef struct _RemotePara//参数结构
{
char pLoadLibrary[256];
char pGetProcAddress[60];
DWORD dwGetProcAddress;
DWORD dwLoadLibrary;
}RemotePara;
DWORD WINAPI ThreadProc (RemotePara *lpPara)
{
typedef HMODULE (WINAPI *LOADLIBRARY)(LPCTSTR );
typedef DWORD (WINAPI *GETPROCADDRESS)(HMODULE,LPCSTR);
typedef BOOL (__cdecl *MYFUNC)(int,HWND);

LOADLIBRARY myLoadLibrary = (LOADLIBRARY)lpPara->dwLoadLibrary;
GETPROCADDRESS myGetProcAddress = (GETPROCADDRESS)lpPara->dwGetProcAddress;

HMODULE hDll = myLoadLibrary((LPCSTR)lpPara->pLoadLibrary);
MYFUNC init = (MYFUNC)myGetProcAddress(hDll,(LPCSTR)lpPara->pGetProcAddress);

init(0,(HWND)0x0070011E);

return 0;
}
void InsertThread()
{
const DWORD THREADSIZE = 1024 * 8;
HANDLE hWnd = hProcess;
DWORD byte_write;
char localpath[1000];
LoadLibrary("apicap.dll");
HMODULE hdl = GetModuleHandle("apicap.dll");
if (hdl==NULL)
MessageBox(0,"wrong2",0,0);

int len = GetModuleFileName(hdl,localpath,sizeof(localpath));
CloseHandle(hdl);

void *pRemoteThread = ::VirtualAllocEx(hWnd,0,THREADSIZE,MEM_COMMIT| MEM_RESERVE,PAGE_EXECUTE_READWRITE);

if(!pRemoteThread)
{
MessageBox(0,"virtual alloc error",0,0);
return;
}

if(!::WriteProcessMemory(hWnd,pRemoteThread,ThreadProc,THREADSIZE,0))
{
MessageBox(0,"write process memory error",0,0);
return;
}

RemotePara myRemotePara;
::ZeroMemory(&myRemotePara,sizeof(RemotePara));

HINSTANCE hKernel32 = LoadLibrary("kernel32.dll");
myRemotePara.dwLoadLibrary =(DWORD)GetProcAddress(hKernel32,"LoadLibraryA");
myRemotePara.dwGetProcAddress =(DWORD)GetProcAddress (hKernel32,"GetProcAddress");

strcpy(myRemotePara.pLoadLibrary,localpath);
strcpy(myRemotePara.pGetProcAddress,"init");

//写进目标进程
RemotePara *pRemotePara =(RemotePara *)::VirtualAllocEx(hWnd ,0,sizeof(RemotePara),MEM_COMMIT,PAGE_READWRITE);//注意申请空间时的页面属性
if(!pRemotePara)
return;
if(!::WriteProcessMemory (hWnd,pRemotePara,&myRemotePara,sizeof(myRemotePara),0))
return;
//启动线程

//::CreateRemoteThread(hWnd,0,0,(DWORD (WINAPI *)(void *))pRemoteThread ,pRemotePara,0,&byte_write);

}
 
type
TRemotePara = record
pLoadLibrary: array[0..99] of char;
pGetProcAddress: array[0..59] of char;
dwGetProcAddress: DWORD;
dwLoadLibrary: DWORD;
end;
 
type
PRemotePara = ^TRemotePara;
TRemotePara = record
pLoadLibrary : array[0..255] of Char;
pGetProcAddress: array[0..59] of Char;
dwGetProcAddress : DWORD;
dwLoadLibrary : DWORD;
end;

function ThreadProc(lpPara : PRemotePara) : DWORD
stdcall;
type
LOADLIBRARY = function(lpLibFileName: PChar): HMODULE
stdcall;
GETPROCADDRESS = function(hModule: HMODULE
lpProcName: LPCSTR): FARPROC
stdcall;
MYFUNC = function(p1 : Integer
p2 : HWND) : BOOL
cdecl;
var
myLoadLibrary : LOADLIBRARY;
myGetProcAddress : GETPROCADDRESS;
hDll : HMODULE;
init : MYFUNC;
begin
myLoadLibrary := Pointer(lpPara^.dwLoadLibrary);
myGetProcAddress := Pointer(lpPara^.dwGetProcAddress);
hDll := myLoadLibrary(lpPara^.pLoadLibrary);
init := myGetProcAddress(hDll,lpPara^.pGetProcAddress);
init(0,$0070011E);
Result := 0;
end;
 
program Project1;

uses
Windows;

{$R *.res}

type
PRemotePara = ^TRemotePara;
TRemotePara = record
pLoadLibrary : array[0..255] of Char;
pGetProcAddress: array[0..59] of Char;
dwGetProcAddress : DWORD;
dwLoadLibrary : DWORD;
end;

function ThreadProc(lpPara : PRemotePara) : DWORD
stdcall;
type
LOADLIBRARY = function(lpLibFileName: PChar): HMODULE
stdcall;
GETPROCADDRESS = function(hModule: HMODULE
lpProcName: LPCSTR): FARPROC
stdcall;
MYFUNC = function(p1 : Integer
p2 : HWND) : BOOL
cdecl;
var
myLoadLibrary : LOADLIBRARY;
myGetProcAddress : GETPROCADDRESS;
hDll : HMODULE;
init : MYFUNC;
begin
myLoadLibrary := Pointer(lpPara^.dwLoadLibrary);
myGetProcAddress := Pointer(lpPara^.dwGetProcAddress);
hDll := myLoadLibrary(lpPara^.pLoadLibrary);
init := myGetProcAddress(hDll,lpPara^.pGetProcAddress);
init(0,$0070011E);
Result := 0;
end;

procedure InsertThread;
Const
THREADSIZE = DWORD(1024 * 8);
var
hWnd : THandle;
byte_write : DWORD;
localpath : array[0..999] of char;
pRemoteThread : Pointer;
hdl : HMODULE;
myRemotePara : TRemotePara;
hKernel32 : THandle;
pRemotePara : ^TRemotePara;
begin
hWnd := GetCurrentProcess;
LoadLibrary('apicap.dll');
hdl := GetModuleHandle('apicap.dll');
if hdl=0 then
MessageBox(0,'wrong2',nil,0);
//len :=
GetModuleFileName(hdl,localpath,sizeof(localpath));
CloseHandle(hdl);

pRemoteThread := VirtualAllocEx(hWnd,nil,THREADSIZE,MEM_COMMIT or MEM_RESERVE,
PAGE_EXECUTE_READWRITE);

if not Assigned(pRemoteThread) then
begin
MessageBox(0,'virtual alloc error',nil,0);
Exit;
end;

if not WriteProcessMemory(hWnd, pRemoteThread, @ThreadProc,
THREADSIZE,byte_write) then
begin
MessageBox(0,'write process memory error',nil,0);
Exit;
end;


ZeroMemory(@myRemotePara, sizeof(TRemotePara));

hKernel32 := LoadLibrary('kernel32.dll');
myRemotePara.dwLoadLibrary := DWORD(GetProcAddress(hKernel32,'LoadLibraryA'));
myRemotePara.dwGetProcAddress := DWORD(GetProcAddress(hKernel32,'GetProcAddress'));

lstrcpy(myRemotePara.pLoadLibrary,localpath);
lstrcpy(myRemotePara.pGetProcAddress,'init');


pRemotePara := VirtualAllocEx(hWnd ,nil,sizeof(TRemotePara),MEM_COMMIT,PAGE_READWRITE);//注意申?空??的?面?性
if not Assigned(pRemotePara) then Exit;

if not WriteProcessMemory(hWnd,pRemotePara,@myRemotePara,
sizeof(TRemotePara),byte_write) then Exit;
//CreateRemoteThread(hWnd,nil,0,pRemoteThread ,pRemotePara,0,byte_write);
end;

begin
//InsertThread;
end.
 
多人接受答案了。
 
后退
顶部