gpt4 book ai didi

C++类反汇编

转载 作者:行者123 更新时间:2023-11-30 01:29:04 26 4
gpt4 key购买 nike

我有以下代码:

class Base {
public:
int x,y;
Base() { x=10; y=20; }
virtual void myfunction() { }
};

int main() {
Base *b = new Base();
return 0;
}

反汇编给我这样的东西:

push 0Ch                ; size of Base
call j_<some giberrish> ; IDA gives the comment "operator new(uint)"
add esp, 4 ; function epilogue
mov [ebp+var_E0], eax

几行之后,您将调用构造函数。

mov ecx, [ebp+var_E0]
call j_Base__Base
mov [ebp+var_F4], eax
  • 起初我以为 var_E0 会包含指向实例的指针,但现在我很确定 var_F4 会包含实例的返回值构造函数。
  • 在那种情况下,var_E0 到底包含什么?为什么在调用构造函数之前就移到ecx中了?

最佳答案

它是编译器临时生成的一些内部变量。

当你编写new Base时,编译器生成一个对全局的调用operator new 函数,然后调用返回的构造函数地址。显然,您的编译器保存了从operator new 在内存中,而不是将其保存在寄存器中。

关于C++类反汇编,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6436776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com