c++类的反汇编代码的实现【DEBUG】
2013-07-04 23:02
239 查看
int main( ){
01104810 push ebp
01104811 mov ebp,esp
01104813 sub esp,0E8h
01104819 push ebx
0110481A push esi
0110481B push edi
0110481C lea edi,[ebp-0E8h]
01104822 mov ecx,3Ah
01104827 mov eax,0CCCCCCCCh
0110482C rep stos dword ptr es:[edi]
0110482E mov eax,dword ptr ds:[0110F0E0h]
01104833 xor eax,ebp
01104835 mov dword ptr [ebp-4],eax
fruit apple = fruit("apple",3.1f,100.00f); //类调用构造函数进行初始化,apple 是类fruit 的一个实例,为main函数内的一个局部变量
01104838 push ecx ;ecx = 00000000 ,作用是提高栈顶位置用于存放构造函数的参数
01104839 movss xmm0,dword ptr ds:[110CD50h]
; 将0000c842 复制到xmm0 寄存器的低32 位
01104841 movss dword ptr [esp],xmm0 ;将xmm0 的低32 位存放到栈顶位置,参数3
01104846 push ecx ;作用如上,保存构造函数的参数
01104847 movss xmm0,dword ptr ds:[110CD4Ch]
;参数2
fruit apple = fruit("apple",3.1f,100.00f);
0110484F movss dword ptr [esp],xmm0
01104854 push 110CC98h ; 将apple 字符串的首地址压栈作为构造函数的参数 ,参数1
01104859 lea ecx,[apple] ;此处是一个特殊的地方,构造函数只有三个参数,此处使用ecx寄存器保存apple对象地址的作用是什么?
0110485C call fruit::fruit (011011B8h) ;调用构造函数初始化apple 对象
apple.show_fruit();
01104861 lea ecx,[apple]
01104864 call fruit::show_fruit (01101217h)
return 0;
01104869 xor eax,eax
}
// 类定义部分的反汇编代码
#include<iostream>
#include<cstdio>
class fruit {
private:
char name[20];
float price;
float weight;
public:
fruit(char name_[] , float price_ , float weight_){
01102BE0 push ebp ;自动从栈中获取保存局部变量的地址空间并使用cccccccc 填充该部分空间
01102BE1 mov ebp,esp
01102BE3 sub esp,0CCh
01102BE9 push ebx
01102BEA push esi
01102BEB push edi
01102BEC push ecx
01102BED lea edi,[ebp-0CCh]
01102BF3 mov ecx,33h
01102BF8 mov eax,0CCCCCCCCh
01102BFD rep stos dword ptr es:[edi]
01102BFF pop ecx ;
01102C00 mov dword ptr [this],ecx ;由此处可以看出ecx中apple的地址是为了初始化this 指针。
strcpy_s(name,name_);
01102C03 mov eax,dword ptr [name_] ;将name_ ,name 入栈,然后调用strcpy_s 函数初始化apple 对象的name 成员
01102C06 push eax
01102C07 mov ecx,dword ptr [this]
;
01102C0A push ecx
01102C0B call strcpy_s<20> (011014A6h)
01102C10 add esp,8 ; 保持栈平衡
price = price_;
01102C13 mov eax,dword ptr [this]
;初始化price 对象成员
01102C16 movss xmm0,dword ptr [price_]
01102C1B movss dword ptr [eax+14h],xmm0 ; eax + 14 h = eax + 20 (20 是name字符数组的大小) 是apple 对象中price 成员的地址 ;eax = this ,this 在C++ 中代表对象的地址
weight = weight_;
01102C20 mov eax,dword ptr [this]
;初始化weight 对象成员
01102C23 movss xmm0,dword ptr [weight_]
01102C28 movss dword ptr [eax+18h],xmm0 ; eax + 18h 是对象中weight 的地址
}
01102C2D mov eax,dword ptr [this]
01102C30 pop edi
01102C31 pop esi
01102C32 pop ebx
01102C33 add esp,0CCh
01102C39 cmp ebp,esp
01102C3B call __RTC_CheckEsp (01101339h)
01102C40 mov esp,ebp
01102C42 pop ebp
01102C43 ret 0Ch
思考:this 指针存放的位置?
// source code
01104810 push ebp
01104811 mov ebp,esp
01104813 sub esp,0E8h
01104819 push ebx
0110481A push esi
0110481B push edi
0110481C lea edi,[ebp-0E8h]
01104822 mov ecx,3Ah
01104827 mov eax,0CCCCCCCCh
0110482C rep stos dword ptr es:[edi]
0110482E mov eax,dword ptr ds:[0110F0E0h]
01104833 xor eax,ebp
01104835 mov dword ptr [ebp-4],eax
fruit apple = fruit("apple",3.1f,100.00f); //类调用构造函数进行初始化,apple 是类fruit 的一个实例,为main函数内的一个局部变量
01104838 push ecx ;ecx = 00000000 ,作用是提高栈顶位置用于存放构造函数的参数
01104839 movss xmm0,dword ptr ds:[110CD50h]
; 将0000c842 复制到xmm0 寄存器的低32 位
01104841 movss dword ptr [esp],xmm0 ;将xmm0 的低32 位存放到栈顶位置,参数3
01104846 push ecx ;作用如上,保存构造函数的参数
01104847 movss xmm0,dword ptr ds:[110CD4Ch]
;参数2
fruit apple = fruit("apple",3.1f,100.00f);
0110484F movss dword ptr [esp],xmm0
01104854 push 110CC98h ; 将apple 字符串的首地址压栈作为构造函数的参数 ,参数1
01104859 lea ecx,[apple] ;此处是一个特殊的地方,构造函数只有三个参数,此处使用ecx寄存器保存apple对象地址的作用是什么?
0110485C call fruit::fruit (011011B8h) ;调用构造函数初始化apple 对象
apple.show_fruit();
01104861 lea ecx,[apple]
01104864 call fruit::show_fruit (01101217h)
return 0;
01104869 xor eax,eax
}
// 类定义部分的反汇编代码
#include<iostream>
#include<cstdio>
class fruit {
private:
char name[20];
float price;
float weight;
public:
fruit(char name_[] , float price_ , float weight_){
01102BE0 push ebp ;自动从栈中获取保存局部变量的地址空间并使用cccccccc 填充该部分空间
01102BE1 mov ebp,esp
01102BE3 sub esp,0CCh
01102BE9 push ebx
01102BEA push esi
01102BEB push edi
01102BEC push ecx
01102BED lea edi,[ebp-0CCh]
01102BF3 mov ecx,33h
01102BF8 mov eax,0CCCCCCCCh
01102BFD rep stos dword ptr es:[edi]
01102BFF pop ecx ;
01102C00 mov dword ptr [this],ecx ;由此处可以看出ecx中apple的地址是为了初始化this 指针。
strcpy_s(name,name_);
01102C03 mov eax,dword ptr [name_] ;将name_ ,name 入栈,然后调用strcpy_s 函数初始化apple 对象的name 成员
01102C06 push eax
01102C07 mov ecx,dword ptr [this]
;
01102C0A push ecx
01102C0B call strcpy_s<20> (011014A6h)
01102C10 add esp,8 ; 保持栈平衡
price = price_;
01102C13 mov eax,dword ptr [this]
;初始化price 对象成员
01102C16 movss xmm0,dword ptr [price_]
01102C1B movss dword ptr [eax+14h],xmm0 ; eax + 14 h = eax + 20 (20 是name字符数组的大小) 是apple 对象中price 成员的地址 ;eax = this ,this 在C++ 中代表对象的地址
weight = weight_;
01102C20 mov eax,dword ptr [this]
;初始化weight 对象成员
01102C23 movss xmm0,dword ptr [weight_]
01102C28 movss dword ptr [eax+18h],xmm0 ; eax + 18h 是对象中weight 的地址
}
01102C2D mov eax,dword ptr [this]
01102C30 pop edi
01102C31 pop esi
01102C32 pop ebx
01102C33 add esp,0CCh
01102C39 cmp ebp,esp
01102C3B call __RTC_CheckEsp (01101339h)
01102C40 mov esp,ebp
01102C42 pop ebp
01102C43 ret 0Ch
思考:this 指针存放的位置?
// source code
#include<iostream> #include<cstdio> class fruit { private: char name[20]; float price; float weight; public: fruit(char name_[] , float price_ , float weight_){ strcpy_s(name,name_); price = price_; weight = weight_; } void set_name(char m_name[]){ strcpy_s(name,m_name); } void set_price(float m_price){ price = m_price; } void set_weight(float m_weight){ weight = m_weight; } void show_fruit(){ std::cout << "name: "; std::cout << name << std::endl; std::cout << "price: " << price << std::endl; std::cout << "weight: "<< weight << std::endl; } }; int main(){ fruit apple = fruit("apple",3.1f,100.00f); apple.show_fruit(); return 0; }
相关文章推荐
- 实现只在debug配置下执行部分代码
- adb代码实现及debug
- 一个实现了APP内部集中式通知中心,简化通知管理,简化代码逻辑和debug
- C++类String的实现代码
- 在C#中使用Conditional元数据attribute来实现Debug代码
- 《c/c++商用工程之道》代码实现之1_debug工具
- FB AS3 中,使用条件编译,实现debug、release的代码分离编译。
- FB AS3 中,使用条件编译,实现debug、release的代码分离编译。
- QT入门笔记--信号和槽(附简单的C++类实现代码)
- C++ 动态内存的分配与释放反汇编代码【DEBUG】
- C++语言的数组在汇编代码中的实现【DEBUG】
- 《逆向工程核心原理》<04-30> 通过Debug修改代码实现API钩取的技术
- 用debug实现dos下重启的代码
- C++类模板 实现队列的链式存储结构算法 《数据结构》(北京科海) 部分代码摘抄,自己编写运行
- erlang使用gen_server实现质数服务器(手打代码,还debug了几个错误)
- 为jQuery.Treeview添加右键菜单的实现代码
- 接入脚本interface.php实现代码
- 算法代码实现之堆排序,C/C++实现
- Java反射实现不同对象相同代码地对象查询和封装
- jquery 实现复选框的全选操作实例代码