本文使用unidbg对snh48 app进行模拟测试,首先给大家呈现完整代码,然后逐行分析代码内容下面是主要代码
EncryptlibUtils(boolean logging) {
this.logging = logging;
////改for64BIT,setProcessName("com.maihan.tredian")
emulator = AndroidEmulatorBuilder.for64Bit()
.setProcessName("com.pocket.snh48.activity")
.addBackendFactory(new Unicorn2Factory(true))
.build(); // 创建模拟器实例,要模拟32位或者64位,在这里区分
final Memory memory = emulator.getMemory(); // 模拟器的内存操作接口
memory.setLibraryResolver(new AndroidResolver(23)); // 设置系统类库解析
vm = emulator.createDalvikVM(); // 创建Android虚拟机
vm.setVerbose(logging); // 设置是否打印Jni调用细节
vm.setJni(this);
////改o
DalvikModule dm = vm.loadLibrary(new File("unidbg-android/src/test/resources/example_binaries/libencryptlib.so"), false); // 加载libNativeHelper.so到unicorn虚拟内存,加载成功以后会默认调用init_array等函数
dm.callJNI_OnLoad(emulator); // 手动执行JNI_OnLoad函数
module = dm.getModule(); // 加载好的libNativeHelper.so对应为一个模块
TreUtilUtils = vm.resolveClass("com/pocket/snh48/base/net/utils/EncryptlibUtils");
}
void destroy() {
IOUtils.close(emulator);
if (logging) {
System.out.println("destroy");
}
}
public static void main(String[] args) throws Exception {
EncryptlibUtils test = new EncryptlibUtils(true);
String sign_str="1636221462621";
test.call_sign();
test.destroy();
}
////在java中被混淆了,只能通过c++层调用
void call_sign(){
UnidbgPointer md5CTX=emulator.getMemory().malloc(200, false).getPointer();
module.callFunction(emulator,0X1EAD0,md5CTX);
UnidbgPointer inputAddr=emulator.getMemory().malloc(200, false).getPointer();
byte[] inputBytes="12345678".getBytes();
inputAddr.write(inputBytes);
UnidbgPointer outputAddr=emulator.getMemory().malloc(200, false).getPointer();
module.callFunction(emulator,0x1FA38,md5CTX,inputAddr,inputBytes.length,outputAddr);
Inspector.inspect(outputAddr.getByteArray(0,32),"result");
}
这段 Java 代码使用了 Unidbg 框架(一个基于 Unicorn 的 Android native 代码模拟执行框架),目的是在 非 Android 环境(如 PC) 中模拟执行一个名为 libencryptlib.so 的 native 动态库中的函数,从而调用其加密逻辑(如 MD5 或其他签名算法)。
下面逐部分详细解释:
1. 类定义与字段
public class EncryptlibUtils extends AbstractJni {
private final AndroidEmulator emulator;
private final VM vm;
private final Module module;
private final DvmClass TreUtilUtils;
private final boolean logging;
EncryptlibUtils:自定义类,用于封装对 native 库的调用。- 继承
AbstractJni:这是 Unidbg 提供的基类,用于实现 JNI(Java Native Interface)回调,即当 native 代码尝试调用 Java 方法时,可通过此机制模拟。 - 字段说明:
emulator:Android 模拟器实例(基于 Unicorn CPU 模拟器)。

最低0.47元/天 解锁文章
3574

被折叠的 条评论
为什么被折叠?



