首页
社区
课程
招聘
含有c++类的程序如何逆向
2006-12-31 15:45 4328

含有c++类的程序如何逆向

2006-12-31 15:45
4328
如果只是控制台程序,没有C++类,那很简单,用IDA一下就能找出来,如果里面有自定义函数,也是可以逆向出来的,只是比单纯的main()函数中写测试稍微复杂一点.
然后我写了一个极简单的测试类,但发现再也无法跟踪出来了.请高手帮忙.之前发过一篇类似的,坛主发了一篇有关C++的贴子我看,没看懂,没有从其中找到方法.呵呵.
例子说明:
这个简单的代码,我用IDA调试,居然发现所有和类有关的代码全没有,甚至连sum++的反汇编的代码都没有找到.郁闷得不行.

觉得这样的代码反汇编难度应不是很大才对,怎么我一点边都没摸到,还是方法出现了问题?
class AA
{
public:
AA(int a,int b)
{m_a = a;m_b=b;}
int Add(){ return a+b;}
private:
int m_a;
int m_b;
}
main()
{
printf("hellow world!\n");
AA mya(3,5);
int sum = mya.Add();
sum++;
printf("hellow world end\n");
}

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
打赏
分享
最新回复 (2)
雪    币: 223
活跃值: (10)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
kisser1 2 2006-12-31 16:11
2
0
首先,代码更正如下:
#include <stdio.h>

class AA
{
public:
AA(int a,int b)
{m_a = a;m_b=b;}
int Add(){ return m_a+m_b;}//原来a和b不可用
private:
int m_a;
int m_b;
}; //这里少了一个分号
int main()
{
printf("hellow world!\n");
AA mya(3,5);
int sum = mya.Add();
sum++;
printf("hellow world end\n");
return 0;
}

以上用VC++ 6.0编译通过(默认设置,反汇编代码是Debug版的)。
用OD载入,运行。分析如下:

004012E3  |.  51            push    ecx
004012E4  |.  E8 26FDFFFF   call    test.0040100F //调用main函数,跟进
======================================================================
00401005   $ /E9 F6000000   jmp     test.AA::Add //方法
0040100A   $ |E9 A1000000   jmp     test.AA::AA //构造函数
0040100F   $ |E9 1C000000   jmp     test.main //跳到main函数

======================================================================
main函数:
00401030 >/> \55            push    ebp
00401031  |.  8BEC          mov     ebp, esp
00401033  |.  83EC 4C       sub     esp, 4C
00401036  |.  53            push    ebx
00401037  |.  56            push    esi
00401038  |.  57            push    edi
00401039  |.  8D7D B4       lea     edi, [local.19]
0040103C  |.  B9 13000000   mov     ecx, 13
00401041  |.  B8 CCCCCCCC   mov     eax, CCCCCCCC
00401046  |.  F3:AB         rep     stos dword ptr es:[edi]
//以上是初始化
00401048  |.  68 34204200   push    offset test.??_C@_0P@IMDC@hellow>; /format = "hellow world!
"
0040104D  |.  E8 EE000000   call    test.printf                      ; \printf
00401052  |.  83C4 04       add     esp, 4
//printf("hellow world!\n");
00401055  |.  6A 05         push    5
00401057  |.  6A 03         push    3
00401059  |.  8D4D F8       lea     ecx, [local.2]
0040105C  |.  E8 A9FFFFFF   call    test.0040100A
//调用类的构造函数,可参见上面3个jmp
00401061  |.  8D4D F8       lea     ecx, [local.2]
00401064  |.  E8 9CFFFFFF   call    test.00401005
//调用类的方法
00401069  |.  8945 F4       mov     [local.3], eax
0040106C  |.  8B45 F4       mov     eax, [local.3]
0040106F  |.  83C0 01       add     eax, 1 //sum++
00401072  |.  8945 F4       mov     [local.3], eax
//
00401075  |.  68 1C204200   push    offset test.??_C@_0BC@JIKG@hello>; /format = "hellow world end
"
0040107A  |.  E8 C1000000   call    test.printf                      ; \printf
0040107F  |.  83C4 04       add     esp, 4
//printf("hellow world end\n");
00401082  |.  33C0          xor     eax, eax
00401084  |.  5F            pop     edi
00401085  |.  5E            pop     esi
00401086  |.  5B            pop     ebx
00401087  |.  83C4 4C       add     esp, 4C
0040108A  |.  3BEC          cmp     ebp, esp
0040108C  |.  E8 2F010000   call    test.__chkesp
00401091  |.  8BE5          mov     esp, ebp
00401093  |.  5D            pop     ebp
00401094  \.  C3            retn

对于类的方法及构造函数,这里不列出,自己去对应的地址可以清楚的看到。
在网上有一篇在证明对象只有属性没有方法的文章,题目忘了,自己google下。

你自己可以去试着用Release版编译,然后去调试,这样子,就可以更进一步不需要调试信息的帮助。

更多的收获,还得靠自己去耕耘。
雪    币: 208
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Luis 2007-1-2 09:52
3
0
感谢关注,指导的这么详细。
您所说的debug版本调试,
我在本机上做过。不知您做过release的反汇编没有。
以上的C++代码,release反汇编代码为(OD上):
00401000  /$  68 44704000   PUSH testclas.00407044                   ;  ASCII "hellow world!
"
00401005  |.  E8 16000000   CALL testclas.00401020
0040100A  |.  83C4 04       ADD ESP,4
0040100D  |.  68 30704000   PUSH testclas.00407030                   ;  ASCII "hellow world end
"
00401012  |.  E8 09000000   CALL testclas.00401020
00401017  |.  83C4 04       ADD ESP,4
0040101A  |.  33C0          XOR EAX,EAX
0040101C  \.  C3            RETN

对比一下debug下的反汇编,发现和类有关的所有信息居然都没有了,甚至连sum++的反汇编语句(add     eax, 1 //sum++)都找不到了
00401048  |.  68 34204200   push    offset test.??_C@_0P@IMDC@hellow>; /format = "hellow world!
"
0040104D  |.  E8 EE000000   call    test.printf                      ; \printf
00401052  |.  83C4 04       add     esp, 4
//printf("hellow world!\n");
00401055  |.  6A 05         push    5
00401057  |.  6A 03         push    3
00401059  |.  8D4D F8       lea     ecx, [local.2]
0040105C  |.  E8 A9FFFFFF   call    test.0040100A
//调用类的构造函数,可参见上面3个jmp
00401061  |.  8D4D F8       lea     ecx, [local.2]
00401064  |.  E8 9CFFFFFF   call    test.00401005
//调用类的方法
00401069  |.  8945 F4       mov     [local.3], eax
0040106C  |.  8B45 F4       mov     eax, [local.3]
0040106F  |.  83C0 01       add     eax, 1 //sum++
00401072  |.  8945 F4       mov     [local.3], eax
//
00401075  |.  68 1C204200   push    offset test.??_C@_0BC@JIKG@hello>; /format = "hellow world end
"
0040107A  |.  E8 C1000000   call    test.printf                      ; \printf
0040107F  |.  83C4 04       add     esp, 4
//printf("hellow world end\n");

没有一点有关class的信息。我比较了一下,与debug版本下完全不同,也就是所有与class相关的信息都被隐藏掉了。
对于这一点我很是郁闷。
游客
登录 | 注册 方可回帖
返回