Android SO逆向-多重继承

    0x00

    这一节我们要讨论多重的汇编实现。


    0x01 

    我们先直接看汇编代码:

#include "com_example_ndkreverse7_Lesson7.h"
#include <android/log.h>
#define LOG_TAG "lesson7"
#define ALOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))

class Child1 {
public:
	Child1(int p) {
		ALOGD("Child1 ...");
		p_ = 3;                         
	}

	virtual void Display() {
		ALOGD("Child1 Display:%d", p_);
	}
	int p_;
};

class Child2 {
public:
	Child2(int p) {
		ALOGD("Child2 ...");
		p_ = 5;                       
	}

	virtual void Display() {
		ALOGD("Child2 Display:%d", p_);
	}
	int p_;
};

class GrandChild: public Child2, public Child1 {
public:
	int grandchild;

	GrandChild(int p) :
			Child1(p), Child2(p) {
		ALOGD("GrandChild ...");
		grandchild = 14;
	}

	virtual void Display() {
		ALOGD("GrandChild Display:%d", grandchild);
	}
};

JNIEXPORT void JNICALL Java_com_example_ndkreverse7_Lesson7_main
(JNIEnv * env, jobject jobject) {
	Child2* pGC = new GrandChild(4);
	pGC->Display();
}
    那么,运行后执行的结果如下:

D/lesson7 (18324): Child2 ...
D/lesson7 (18324): Child1 ...
D/lesson7 (18324): GrandChild ...
D/lesson7 (18324): GrandChild Display:14

    0x02

    下面我们使用ida来打开so,对汇编代码做出解释。该汇编代码使用的是调试状态下的汇编代码

.text:70422048                 EXPORT Java_com_example_ndkreverse7_Lesson7_main
.text:70422048 Java_com_example_ndkreverse7_Lesson7_main
.text:70422048                 PUSH    {R3-R5,LR}
.text:7042204A                 MOVS    R0, #0x14       ; unsigned int  在堆上分配20个字节的空间
.text:7042204C                 BL      _Znwj           ; operator new(uint)
.text:70422050                 LDR     R3, =(_ZTV6Child2_ptr - 0x7042205A) ;
.text:70422052                 LDR     R5, =(aLesson7 - 0x7042205E)
.text:70422054                 LDR     R2, =(aChild2___ - 0x70422068)
.text:70422056                 ADD     R3, PC ; _ZTV6Child2_ptr
.text:70422058     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值