带有参数和快速调用的 C++ typedef

标签 c++ dword

所以我正在查看一些源代码,这件事让我很困惑。我是 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

关于带有参数和快速调用的 C++ typedef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17518747/

相关文章:

c++ - 为什么这个函数可以返回一个C++ int 引用?

c++ - 未在此范围内声明 OpenCV 符号

c++ - 检测 32 位双字 + 双字进位/C++

c++ - 从偏移创建一个 DWORD 指针

c++ - OpenCV IOS swift 2 :How to implement the CvVideoCameraDelegate protocol process Video Frames

c++ - 使用 C++ 或 Python 生成随机数

c++ - 将 DWORD 写入内存只会覆盖 1 个字节而不是 4 个字节

c++ - 多值 DWORD 枚举作为一个函数参数 C++

c++ - 空字符串加一个整数?

c - 简单交换后 DWORD 强制转换为 float ?