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