使用绕道DLL钩子从函数内读取数据
Reading data from within a function with detours DLL hook
我想知道是否有可能从函数中读取数据。
我知道我可以使用绕道来挂钩函数和自由地改变参数。
但这就是我对绕路的理解。
//cryptkeys
typedef int (WINAPI *pCryptKey)(int crypt1, int crypt2, int crypt3);
int WINAPI MyCryptKey(int crypt1, int crypt2, int crypt3);
pCryptKey MyCrypt2Key = (pCryptKey)(0x60FF50);
int WINAPI MyCryptKey(int crypt1, int crypt2, int crypt3)
{
cout << crypt1 << crypt2 << crypt3 << endl;
return MyCrypt2Key(999,135,2);
}
这段代码绕过了游戏中的crypt key函数,并在调用它之前更改了参数。所以当它被调用时,参数被改变了。
我在想,如果函数内部有数据而不是参数上的数据怎么办?
如何更改或显示它?
我应该重写整个函数吗?
我想要得到的是使用游戏本身来加密和解密数据包。
我已经钩住了执行此操作的函数,但我所能做的就是更改参数。
游戏只是继续它的事情。
在它被加密之前我已经改变了数据包,所以另一个数据包被发送。但这只会在我试图发送数据包并修改它时发生。我想直接调用函数,而不是等待它被游戏调用,只是修改值。
比如我将使用游戏输入我自己未加密的数据包,然后按加密键来查看加密的值,反之亦然。
一个解释或教程的链接将是伟大的。
如果我这样做呢:
int WINAPI MyCryptKey(int crypt1, int crypt2, int crypt3)
{
//dont know whats supposed to be in here. But it should be alot of codes.
}
并像
那样调用返回值int cryptValue = MyCrypt2Key(999,135,2);
cout << cryptValue << endl; //to get the return?
您的示例已经在正确的轨道上,cout
和endl
都存在于绕道函数之外。对于在绕道函数中放置什么代码实际上没有任何明确的限制。在函数外访问数据与其他程序一样。
int globalVar = 1;
int WINAPI MyCryptKey(int crypt1, int crypt2, int crypt3)
{
cout << crypt1 << crypt2 << crypt3 << globalVar << endl;
globalVar++;
return MyCrypt2Key(999,135,2);
}
要将数据保存在函数内部,可以像通常那样声明变量,必要时使用静态存储时间。
int WINAPI MyCryptKey(int crypt1, int crypt2, int crypt3)
{
static int staticVar = 1;
int localVar = staticVar + 1;
staticVar++;
cout << localVar << crypt1 << crypt2 << crypt3 << endl;
return MyCrypt2Key(999,135,2);
}
如果您想完全替换函数,只需删除对原始函数的调用并提供完整的实现。您应该记住,函数在调用时应该表现出与原始函数相同的行为,否则使用它的代码可能会失败。
int WINAPI MyCryptKey(int crypt1, int crypt2, int crypt3)
{
cout << crypt1 << crypt2 << crypt3 << endl;
return 5;
}
弄清楚一个函数是如何工作的,以取代它的实现是你必须付出努力的地方。通过阅读该函数的文档,通常可以很好地了解该函数应该如何工作。如果没有文档或者文档不多,你就得自己去找了。
你可以像平常一样调用原始函数。下面的示例将调用真正的MyCryptKey
函数,而不需要被您所挂接的应用程序调用。
int FunctionForAnotherThread()
{
int cryptValue = MyCrypt2Key(999,135,2);
cryptValue += rand() % 10;
return cryptValue;
}
相关文章:
- C++从 std::async 函数读取命名空间中的全局变量标志
- 使用函数读取文件.txt中的矩阵
- 函数读取最大和min int值,并用文本字符串返回
- 如何使用 void 函数读取名字和姓氏
- 使用 getline 函数读取文件,但第一列显示为空
- 如何从函数读取返回值
- 使用函数C++读取文件
- 使用比较运算符和字符串比较函数读取文本文件的子部分时出现问题
- 其中是升压套接字的函数读取
- 单链表添加函数-读取访问冲突
- 在使用 imread 函数读取 jpg 文件时,是否有任何可能的理由在 opencv 中遇到一些困难
- 使用成员函数读取C++中的文件
- 是否可以使用stdio函数读取Windows应用商店应用程序中的资产
- 函数读取输入并运行函数两次
- C++ 在 main 中打开一个文件以供函数读取
- 函数读取进程内存不断返回ERROR_PARTIAL_COPY
- 如何确定未格式化输入函数读取的字符数
- 为什么我不能使用此 scanf 函数读取输入字符串?
- 使用递归函数读取txt文件的行
- 函数读取二进制文件使用v8