如何少走弯路hook类实例方法?

问题描述 投票:0回答:1

我一直在尝试在 Shobjdl_core.h 中挂钩 GetSelectedItems 函数

 virtual HRESULT STDMETHODCALLTYPE GetSelectedItems( 
            /* [out] */ __RPC__deref_out_opt IShellItemArray **ppsai) = 0;

由于它是一个虚函数,我无法编译代码

HRESULT(WINAPI* TrueSleep)(IShellItemArray** ppsai) = GetSelectedItems;

// Detour function that replaces the Sleep API.
//
HRESULT WINAPI TimedSleep(IShellItemArray** ppsai)
{

    return 0;
    
}

错误是

Severity    Code    Description Project File    Line    Suppression State
Error   C2065   'GetSelectedItems': undeclared identifier   DllCreateFile   C:\Users\x\source\repos\DllCreateFile\DllCreateFile\dllmain.cpp 132 

有挂钩类实例方法的示例吗? 唯一的链接就是这个。

winapi dll hook dll-injection detours
1个回答
0
投票

解决方案是:

HRESULT(WINAPI IFileOpenDialog::* TrueSleep)(IShellItemArray** ppsai) = &IFileOpenDialog::GetSelectedItems;

// Detour function that replaces the Sleep API.
//
HRESULT WINAPI TimedSleep(IShellItemArray** ppsai)
{
    // Save the before and after times around calling the Sleep API.
    DWORD dwBeg = GetTickCount();
    //TrueSleep(dwMilliseconds);
    DWORD dwEnd = GetTickCount();
    return 0;
    
}
© www.soinside.com 2019 - 2024. All rights reserved.