小试 Xcode 逆向:App 内存监控原理初探(逆向技术必看)

前言

最近看到公司同事的《iOS内存那些事》系列文章,其中的一篇文章讲了他在研究WebKit中内存管理的时候,发现可以用phys_footprint来衡量内存,其结果和xcode debug显示的值基本一致。文章通读下来,收获颇丰~回味之余,突然脑洞了一下,为啥不直接逆向一下Xcode,学习一下xcode debug app时它是怎么实现内存监控的?刚好最近在自学逆向知识,顺便也来练练手~

动手实践
准备一个小项目
运行一下,我们可以在debug面板看到memory report信息

lldb和hopper的使用
通过如下操作,我们可以直接attach Xcode调试

➜  ~ lldb -n Xcode
(lldb) process attach --name "Xcode"
Process 969 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007fffe2bcb34a libsystem_kernel.dylib`mach_msg_trap + 10
libsystem_kernel.dylib`mach_msg_trap:
->  0x7fffe2bcb34a <+10>: retq
    0x7fffe2bcb34b <+11>: nop

libsystem_kernel.dylib`mach_msg_overwrite_trap:
    0x7fffe2bcb34c <+0>:  movq   %rcx, %r10
    0x7fffe2bcb34f <+3>:  movl   $0x1000020, %eax          ; imm = 0x1000020
Target 0: (Xcode) stopped.

Executable module set to "/Applications/Xcode.app/Contents/MacOS/Xcode".
Architecture set to: x86_64h-apple-macosx.
(lldb) c
Process 969 resuming
(lldb)
复制代码
来到Xcode debug面板,可以直接看到app运行时的内存信息。先小试一下那个内存信息栏能否响应点击操作。加个断点,尝试点击一下那个内存栏,bingo,顺利跑到断点处~

(lldb) b -[NSResponder mouseUp:]
Breakpoint 1: where = AppKit`-[NSResponder mouseUp:], address = 0x00007fffcb070177
Process 969 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00007fffcb070177 AppKit`-[NSResponder mouseUp:]
AppKit`-[NSResponder mouseUp:]:
->  0x7fffcb070177 <+0>: pushq  %rbp
    0x7fffcb070178 <+1>: movq   %rsp, %rbp
    0x7fffcb07017b <+4>: popq   %rbp
    0x7fffcb07017c <+5>: jmp    0x7fffcaf94724            ; forwardMethod
Target 0: (Xcode) stopped.(lldb)

复制代码
因为Xcode肯定是x86_64架构编译的,所以通过po $rdi,可以看到点击方法的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值