麻烦将下面的C代码翻译成Delphi语言 ( 积分: 300 )

  • 主题发起人 主题发起人 YuZi
  • 开始时间 开始时间
Y

YuZi

Unregistered / Unconfirmed
GUEST, unregistred user!
麻烦将下面的代码翻译成Delphi语言,前次自己修改结果还是有问题,干脆请大侠帮忙完全转译一下,谢谢!会的人应该不难。
typedef struct tagDataList {
DWORD dwIndex;
union {
DATA_A DataA;
DATA_B DataB;
};
}DATALIST,*LPDATALIST;
typedef struct tagListHeader {
DWORD dwCount;
LPDATALIST* lpDataList;
}LISTHEADER,*LPLISTHEADER;
typedef struct tagMyData {
DWORD dwData1;
DWORD dwData2;
LPLISTHEADER lpListHeader;
} MYDATA,*LPMYDATA;
#include "tlhelp32.h"
LPMYDATA GetMyData()
{
HWND hWin = Wnd;//一个窗口句柄
LPMYDATA lpMyData=(LPMYDATA)VirtualAlloc(NULL,sizeof(MyData),MEM_COMMIT,PAGE_READWRITE);
if (lpMyData)
{
LPVOID lpData = (LPVOID)GetWindowLong(hWin,0);
if (lpData)
{
DWORD pid=0;
GetWindowThreadProcessId(hWin,&pid);
HANDLE hP = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION,FALSE,pid);
if (hP)
{
if (ReadProcessMemory(hP,lpData,(LPVOID)lpMyData,sizeof(MyData),NULL))
{
lpData = (LPVOID)lpMyData->lpListHeader;
lpMyData->lpListHeader = (LPLISTHEADER)VirtualAlloc(NULL,sizeof(LISTHEADER),MEM_COMMIT,PAGE_READWRITE);
if (lpMyData->lpListHeader)
{
if (ReadProcessMemory(hP,lpData,(LPVOID)lpMyData->lpListHeader,sizeof(LISTHEADER),NULL))
{
ULONG dwCount =lpMyData->lpListHeader->dwCount;
lpData = (LPVOID)lpMyData->lpListHeader->lpDataList;
lpMyData->lpListHeader->lpDataList = (LPDATALIST*)VirtualAlloc(NULL,dwCount * sizeof(LPVOID),MEM_COMMIT,PAGE_READWRITE);
if (ReadProcessMemory(hP,lpData,(LPVOID)lpMyData->lpListHeader->lpDataList,dwCount * sizeof(LPVOID),NULL))
{
for (UINT x =0;
x < dwCount;x++)
{
if (IsWindowsNT())
{
if (((lpMyData->lpListHeader->lpDataList))[x] = (LPDATALIST)VirtualAlloc(NULL,sizeof(DATA_W)+4,MEM_COMMIT,PAGE_READWRITE))
ReadProcessMemory(hP,(LPVOID)(((LPDATALIST*)lpData)[x]),(LPVOID)((lpMyData->lpListHeader->lpDataList))[x],sizeof(DATA_W)+4,NULL);
}
else
{
if (((lpMyData->lpListHeader->lpDataList))[x] = (LPDATALIST)VirtualAlloc(NULL,sizeof(DATA_A)+4,MEM_COMMIT,PAGE_READWRITE))
ReadProcessMemory(hP,(LPVOID)(((LPDATALIST*)lpData)[x]),(LPVOID)((lpMyData->lpListHeader->lpDataList))[x],sizeof(DATA_A)+4,NULL);
}
}
}
}
}
}
CloseHandle(hP);
}
}
}
return lpMyData;
}
 
麻烦将下面的代码翻译成Delphi语言,前次自己修改结果还是有问题,干脆请大侠帮忙完全转译一下,谢谢!会的人应该不难。
typedef struct tagDataList {
DWORD dwIndex;
union {
DATA_A DataA;
DATA_B DataB;
};
}DATALIST,*LPDATALIST;
typedef struct tagListHeader {
DWORD dwCount;
LPDATALIST* lpDataList;
}LISTHEADER,*LPLISTHEADER;
typedef struct tagMyData {
DWORD dwData1;
DWORD dwData2;
LPLISTHEADER lpListHeader;
} MYDATA,*LPMYDATA;
#include "tlhelp32.h"
LPMYDATA GetMyData()
{
HWND hWin = Wnd;//一个窗口句柄
LPMYDATA lpMyData=(LPMYDATA)VirtualAlloc(NULL,sizeof(MyData),MEM_COMMIT,PAGE_READWRITE);
if (lpMyData)
{
LPVOID lpData = (LPVOID)GetWindowLong(hWin,0);
if (lpData)
{
DWORD pid=0;
GetWindowThreadProcessId(hWin,&amp;pid);
HANDLE hP = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION,FALSE,pid);
if (hP)
{
if (ReadProcessMemory(hP,lpData,(LPVOID)lpMyData,sizeof(MyData),NULL))
{
lpData = (LPVOID)lpMyData->lpListHeader;
lpMyData->lpListHeader = (LPLISTHEADER)VirtualAlloc(NULL,sizeof(LISTHEADER),MEM_COMMIT,PAGE_READWRITE);
if (lpMyData->lpListHeader)
{
if (ReadProcessMemory(hP,lpData,(LPVOID)lpMyData->lpListHeader,sizeof(LISTHEADER),NULL))
{
ULONG dwCount =lpMyData->lpListHeader->dwCount;
lpData = (LPVOID)lpMyData->lpListHeader->lpDataList;
lpMyData->lpListHeader->lpDataList = (LPDATALIST*)VirtualAlloc(NULL,dwCount * sizeof(LPVOID),MEM_COMMIT,PAGE_READWRITE);
if (ReadProcessMemory(hP,lpData,(LPVOID)lpMyData->lpListHeader->lpDataList,dwCount * sizeof(LPVOID),NULL))
{
for (UINT x =0;
x < dwCount;x++)
{
if (IsWindowsNT())
{
if (((lpMyData->lpListHeader->lpDataList))[x] = (LPDATALIST)VirtualAlloc(NULL,sizeof(DATA_W)+4,MEM_COMMIT,PAGE_READWRITE))
ReadProcessMemory(hP,(LPVOID)(((LPDATALIST*)lpData)[x]),(LPVOID)((lpMyData->lpListHeader->lpDataList))[x],sizeof(DATA_W)+4,NULL);
}
else
{
if (((lpMyData->lpListHeader->lpDataList))[x] = (LPDATALIST)VirtualAlloc(NULL,sizeof(DATA_A)+4,MEM_COMMIT,PAGE_READWRITE))
ReadProcessMemory(hP,(LPVOID)(((LPDATALIST*)lpData)[x]),(LPVOID)((lpMyData->lpListHeader->lpDataList))[x],sizeof(DATA_A)+4,NULL);
}
}
}
}
}
}
CloseHandle(hP);
}
}
}
return lpMyData;
}
 
没人愿意帮忙?
 
偷懒不行。你说你句你不会翻,有人回帮你。
 
不是偷懒呀,我分数本来就不够用,哪能偷懒呢,
请大侠们出手相救呀~~~~~~~~~~
 
{ ================================================================ }
{ 为了能够通过编译 }
type
DATA_A = record
end;
DATA_B = record
end;
DATA_W = record
end;
var
Wnd: HWND;
function IsWindowsNT: Boolean;
begin
end;
{ ================================================================ }
type
tagDataList = record
dwIndex: DWORD;
case Integer of
0: (DataA: DATA_A);
1: (DataB: DATA_B);
end;
DATALIST = tagDataList;
LPDATALIST = ^DATALIST;
LPDATALISTArray = array[0..255] of LPDATALIST;
PLPDATALISTArray = ^LPDATALISTArray;
tagListHeader = record
dwCount: DWORD;
lpDataList: PLPDATALISTArray;
end;
LISTHEADER = tagListHeader;
LPLISTHEADER = ^LISTHEADER;
tagMyData = record
dwData1: DWORD;
dwData2: DWORD;
lpListHeader: LPLISTHEADER;
end;
MYDATA = tagMyData;
LPMYDATA = ^MYDATA;
function GetMyData: LPMYDATA;
var
h: HWND;
pMyData: LPMYDATA;
lpData: Pointer;
hp: THandle;
pid, dwDummy, dwCount, x: DWORD;
begin
h := Wnd;//一个窗口句柄
pMyData := VirtualAlloc(nil, sizeof(MyData),MEM_COMMIT,PAGE_READWRITE);
if (pMyData <> nil) then
begin
lpData := Pointer(GetWindowLong(h,0));
if (lpData <> nil) then
begin
pid:=0;
GetWindowThreadProcessId(h,pid);
hP := OpenProcess(PROCESS_VM_READ or PROCESS_VM_OPERATION,FALSE,pid);
if (hP <> 0) then
begin
if (ReadProcessMemory(hP,lpData,pMyData,sizeof(MyData),dwDummy)) then
begin
lpData := pMyData^.lpListHeader;
pMyData^.lpListHeader := VirtualAlloc(nil,sizeof(LISTHEADER),MEM_COMMIT,PAGE_READWRITE);
if (pMyData^.lpListHeader <> nil) then
begin
if (ReadProcessMemory(hP,lpData,pMyData^.lpListHeader,sizeof(LISTHEADER),dwDummy)) then
begin
dwCount := pMyData^.lpListHeader^.dwCount;
lpData := pMyData^.lpListHeader^.lpDataList;
pMyData^.lpListHeader^.lpDataList := VirtualAlloc(nil,dwCount * sizeof(Pointer),MEM_COMMIT,PAGE_READWRITE);
if (ReadProcessMemory(hP,lpData,pMyData^.lpListHeader^.lpDataList,dwCount * sizeof(Pointer),dwDummy)) then
begin
for x := 0 to dwCount - 1do
begin
if (IsWindowsNT) then
begin
pMyData^.lpListHeader^.lpDataList[x] := VirtualAlloc(nil,sizeof(DATA_W)+4,MEM_COMMIT,PAGE_READWRITE);
if (pMyData^.lpListHeader^.lpDataList[x] <> nil) then
ReadProcessMemory(hP,PLPDATALISTArray(lpData)[x],pMyData^.lpListHeader^.lpDataList[x],sizeof(DATA_W)+4,dwDummy);
end
else
begin
pMyData^.lpListHeader^.lpDataList[x] := VirtualAlloc(nil,sizeof(DATA_A)+4,MEM_COMMIT,PAGE_READWRITE);
if (pMyData^.lpListHeader^.lpDataList[x] <> nil) then
ReadProcessMemory(hP,PLPDATALISTArray(lpData)[x],pMyData^.lpListHeader^.lpDataList[x],sizeof(DATA_A)+4,dwDummy);
end;
end;
end;
end;
end;
end;
CloseHandle(hP);
end;
end;
end;
Result := pMyData;
end;
 
非常感谢lichengbin!看来真的要定义一个指针数组才行,谢谢!
 
后退
顶部