包含 RTTI getter 函数的 C++ 结构?

逆向工程 二元分析 C++ 吉德拉 结构
2021-06-14 20:23:53

我正在研究反转 C++ 应用程序,并且遇到了一个包含返回的 getter 函数的结构TypeDescriptor*,我阅读了一些关于 RTTI 和反转 C++ 的文章,但找不到与我所看到的匹配的结构.

由于getter,似乎是编译器生成的结构TypeDescriptor我希望有人能指出我正确的方向。有多个这样的结构,它们大多是连续的,但在我看来并不完全。

该结构的伪代码如下所示:

// These are all function pointers
class SomeClazz
{
    // func1/func2 are pointers to the same function. It looks like a constructor.
    void* func1(void* param1, void** param2);
    void* func2(void* param1, void** param2);
    // This function differs depending on the class. I believe this to be a implementation of a virtual function maybe?
    virtual void handler();
    // Returns a pointer to a RTTI TypeDescriptor depending on the class
    TypeDescriptor* get_type_descriptor();
    void get_something();
} 

这是func1/2函数中的代码,以防万一它是什么:


undefined ** FUN_00125860(longlong param_1,undefined **param_2)

{
  undefined4 uVar1;
  undefined4 uVar2;
  undefined4 uVar3;
  
  *param_2 = (undefined *)&Vftable_maybe_00589ef0;
  uVar1 = *(undefined4 *)(param_1 + 0xc);
  uVar2 = *(undefined4 *)(param_1 + 0x10);
  uVar3 = *(undefined4 *)(param_1 + 0x14);
  *(undefined4 *)(param_2 + 1) = *(undefined4 *)(param_1 + 8);
  *(undefined4 *)((longlong)param_2 + 0xc) = uVar1;
  *(undefined4 *)(param_2 + 2) = uVar2;
  *(undefined4 *)((longlong)param_2 + 0x14) = uVar3;
  return param_2;
}

这是get_type_descriptor

TypeDescriptor * class::get_type_descriptor(void)

{
  return &class_<lambda_88a0d3301c644a20c1df3ad0c52a86e4>_RTTI_Type_Descriptor;
}

////////////
LEA RAX, [class_<lambda_88a0d3301c644a20c1df3ad0c52 ...]
RET

这是get_something,不确定目的是什么或它在做什么:

LEA RAX, [RCX+0x8]
RET

任何帮助/建议都会很棒。谢谢。

2个回答

IIRCtypeid运算符返回一个指向类型信息实例的指针。

总的来说,代码看起来像一个lambda 表达式实现;“构造函数”捕获上下文,以便“处理程序”(lambda 主体)可以从外部作用域访问它需要的变量。

这是一个 lambda 表达式。当 lambda 表达式捕获到它时,它被编译成一个实现定义的结构。在我的情况下,lambda 已捕获,使用 MSVC 将结构_Func_Base定义为:

#pragma warning(push)
#pragma warning(disable : 4265) // class has virtual functions, but destructor is not virtual (/Wall)
// CLASS TEMPLATE _Func_base
template <class _Rx, class... _Types>
class __declspec(novtable) _Func_base { // abstract base for implementation types
public:
    virtual _Func_base* _Copy(void*) const                 = 0;
    virtual _Func_base* _Move(void*) noexcept              = 0;
    virtual _Rx _Do_call(_Types&&...)                      = 0;
    virtual const type_info& _Target_type() const noexcept = 0;
    virtual void _Delete_this(bool) noexcept               = 0;

#if _HAS_STATIC_RTTI
    const void* _Target(const type_info& _Info) const noexcept {
        return _Target_type() == _Info ? _Get() : nullptr;
    }
#endif // _HAS_STATIC_RTTI

    _Func_base()                  = default;
    _Func_base(const _Func_base&) = delete;
    _Func_base& operator=(const _Func_base&) = delete;
    // dtor non-virtual due to _Delete_this()

private:
    virtual const void* _Get() const noexcept = 0;
};
#pragma warning(pop)