Microsoft Detours-无法挂接__thiscall函数
Microsoft Detours - unable to hook __thiscall function
我正在尝试挂接一个未记录的函数,该函数具有以下签名:
(void(__thiscall*)(int arg1, int arg2))0x6142E0;
我看过弯路样本"成员",它解释道:
默认情况下,C++成员函数使用__thiscall调用习俗为了实现会员功能,蹦床并且迂回道必须与目标函数。遗憾的是,VC编译器不支持__因此,创建合法绕行和蹦床功能的唯一方法是让它们成为"绕行"类的类成员。
此外,C++不支持将指针转换为成员函数指向任意指针。要获取原始指针的必须移动到临时成员函数中指针,然后通过获取它的地址来传递,然后取消对它的引用。幸运的是,编译器会对代码进行优化,以删除额外的指针操作。
我已经从示例中复制了一些代码并对其进行了修改,但我似乎无法使其工作(此处为原始示例代码):
class CDetour {
public:
void Mine_Target(int arg1, int arg2);
static void (CDetour::* Real_Target)(int arg1, int arg2);
};
void CDetour::Mine_Target(int arg1, int arg2) {
printf(" CDetour::Mine_Target! (this:%p)n", this);
(this->*Real_Target)(arg1, arg2);
}
void (CDetour::* CDetour::Real_Target)(int arg1, int arg2) = (void(CDetour::*)(int arg1, int arg2)) (0x6142E0);
void hoo()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)CDetour::Real_Target, (PVOID)(&(PVOID&)CDetour::Mine_Target));
DetourTransactionCommit();
}
我不知道该怎么做。a bow代码有两个编译器错误:
void (CDetour::* CDetour::Real_Target)(int arg1, int arg2) = (void(CDetour::*)(int arg1, int arg2)) (0x6142E0);
//Error C2440 'type cast': cannot convert from 'int' to 'void (__thiscall CDetour::* )(int,int)'
和:
DetourAttach(&(PVOID&)CDetour::Real_Target, (PVOID)(&(PVOID&)CDetour::Mine_Target));
//Error C2440 'type cast': cannot convert from 'void (__thiscall CDetour::* )(int,int)' to 'PVOID &'
我希望有人能帮助我朝着正确的方向前进,因为我即将放弃钩住__thiscall函数。。。
我正在考虑编写一个带有内联汇编的全局"__declspec(naken)void MyFunc(int,int)"函数,以便保留这里建议的"this pointer"。
尝试使用更强大的替代方案http://www.nektra.com/products/deviare-api-hook-windows/deviare-in-process/它是开源的。
Detours相当古老。显式编译器对__thiscall
的支持是相当新的。Visual C++2005及更高版本似乎支持它。Detours的文件似乎从未更新过。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 内置函数可查看CPP中的成员变量
- 如何获取std::result_of函数的返回类型
- 如何在c++中为模板函数实例创建快捷方式
- 如何正确调用 thiscall 函数,并将其作为 mfc 控件