能力值:
( LV4,RANK:40 )
13 楼
20140514修正代码:
#pragma pack(push,16)
typedef struct tagLVITEM64
{
UINT mask;
int iItem;
int iSubItem;
UINT state;
UINT stateMask;
PVOID64 pszText;
int cchTextMax;
int iImage;
PVOID64 lParam;
#if (_WIN32_IE >= 0x0300)
int iIndent;
#endif
#if (_WIN32_WINNT >= 0x0501)
int iGroupId;
UINT cColumns; // tile view columns
PVOID64 puColumns;
#endif
#if _WIN32_WINNT >= 0x0600 // Will be unused downlevel, but sizeof(LVITEMA) must be equal to sizeof(LVITEMW)
PVOID64 piColFmt;
int iGroup; // readonly. only valid for owner data.
#endif
} LVITEM64, *LPLVITEM64;
typedef LVITEM64 LV_ITEM64;
typedef LPLVITEM64 LPLV_ITEM64;
typedef struct _HD_ITEM64
{
UINT mask;
int cxy;
PVOID64 pszText;
PVOID64 hbm;
int cchTextMax;
int fmt;
PVOID64 lParam;
#if (_WIN32_IE >= 0x0300)
int iImage; // index of bitmap in ImageList
int iOrder; // where to draw this item
#endif
#if (_WIN32_IE >= 0x0500)
UINT type; // [in] filter type (defined what pvFilter is a pointer to)
PVOID64 pvFilter; // [in] filter data see above
#endif
#if _WIN32_WINNT >= 0x0600
UINT state;
#endif
} HDITEM64, *LPHDITEM64;
#pragma pack(pop,16)
BOOL ProcessIs64Process(HANDLE hProcess)
{
BOOL bRet=FALSE;
if (hProcess)
{
static BOOL (WINAPI* _IsWow64Process)(__in HANDLE hProcess,__out PBOOL Wow64Process)=
(BOOL (__stdcall *)(HANDLE,PBOOL))GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"IsWow64Process");
BOOL bIsWow64;
if (_IsWow64Process && _IsWow64Process(hProcess,&bIsWow64) && bIsWow64==FALSE)//64位进程
{
bRet=TRUE;
}
}
return bRet;
}
#define COPY_STRUCT_MEMBER(lpDstStruct,lpSrcStruct,Member) (lpDstStruct)->Member=(lpSrcStruct)->Member
#define COPY_STRUCT_MEMBER_EX(lpDstStruct,lpSrcStruct,Member,DstStructMemberType) (lpDstStruct)->Member=(DstStructMemberType)(lpSrcStruct)->Member
LRESULT (WINAPI* RealSendMessage)( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI MySendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg==HDM_GETITEMA || Msg==HDM_GETITEMW)
{
HDITEM* phdi32=(HDITEM*)lParam;
DWORD dwDstWindowProcessId;
GetWindowThreadProcessId(hWnd,&dwDstWindowProcessId);
CHANDLE hProcess=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION,FALSE,dwDstWindowProcessId);
BOOL bTryToUseX64=ProcessIs64Process(hProcess);
if (bTryToUseX64)
{
HDITEM hdi32;
if (dwDstWindowProcessId!=GetCurrentProcessId())//不是本进程
{
SIZE_T ReadLen;
ReadProcessMemory(hProcess,phdi32,&hdi32,sizeof(hdi32),&ReadLen);
phdi32=&hdi32;
if (phdi32->mask &HDI_TEXT)
{
WCHAR StrBuf[MAX_PATH];
SIZE_T stGetStrLen=min(phdi32->cchTextMax,sizeof(StrBuf));
ReadProcessMemory(hProcess,phdi32->pszText,StrBuf,stGetStrLen,&ReadLen);
bTryToUseX64=(ReadLen==stGetStrLen);
}
}
}
if (bTryToUseX64)
{
HDITEM64 hdi64={0};
LPHDITEM64 phdi64=&hdi64;
COPY_STRUCT_MEMBER(&hdi64,phdi32,mask);
COPY_STRUCT_MEMBER(&hdi64,phdi32,cxy);
COPY_STRUCT_MEMBER(&hdi64,phdi32,pszText);
COPY_STRUCT_MEMBER(&hdi64,phdi32,hbm);
COPY_STRUCT_MEMBER(&hdi64,phdi32,cchTextMax);
COPY_STRUCT_MEMBER(&hdi64,phdi32,fmt);
COPY_STRUCT_MEMBER_EX(&hdi64,phdi32,lParam,PVOID64);
COPY_STRUCT_MEMBER(&hdi64,phdi32,iImage);
COPY_STRUCT_MEMBER(&hdi64,phdi32,iOrder);
COPY_STRUCT_MEMBER(&hdi64,phdi32,type);
COPY_STRUCT_MEMBER(&hdi64,phdi32,pvFilter);
COPY_STRUCT_MEMBER(&hdi64,phdi32,state);
if (dwDstWindowProcessId!=GetCurrentProcessId())//不是本进程
{
PVOID pAllocBuf=VirtualAllocEx(hProcess,NULL,sizeof(hdi64),MEM_COMMIT,PAGE_READWRITE);
SIZE_T WriteLen;
WriteProcessMemory(hProcess,pAllocBuf,&hdi64,sizeof(hdi64),&WriteLen);
phdi64=(LPHDITEM64)pAllocBuf;
}
LRESULT lr=RealSendMessage(hWnd,Msg,wParam,(LPARAM)phdi64);
if (phdi64!=&hdi64)
{
SIZE_T ReadLen;
ReadProcessMemory(hProcess,phdi64,&hdi64,sizeof(hdi64),&ReadLen);
VirtualFreeEx(hProcess,phdi64,0,MEM_RELEASE);
phdi64=NULL;
}
COPY_STRUCT_MEMBER(phdi32,&hdi64,mask);
COPY_STRUCT_MEMBER(phdi32,&hdi64,cxy);
COPY_STRUCT_MEMBER_EX(phdi32,&hdi64,pszText,LPSTR);
COPY_STRUCT_MEMBER_EX(phdi32,&hdi64,hbm,HBITMAP);
COPY_STRUCT_MEMBER(phdi32,&hdi64,cchTextMax);
COPY_STRUCT_MEMBER(phdi32,&hdi64,fmt);
COPY_STRUCT_MEMBER_EX(phdi32,&hdi64,lParam,LPARAM);
COPY_STRUCT_MEMBER(phdi32,&hdi64,iImage);
COPY_STRUCT_MEMBER(phdi32,&hdi64,iOrder);
COPY_STRUCT_MEMBER(phdi32,&hdi64,type);
COPY_STRUCT_MEMBER_EX(phdi32,&hdi64,pvFilter,void*);
COPY_STRUCT_MEMBER(phdi32,&hdi64,state);
return lr;
}
}
else if (Msg==LVM_GETITEMTEXTA || Msg==LVM_GETITEMTEXTW)
{
LVITEM* pitem32=(LVITEM*)lParam;
DWORD dwDstWindowProcessId;
GetWindowThreadProcessId(hWnd,&dwDstWindowProcessId);
CHANDLE hProcess=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION,FALSE,dwDstWindowProcessId);
BOOL bTryToUseX64=ProcessIs64Process(hProcess);
if (bTryToUseX64)
{
if (dwDstWindowProcessId!=GetCurrentProcessId())//不是本进程
{
LVITEM item32;
SIZE_T ReadLen;
ReadProcessMemory(hProcess,pitem32,&item32,sizeof(item32),&ReadLen);
pitem32=&item32;
if (pitem32->mask &LVIF_TEXT)
{
WCHAR StrBuf[MAX_PATH];
SIZE_T stGetStrLen=min(pitem32->cchTextMax,sizeof(StrBuf));
ReadProcessMemory(hProcess,pitem32->pszText,StrBuf,stGetStrLen,&ReadLen);
bTryToUseX64=(ReadLen==stGetStrLen);
}
}
}
if(bTryToUseX64)
{
LVITEM64 item64={0};
LPLVITEM64 pitem64=&item64;
COPY_STRUCT_MEMBER(&item64,pitem32,mask);
COPY_STRUCT_MEMBER(&item64,pitem32,iItem);
COPY_STRUCT_MEMBER(&item64,pitem32,iSubItem);
COPY_STRUCT_MEMBER(&item64,pitem32,state);
COPY_STRUCT_MEMBER(&item64,pitem32,stateMask);
COPY_STRUCT_MEMBER(&item64,pitem32,pszText);
COPY_STRUCT_MEMBER(&item64,pitem32,cchTextMax);
COPY_STRUCT_MEMBER(&item64,pitem32,iImage);
COPY_STRUCT_MEMBER_EX(&item64,pitem32,lParam,PVOID64);
COPY_STRUCT_MEMBER(&item64,pitem32,iIndent);
COPY_STRUCT_MEMBER(&item64,pitem32,iGroupId);
COPY_STRUCT_MEMBER(&item64,pitem32,cColumns);
COPY_STRUCT_MEMBER(&item64,pitem32,puColumns);
COPY_STRUCT_MEMBER(&item64,pitem32,piColFmt);
COPY_STRUCT_MEMBER(&item64,pitem32,iGroup);
if (dwDstWindowProcessId!=GetCurrentProcessId())//不是本进程
{
PVOID pAllocBuf=VirtualAllocEx(hProcess,NULL,sizeof(item64),MEM_COMMIT,PAGE_READWRITE);
SIZE_T WriteLen;
WriteProcessMemory(hProcess,pAllocBuf,&item64,sizeof(item64),&WriteLen);
pitem64=(LPLVITEM64)pAllocBuf;
}
LRESULT lr=RealSendMessage(hWnd,Msg,wParam,(LPARAM)pitem64);
if (pitem64!=&item64)
{
SIZE_T ReadLen;
ReadProcessMemory(hProcess,pitem64,&item64,sizeof(item64),&ReadLen);
VirtualFreeEx(hProcess,pitem64,0,MEM_RELEASE);
pitem64=NULL;
}
COPY_STRUCT_MEMBER(pitem32,&item64,mask);
COPY_STRUCT_MEMBER(pitem32,&item64,iItem);
COPY_STRUCT_MEMBER(pitem32,&item64,iSubItem);
COPY_STRUCT_MEMBER(pitem32,&item64,state);
COPY_STRUCT_MEMBER(pitem32,&item64,stateMask);
COPY_STRUCT_MEMBER_EX(pitem32,&item64,pszText,LPSTR);
COPY_STRUCT_MEMBER(pitem32,&item64,cchTextMax);
COPY_STRUCT_MEMBER(pitem32,&item64,iImage);
COPY_STRUCT_MEMBER_EX(pitem32,&item64,lParam,LPARAM);
COPY_STRUCT_MEMBER(pitem32,&item64,iIndent);
COPY_STRUCT_MEMBER(pitem32,&item64,iGroupId);
COPY_STRUCT_MEMBER(pitem32,&item64,cColumns);
COPY_STRUCT_MEMBER_EX(pitem32,&item64,puColumns,PUINT);
COPY_STRUCT_MEMBER_EX(pitem32,&item64,piColFmt,int*);
COPY_STRUCT_MEMBER(pitem32,&item64,iGroup);
return lr;
}
}
return RealSendMessage(hWnd,Msg,wParam,lParam);
}