带有参数和fastcall的c++typedef

c++ typedef with parameters and fastcall

本文关键字:c++typedef fastcall 参数      更新时间:2023-10-16

所以我正在浏览一些源代码,有一件事让我很困惑。我对c++有点陌生,所以我很难理解这是为了什么。我真的不知道下面的typedef是用来做什么的,以及它在下面的代码中是如何使用的

typedef void (__fastcall *TSecType_long___SetData_t)(DWORD dwAddress, DWORD dwEDX, DWORD dwValue);

这些是用于使用此typedef的方法的一些值。

const TSecType_long___SetData_t TSecType_long___SetData = reinterpret_cast<TSecType_long___SetData_t>(0x00518430); // 56 8B ? 8B ? ? ? ? ? 41 [3rd Result]
const DWORD *const pdwUserLocal = reinterpret_cast<const DWORD *const>(0x016A1234); // 8B ? ? ? ? ? 85 C9 74 ? 83 B8 ? ? ? ? 00 74 ? 8B ? ? ? ? ? 85 C0 7E ? 8B
const DWORD dwTeleportToggleOffset = 0x00008A94; // 8D ? ? ? ? ? 8B ? 8B ? E8 ? ? ? ? 85 ? 0F 85 ? ? ? ? 39 ? ? ? ? ?
const DWORD dwTeleportYOffset = 0x00008AAC; // 8D ? ? ? ? ? ? 8B ? E8 ? ? ? ? 6A ? 8B ? E8 ? ? ? ? 6A 00 68 ? ? ? ?
const DWORD dwTeleportXOffset = dwTeleportYOffset + 0x0C;

对于方法本身:

bool Teleport(_In_ int nX, _In_ int nY)
{
__try
{
    {
        DWORD dwUserLocal = *pdwUserLocal;
        TSecType_long___SetData(dwUserLocal + dwTeleportToggleOffset, NULL, 0);
        TSecType_long___SetData(dwUserLocal + dwTeleportXOffset, NULL, nX);
        TSecType_long___SetData(dwUserLocal + dwTeleportYOffset, NULL, nY);
        TSecType_long___SetData(dwUserLocal + dwTeleportToggleOffset, NULL, 1);
    }
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
    return false;
}
return true;
}

假设您知道typedef是什么(它接受一个数据类型并赋予它另一个名称),那么这就是一个函数typedef。换句话说,TSecType_long___SetData_t是一个接受3个DWORD参数并返回一个void的函数。

在您的情况下,有人先验地知道地址0x00518430包含一个可以在给定TSecType_long___SetData_t API的情况下调用的函数。为了使该地址可调用,地址被重新解释为函数数据类型,并分配给变量TSecType_long___SetData

就像@chris所说的TSecType_long___SetData_t只是一个指向函数的指针的声明,因此具有参数。下面一行:

const TSecType_long___SetData_t TSecType_long___SetData = einterpret_cast<TSecType_long___SetData_t>(0x00518430);

定义了一个该类型的变量并为其赋值,在这种情况下,它似乎是一个硬编码的内存位置(我不知道它来自哪里)。所有其他事件都只是简单的函数调用
在函数指针上搜索一下,你就可以了解它们了。