吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2004|回复: 12
上一主题 下一主题
收起左侧

[MacOS逆向] Hopper Disassembler for macOS之内存检测

[复制链接]
跳转到指定楼层
楼主
nmweizi 发表于 2025-4-29 01:18 回帖奖励
本帖最后由 nmweizi 于 2025-4-29 07:33 编辑
  • Hopper Disassembler 有内存检测,当内存代码被patch时,会异常退出。
    现在有个重要函数,地址是114FE,通过frida hook

function hook_sub_114FE() {
    //mem_patch(surge_base.base.add(0x114FE),64,1);
    [i]x114FE_bak = [i]x114FE_addr.readByteArray(16);

    Interceptor.attach([i]surge_base.base.add(0x114FE), {
        onEnter: function (args) {
        },

        // onLeave is called after the original function executes, before it returns
        onLeave: function (retval) {
            //console.log("[+] sub_1000CC940 returned (via attach) - onLeave");
            [i]console.log("0x114FE    Original return value:", retval, "->", 1); // Log original return value
            retval.replace(0x1);
            //sub_114FE.detach();
        }
    });
}

启动后,打开一个文件反编译,就会崩溃。  

使用硬件断点分析读取内存操作

参考了代码(https://github.com/hackcatml/frida-watchpoint-tutorial
frida 在新版本中增加了硬件断点操作。
在114FE处,下硬件断点。
installWatchpoint(0x114FE, 1, "r")

function installWatchpoint(addr, size, conditions) {
    _addr = addr;
    _size = size;
    _conditions = conditions;
    threads = Process.enumerateThreads();
    Process.setExceptionHandler(e => {
        if (['breakpoint', 'single-step'].includes(e.type)) {
            console.log(`\n[!] ${e.context.pc} ${e.context.pc.sub(surge_base.base)} tried to "${_conditions}" at ${_addr}`);
            for (const thread of threads) {
                if (thread.id === Process.getCurrentThreadId()) {
                    thread.unsetHardwareWatchpoint(0);
                    unsetWatchPoint = true;
                    return true;
                }
            }
        }
        return false;
    });
    for (const thread of threads) {
        try {
            thread.setHardwareWatchpoint(0, addr, size, conditions);
            console.log(` HardwareWatchpoint set at ${addr} (${thread.id} ${thread.name})`);
        } catch (error) {}
    }
}

function reInstallWatchPoint() {
    for (const thread of threads) {
        try {
            thread.setHardwareWatchpoint(0, _addr, _size, _conditions);
        } catch (error) {}
    }
}

var int = setInterval(() => {
    if (unsetWatchPoint) {
        reInstallWatchPoint();
        unsetWatchPoint = false;
    }
}, 0);

可以看到有两个地方在读取内存并校验,我们选择其中一个。

找到调用地方, -[HopperDocument logErrorStringMessage:]
hook 这个函数,在进入时,恢复内存,在离开时,设置hook。

function logErrorStringMessage() {
    var logErrorStringMessage = ObjC.classes.HopperDocument["- logErrorStringMessage:"];
    Interceptor.attach(logErrorStringMessage.implementation, {
        onEnter(args) {
            mylog("logErrorStringMessage...")
            write_mem(x114FE_addr,x114FE_bak);
        },
        onLeave: function (retval) {
            write_mem(x114FE_addr,x114FE_patch);
        }
    })
        }

再次启动程序,会发现已经检测不到内存修改了。  

类似方法,可以找到tp_const解密算法,算法挺简单的。

免费评分

参与人数 3威望 +1 吾爱币 +23 热心值 +3 收起 理由
Hmily + 1 + 20 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
杨辣子 + 1 + 1 谢谢@Thanks!
dryzh + 2 + 1 奈斯,16.5 出的硬件断点就学废了,666

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

沙发
xixicoco 发表于 2025-4-29 01:23
这个方法好啊,硬件断点
3#
w668 发表于 2025-4-29 07:58
4#
walykyy 发表于 2025-4-29 08:06
5#
zoscos 发表于 2025-4-29 11:43
感谢大佬分享
6#
woshixiaocaini1 发表于 2025-4-29 13:49
感谢大佬分享
7#
wanmeiyanchu 发表于 2025-4-29 14:58
佩服佩服,楼主牛
感谢大佬分享
8#
dryzh 发表于 2025-4-29 15:30
奈斯,16.5 出的硬件断点就学废了,666
9#
pl52pj 发表于 2025-4-29 15:56
感谢分享!
10#
mengxz2023 发表于 2025-4-29 18:13
学习学习,感谢大佬分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-21 00:07

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表