这只是一个简单的问题。我一直在阅读使用 DetourAttach(&(PVOID &)BindKeyT, BindKeyD); 附加到子例程的内存地址的内容的源代码,其中 BindKeyT
是地址到内存中的子程序。我很好奇, (&(PVOID &)
在英语中到底是什么意思?我知道 PVOID
是一个 void 指针,但是如何将其转换为函数可以用哪个来附加绕行路线?
最佳答案
Terry Mahaffey 是对的,您传递的是一个指向函数指针的指针。每当您向其传递指针的函数(在本例中为 DetourAttach)想要返回多个值,并且这些返回值之一是指针时,通常会使用此方法。由于 C/C++ 中的函数只能返回单个值,因此从中获取多个值的唯一方法是通过指针。
一个简单的例子是当人们希望返回指向已分配内存块的指针时。然后可以编写一个函数,如下所示:
int allocstr(int len, char **retptr)
{
char *p = malloc(len + 1); /* +1 for \0 */
if(p == NULL)
return 0;
*retptr = p;
return 1;
}
要回答您的另一个问题,即如何设置要用作函数的内存地址,可以这样做:
void* (void * BindKeyT)(const char* key) = actual_BindKeyT;
// actual_BindKeyT is a pointer to a function that will be defined elsewhere,
// and whose declaration you will include in your project through a header file
// or a dll import
void * BindKeyD(const char* key)
{
// Code for your hook function
}
DetourAttach(&(PVOID&)BindKeyT, BindKeyD);
(取自 http://zenersblog.blogspot.com/2008/04/api-hooking-with-detours-part-1.html )
请记住,BindKeyT 和 BindKeyD 的声明应该匹配。
关于c++ - DetourAttach(&(PVOID &)BindKeyT, BindKeyD); 是什么意思?意思是?将绕行附加到内存地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2399644/