带有参数和fastcall的c++typedef
c++ typedef with parameters and fastcall
所以我正在浏览一些源代码,有一件事让我很困惑。我对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);
定义了一个该类型的变量并为其赋值,在这种情况下,它似乎是一个硬编码的内存位置(我不知道它来自哪里)。所有其他事件都只是简单的函数调用
在函数指针上搜索一下,你就可以了解它们了。
相关文章:
- C++:TypeDef使用元组
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 为什么在使用typedef时类推导指南会失败
- 尝试根据类中 typedef 的存在来专门化模板函数
- 如何重新定义MPI_FLOAT,MPI_DOUBLE以 typedef 的方式
- typedef 枚举和枚举类有什么区别?
- 在类模板中使用 typedef 时出错
- 模板类中的 typedef 语句
- 在 typedef 内部使用 const 关键字和在 typedef 外部使用 const 关键字之间有区别吗?
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- C++中"typedef"、"using"、"namespace"和"using namespace"有什么区别?
- 向前声明指向类的 typedef 指针
- 使用typedef'ed返回类型声明友元函数时出现编译器错误
- 如何创建 typedef 结构的前向声明
- 从 Typedef 数据类型中删除常量
- typedef vector size_type in header file
- typedef 别名的析构函数
- 如何使用 typedef 创建多个数组?
- 使用智能指针指向 C 库中的结构,该结构通过 typedef 隐藏实现(即不完整的类型)
- 带有参数和fastcall的c++typedef