gpt4 book ai didi

c++ - 什么是 DetourAttach(&(PVOID &)BindKeyT, BindKeyD);意思是?附加绕道到内存地址

转载 作者:太空宇宙 更新时间:2023-11-04 02:19:42 24 4
gpt4 key购买 nike

这只是一个简单的问题。我一直在使用 DetourAttach(&(PVOID &)BindKeyT, BindKeyD); 读取附加到子例程内存地址的东西的源代码,其中 BindKeyT 是地址到内存中的子程序。我很好奇,(&(PVOID &) 在英语中到底是什么意思?我知道 PVOID 是一个空指针,但是如何将其转换为函数哪些可以用来绕道?

最佳答案

Terry Mahaffey 是对的,您传递的是指向函数指针的指针。每当您将指针传递给的函数(在本例中为 DetourAttach)想要返回多个值,并且其中一个返回值是指针时,通常会使用此方法。由于 C/C++ 中的函数只能返回一个值,因此从中获取多个值的唯一方法是通过指针。

一个简单的例子是当一个人希望返回一个指向一 block 已分配内存的指针时。然后可以编写如下函数:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com