[原]逆向iOS SDK -- +[UIImage imageNamed:] 的实现
汇编代码:
; Dump of assembler code for function +[UIImage imageNamed:] ; R0 = UIImage, R1 = "imageNamed:", R2 = imageFileName push {r4, r5, r7, lr} ; 从右向左,依次将这些寄存器压栈 movw r1, #62936 ;R1(低16位) = selRef_mainBundle 地址偏移量的低 16 位的 add r7, sp, #8 ; R7 = 栈上的值 movt r1, #3292 ; R1(高16高) = selRef_mainBundle 地址偏移量的高 16 位 movw r0, #44426 ; R0(低16位) = classRef_NSBundle 偏移量的低 16 位 movt r0, #3293 ; R0(高16位) = classRef_NSBundle 偏移量的高 16 位 add r1, pc ; R1 = selRef_mainBundle add r0, pc ; R0 = classRef_NSBundle mov r4, r2 ; R4 = R2 = imageFileName ldr r1, [r1, #0] ; R1 = "mainBundle" ldr r0, [r0, #0] ; R0 = NSBundle blx 0x31f862a4 <dyld_stub_objc_msgSend> ; [NSBundle mainBundle] mov r5, r0 ; R5 = R0 = mainBundle bl 0x31e0abb4 <_UIScreenForce1xScale> ; _UIScreenForce1xScale(), ;判断是否是高清屏:高清屏返回 YES,低分屏返回 NO mov r1, r5 ; R1 = R5 = mainBundle mov r2, r0 ; R2 = R0 = isRetina mov r0, r4 ; R0 = R4 = imageFileName ldmia.w sp!, {r4, r5, r7, lr} ; b.w 0x31bc2898 <_UIImageAtPath> ; ;_UIImageAtPath(NSString *imageFileName, NSBundle *mainBundle, BOOL isRetina) nop ; End of assembler dump. |
伪代码:
+ (UIImage *)imageNamed:(NSString *)imageFileName { NSBundle *mainBundle = [NSBundlemainBundle]; BOOL isRetina = _UIScreenForce1xScale(); return_UIImageAtPath(imageFileName, mainBundle, isRetina); } |