0

我想知道是否可以从函数中读取数据。
我知道我可以使用 detours 来挂钩函数并自由更改参数。
但这就是我对使用弯路的理解。

例如:

//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);
}

该代码绕过游戏中的加密密钥函数,并在调用它之前更改参数。因此,当它被调用时,参数已被更改。

我在想如果函数内部有数据而不是参数怎么办。
如何更改或显示它?

我应该重写整个函数吗?

我想要得到的是使用游戏本身来加密和解密数据包。
我已经挂钩了执行此操作的函数,但我所能做的就是更改参数。
游戏只是继续它的事情。

我在加密之前更改了数据包,因此发送了另一个数据包。但这只有在我尝试发送数据包并对其进行修改时才会发生。我想从字面上调用该函数,而无需等待游戏调用它,然后就可以修改值。
就像我将使用游戏输入我自己的未加密数据包并按加密以查看加密值,反之亦然。

解释或教程链接会很棒。


如果我像这样:

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?
4

1 回答 1

0

您的示例已经走在正确的轨道上,cout并且都endl存在于 detour 函数之外。对于在函数 detour 中放置的代码,实际上并没有任何明确的限制。在函数之外访问数据与任何其他程序相同。

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;
}
于 2013-04-23T08:43:35.710 回答