-2

所以我决定尝试使用 Ghidra 反编译/反汇编一个带有虚函数和非虚函数的简单 c++ 类。然而; 反编译让我有点困惑。下面是我的源代码和我的反编译。我不明白为什么对非虚函数的调用由诸如打印字符串和其他 3 个奇怪的参数之类的参数组成。这些其他参数是什么?我只能假设其中一个是“This”指针?如果是这样,另外两个是什么?

在 Visual Studio 2k17 x64 版本上编译,没有 pdb

资源

#include <iostream>
#include <stdio.h>

class Person
{
public:
    Person(int val)
    {
        myval = val;
    }

    void PersonFunction()
    {
        printf("this is a person func/n");
    }

    virtual void PersonFunction2()
    {
        printf("this is a person func2/n");
    }

protected:
    int myval = 5;
};

int main(int argc, char** argv)
{
    Person * person = new Person(10);
    std::cout << "Hello World!\n";
    person->PersonFunction();
    person->PersonFunction2();
}

反编译

undefined8
FUN_140001080(undefined8 param_1,undefined8 param_2,undefined8 param_3,undefined8 param_4)

{
  code **ppcVar1;
  
  ppcVar1 = (code **)operator_new(0x10);
  *ppcVar1 = (code *)Person::vftable;
  *(undefined4 *)(ppcVar1 + 1) = 10;
  FUN_1400010e0((longlong *)cout_exref);
  FUN_140001010("this is a person func/n",param_2,param_3,param_4); #what is going on here.. why 3 params?
  (**(code **)*ppcVar1)(ppcVar1); # this, i assume is the virtual function call passing in this ptr
  return 0;
}

// furthermore inside FUN140001010
void FUN_140001010(undefined8 param_1,undefined8 param_2,undefined8 param_3,undefined8 param_4)

{
  undefined8 uVar1;
  undefined8 *puVar2;
  undefined8 local_res10;
  undefined8 local_res18;
  undefined8 local_res20;
  
  local_res10 = param_2;
  local_res18 = param_3;
  local_res20 = param_4;
  uVar1 = __acrt_iob_func(1);
  puVar2 = (undefined8 *)FUN_140001000();
  __stdio_common_vfprintf(*puVar2,uVar1,param_1,0,&local_res10);
  return;
}

谁能解释接受我的字符串和三个参数的函数发生了什么?参数是什么?为什么要传递字符串?

4

1 回答 1

0

所以看起来 MSVC++ 编译器刚刚优化并将 printf 直接内联到 main 中。这是带有 vaargs 的 printf 的外观:

_Check_return_opt_
_CRT_STDIO_INLINE int __CRTDECL printf(
    _In_z_ _Printf_format_string_ char const* const _Format,
    ...)
#if defined _NO_CRT_STDIO_INLINE
;
#else
{
    int _Result;
    va_list _ArgList;
    __crt_va_start(_ArgList, _Format);
    _Result = _vfprintf_l(stdout, _Format, NULL, _ArgList);
    __crt_va_end(_ArgList);
    return _Result;
}
#endif

_Check_return_opt_
_CRT_STDIO_INLINE int __CRTDECL _vfprintf_l(
    _Inout_  FILE*       const _Stream,
    _In_z_   char const* const _Format,
    _In_opt_ _locale_t   const _Locale,
             va_list           _ArgList
    )
#if defined _NO_CRT_STDIO_INLINE
;
#else
{
    return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Stream, _Format, _Locale, _ArgList);
}
#endif
于 2021-03-07T16:15:38.857 回答