比如说一个名为A的dll中导出了下面的类:
namespace B
{
_cdeclspec(dllexport) Class C
{
public:
function D();
function E();
}
}
如果我现在想HOOK第三方程序对函数D或者函数E的调用,该怎么写?
在detour库中使用DETOUR_TRAMPOLINE宏。
DETOUR_TRAMPOLINE有两个输入参数:trampoline的原型和目标函数的名字。
其中目标函数的名字该怎么写,我直接写D,好像不行,老说我函数D没有声明。
namespace B
{
_cdeclspec(dllexport) Class C
{
public:
function D();
function E();
}
}
如果我现在想HOOK第三方程序对函数D或者函数E的调用,该怎么写?
在detour库中使用DETOUR_TRAMPOLINE宏。
DETOUR_TRAMPOLINE有两个输入参数:trampoline的原型和目标函数的名字。
其中目标函数的名字该怎么写,我直接写D,好像不行,老说我函数D没有声明。
////////////////////////////////////////////////////////////////
// Target Class. 也就是你DLL中的类:
class CMember
{
public:
void Target(void);
};void CMember::Target(void)
{
printf(" CMember::Target! (this:%p)\n", this);
}////////////////////////////////////////////////////////////////
// Detour Class. 也就是你自己编写来替代前面类的类:class CDetour /* add ": public CMember" to enable access to member variables... */
{
public:
void Mine_Target(void);
static void (CDetour::* Real_Target)(void); // Class shouldn't have any member variables or virtual functions.
};void CDetour::Mine_Target(void)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}void (CDetour::* CDetour::Real_Target)(void) = (void (CDetour::*)(void))&CMember::Target;// 然后在函数中这样调用:
DetourAttach(&(PVOID&)CDetour::Real_Target, *(PBYTE*)&pfMine);
如果导出的类位于dll中的一个命名空间namespace,该怎样hook,是否和上述方法一样?
而我需要hook的是dll中导出的类,
可以用例子中的方法吗?
有什么区别吗?按照通常的做法导入DLL A 必要的库就行了。
#include ".h"
#pragma comment(lib, ".lib")