package com.liuwei.ndk;
import
com.github.unidbg.AndroidEmulator;
import
com.github.unidbg.Emulator;
import
com.github.unidbg.Module;
import
com.github.unidbg.arm.backend.Unicorn2Factory;
import
com.github.unidbg.debugger.BreakPointCallback;
import
com.github.unidbg.linux.android.AndroidEmulatorBuilder;
import
com.github.unidbg.linux.android.AndroidResolver;
import
com.github.unidbg.linux.android.dvm.
*
;
import
com.github.unidbg.memory.Memory;
import
unicorn.ArmConst;
import
java.io.
File
;
import
java.io.IOException;
public
class
SouFunSec {
private final AndroidEmulator emulator;
private final VM vm;
private final Module module;
private final DvmClass SouFunSec;
private final boolean logging;
SouFunSec(boolean logging) {
this.logging
=
logging;
emulator
=
AndroidEmulatorBuilder.for32Bit()
.setProcessName(
"com.soufun.app"
)
.addBackendFactory(new Unicorn2Factory(true))
.build();
/
/
创建模拟器实例,要模拟
32
位或者
64
位,在这里区分
final Memory memory
=
emulator.getMemory();
/
/
模拟器的内存操作接口
memory.setLibraryResolver(new AndroidResolver(
23
));
/
/
设置系统类库解析
vm
=
emulator.createDalvikVM();
/
/
创建Android虚拟机
vm.setJni(new AbstractJni() {});
vm.setVerbose(logging);
/
/
设置是否打印Jni调用细节
DalvikModule dm
=
vm.loadLibrary(new
File
(
"unidbg-android/src/test/java/com/liuwei/ndk/libSouFunSec.so"
), false);
/
/
加载libttEncrypt.so到unicorn虚拟内存,加载成功以后会默认调用init_array等函数
module
=
dm.getModule();
/
/
加载好的libttEncrypt.so对应为一个模块
SouFunSec
=
vm.resolveClass(
"com/soufun/app/sec/SouFunSec"
);
}
void destroy() throws IOException {
emulator.close();
if
(logging) {
System.out.println(
"destroy"
);
}
}
public static void main(String[] args) throws Exception {
SouFunSec test
=
new SouFunSec(true);
test.callFunc();
test.destroy();
}
private void callFunc() {
emulator.attach().addBreakPoint(module.base
+
0x1710
, new BreakPointCallback() {
@Override
public boolean onHit(Emulator<?> emulator,
long
address) {
System.out.println(
Long
.toHexString(address));
emulator.getBackend().reg_write(ArmConst.UC_ARM_REG_PC, address
+
4
+
1
);
return
true;
}
});
StringObject data
=
new StringObject(vm,
"AndroidPageFrom=zflist&city=%E8%8B%8F%E5%B7%9E&gettype=android&housetype=jjr%2Cwjjr%2Cjx&jkVersion=2&maptype=baidu&messagename=zflist&orderby=15&page=2&pagesize=20&purpose=%E4%BD%8F%E5%AE%85&subwayinfo=1"
);
StringObject result
=
SouFunSec.callStaticJniMethodObject(emulator,
"getSec(Ljava/lang/String;)Ljava/lang/String;"
, data);
/
/
执行Jni方法
System.out.println(
"callFunc执行结果:"
+
result);
}
}