如何 hook com IFileOpenDialog 接口的GetResults函数,请帮忙解答下,急
为什么我的程序 hook com的 IFileOpenDialog 接口的GetResults函数呢,是不是我的变更虚函数表HookVtbl参数不正确啊,请帮忙解答下,急
int HookVtbl(void* pObject, unsigned int classIdx, unsigned int methodIdx,unsigned int newMethod);
typedef HRESULT (__stdcall* PGetResults)(IFileOpenDialog*, IShellItemArray**);
static PGetResults GetResults_old = NULL;
#define HOOK(a, b) b##_old = (P##b)HookVtbl(a, 2, 23, (unsigned int)b##_new) //----是不是这块参数不正确啊
HRESULT __stdcall GetResults_new(IFileOpenDialog *pThis,
IShellItemArray **ppenum)
{
OutputDebugStringA("调用了 GetResults_new ");
HRESULT hr = GetResults_old(pThis, ppenum);
return hr;
}
BOOL WINAPI StartHook()
{
PVOID pInterface = NULL;
CoInitialize(NULL);
//CLSCTX_ALL
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_SERVER, IID_IFileOpenDialog, &pInterface);
if(FAILED(hr))
{
OutputDebugStringA("CoCreateInstance 失败");
return FALSE;
}
HOOK(pInterface, GetResults);
return TRUE;
}
int HookVtbl(void* pObject, unsigned int classIdx, unsigned int methodIdx,unsigned int newMethod)
{
int** vtbl = (int**)pObject;
DWORD oldProtect = 0;
int oldMethod = vtbl[classIdx][methodIdx];
VirtualProtect(vtbl[classIdx] + sizeof(int*) * methodIdx, sizeof(int*), PAGE_READWRITE, &oldProtect);
vtbl[classIdx][methodIdx] = newMethod;
VirtualProtect(vtbl[classIdx] + sizeof(int*) * methodIdx, sizeof(int*), oldProtect, &oldProtect);
return oldMethod;
}