嘿嘿老规矩先上OC源码:
- (void)viewDidLoad {
[super viewDidLoad];
void(^block)(void) = ^(){
NSLog(@"111");
};
block();
}
汇编:
03-汇编-Block`-[ViewController viewDidLoad]:
...
0x1002a6764 <+68>: adrp x8, 2
0x1002a6768 <+72>: add x8, x8, #0x88 ; =0x88
0x1002a676c <+76>: mov x0, x8
0x1002a6770 <+80>: bl 0x1002a6ba4 ; symbol stub for: objc_retainBlock
0x1002a6774 <+84>: str x0, [sp, #0x8]
-> 0x1002a6778 <+88>: ldr x8, [sp, #0x8]
0x1002a677c <+92>: mov x0, x8
0x1002a6780 <+96>: ldr x8, [x8, #0x10]
0x1002a6784 <+100>: blr x8
.....
首先分析通过adrp指令计算出 block的地址
block的地址 = 2 << 12 + 0x1002a6000 + 0x88 = 0x1002a8088
通过LLDB:查看该内存地址
(lldb) memory read --format x --size 8 0x1002a8088
0x1002a8088: 0x00000001b5791288 0x0000000050000000
0x1002a8098: 0x00000001002a67a8 0x00000001002a8068
0x1002a80a8: 0x00000001b5798610 0x00000000000007c8
0x1002a80b8: 0x00000001002a7685 0x0000000000000003
(lldb) po 0x00000001b5791288
__NSGlobalBlock__
首先我们可以通过Block的isa指针知道这货是啥?就是个NSGlobalBlock
然后我们还能从Block+0x10的位置获取到Block的入口看下图
使用IDA查看会更加方便,后面会用到
扩展:LLDB指令的查看 https://lldb.llvm.org/lldb-gdb.html
网友评论