1. 基于原生Unicorn API进行Hook时,不需要考虑是否 + 1,会自己转换
    2. Unicorn原生的Hook功能强大,而且不容易被检测
    3. Unicorn原生API进行inline hook

    image.png

    1. void callFunc() {
    2. emulator.getBackend().hook_add_new(new CodeHook() {
    3. @Override
    4. public void hook(Backend backend, long address, int size, Object user) {
    5. System.out.println("hook...");
    6. RegisterContext context = emulator.getContext();
    7. if (address == module.base + 0x1FF4){
    8. emulator.getUnwinder().unwind();
    9. Pointer md5Ctx = context.getPointerArg(0);//MD5Update第一个参数
    10. Inspector.inspect(md5Ctx.getByteArray(0, 32), "md5Ctx");
    11. Pointer plainText = context.getPointerArg(1);//MD5Update第二个参数
    12. int length = context.getIntArg(2);//MD5Update第三个参数
    13. Inspector.inspect(plainText.getByteArray(0, length), "plainText");
    14. }else if (address == module.base + 0x2004){
    15. Pointer cipherText = context.getPointerArg(1);
    16. Inspector.inspect(cipherText.getByteArray(0, 16), "cipherText");}
    17. }
    18. @Override
    19. public void onAttach(UnHook unHook) {
    20. }
    21. @Override
    22. public void detach() {
    23. }
    24. },module.base +0x1FE8,module.base +0x2004,"a123456");
    25. StringObject md5Result = NativeHelper.callStaticJniMethodObject(emulator, "md5(Ljava/lang/String;)Ljava/lang/String;", new StringObject(vm, "xiaojianbang")); // 执行Jni方法
    26. System.out.println("md5Result: " + md5Result.getValue());
    27. }
    • RegisterContext context = emulator.getContext(); 获取一个结构体
    • MD5Update的参数如图所示,我们使用结构体下的getPointerArg方法获取对应的参数
    • 打印调用栈 :emulator.getUnwinder().unwind()