[原]逆向iOS SDK -- _UIImageAtPath 的实现(SDK 6.1)
汇编代码:
; 状态:R0 = imageFileName, R1 = mainBundle, R2 = isRetina PUSH {R4-R7,LR} ; R0 = imageFileName, R1 = mainBundle, R2 = isRetina ADD R7, SP, #0xC PUSH.W {R8,R10,R11} STR.W R2, [SP,#0x18+var_1C]! MOV R4, R0 ; R4 = R0 = imageFileName MOV R0, #(selRef_length - 0x17BB0) ; selRef_length MOV R10, R1 ; R10 = R1 = mainBundle ADD R0, PC ; selRef_length LDR R1, [R0] ; "length" MOV R0, R4 ; R0 = R4 = imageFileName BLX.W _objc_msgSend ; [imageFileName length] MOVS R6, #0 ; R6 = 0 CMP R0, #0 ; check if R0 is 0 BEQ.W loc_17D1C ; if R0 is 0, goto the label MOV R0, R4 ; R0 = R4 = imageFileName MOV R1, R10 ; R1 = R10 = mainBundle BL __UICacheNameForImageAtPath ; arg_0:imageFileName, arg_1:mainBundle, result:com.proteas.hello_Default.png MOVW R8, #(:lower16:(__MergedGlobals_36 - 0x17BD4)) MOV R5, R0 ; R5 = R0 = imageCacheName MOVT.W R8, #(:upper16:(__MergedGlobals_36 - 0x17BD4)) ADD R8, PC ; __MergedGlobals_36 ADD.W R11, R8, #0x10 ; R11 = R8 + 16 MOV R0, R11 ; lock, OSSpinLock*, 访问全局变量,加锁 BLX.W _OSSpinLockLock ; arg_0: OSSpinLock* LDR.W R0, [R8,#(dword_62C524 - 0x62C510)] ; R0 = cachedImageMap, key:imageCacheName, value:UIImageObject MOVS R6, #0 ; R6 = 0 CBZ R0, loc_17BEC ; if cachedImageMap is nil, goto the label MOV R1, R5 ; R1 = R5 = imageCacheName BLX.W _CFDictionaryGetValue ; CFDictionaryGetValue(cachedImageMap, imageCacheName) MOV R6, R0 ; R6 = R0 = cachedUIImageObject loc_17BEC: MOV R0, #(selRef_retainCount - 0x17BF8) ; selRef_retainCount ADD R0, PC ; selRef_retainCount LDR R1, [R0] ; "retainCount" MOV R0, R6 ; R0 = R6 = cachedUIImageObject BLX.W _objc_msgSend ; [cachedUIImageObject retainCount] CBNZ R0, loc_17C08 ; if retainCount of cachedUIImageObject is not 0, goto the label MOV R0, R11 ; lock BLX.W _OSSpinLockUnlock B loc_17C50 loc_17C08: MOV R0, #(selRef__isCached - 0x17C14) ; selRef__isCached ADD R0, PC ; selRef__isCached LDR R1, [R0] ; R1 = "_isCached" MOV R0, R6 ; R0 = R6 = cachedUIImageObject BLX.W _objc_msgSend ; R0 = isCached TST.W R0, #0xFF ; check if R0 is true BNE loc_17C46 ; if not cached, goto the label MOV R0, #(selRef_retain - 0x17C2C) ; selRef_retain ADD R0, PC ; selRef_retain LDR R1, [R0] ; "retain" MOV R0, R6 ; R0 = R6 = cachedUIImageObject BLX.W _objc_msgSend ; [cachedUIImageObject retain] MOVW R0, #(:lower16:(selRef__setCached_ - 0x17C40)) MOVS R2, #1 ; R2 = 1 MOVT.W R0, #(:upper16:(selRef__setCached_ - 0x17C40)) ADD R0, PC ; selRef__setCached_ LDR R1, [R0] ; "_setCached:" MOV R0, R6 ; R0 = R6 = cachedUIImageObject BLX.W _objc_msgSend ; [cachedUIImageObject _setCached:YES] loc_17C46: MOV R0, R11 ; lock BLX.W _OSSpinLockUnlock ; 释放锁 CMP R6, #0 ; check if cachedUIImageObject is nil BNE loc_17D1C ; if not nil, goto the label loc_17C50: MOVW R3, #(:lower16:(_GetImageAtPath+1 - 0x17C60)) MOV R0, R4 ; R0 = R4 = imageFileName MOVT.W R3, #(:upper16:(_GetImageAtPath+1 - 0x17C60)) LDR R2, [SP,#0x1C+var_1C] ; R2 = isRetina ADD R3, PC ; _GetImageAtPath ; R3 = _GetImageAtPath MOV R1, R10 ; R1 = R10 = mainBundle BL __UIImageCallFunctionForAppropriatePath ; arg_0:imageFileName, arg_1 = mainBundle, arg_2 = isRetina, arg_3 = _GetImageAtPath MOV R6, R0 ; R6 = R0 = UIImageObject CMP R6, #0 ; check if UIImageObject is nil BEQ loc_17D1C ; if failed, goto label MOV R0, R11 ; lock BLX.W _OSSpinLockLock LDR.W R0, [R8,#0x14] ; R0 = pointer to imageCacheMap CBNZ R0, loc_17CAE ; R1 = R5 = imageCacheName MOVW R0, #(:lower16:(_kCFTypeDictionaryKeyCallBacks_ptr - 0x17C86)) MOVS R1, #0 ; R1 = capacity = 0 MOVT.W R0, #(:upper16:(_kCFTypeDictionaryKeyCallBacks_ptr - 0x17C86)) MOVS R3, #0 ; R3 = valueCallBacks = 0 ADD R0, PC ; _kCFTypeDictionaryKeyCallBacks_ptr LDR R2, [R0] ; _kCFTypeDictionaryKeyCallBacks MOVS R0, #0 ; R0 = allocator = NULL BLX.W _CFDictionaryCreateMutable ; R0 = cachedImageMap MOVW R1, #(:lower16:(_kCFTypeDictionaryValueCallBacks_ptr - 0x17C9E)) MOVS R2, #0 ; R2 = keyCallBacks = NULL MOVT.W R1, #(:upper16:(_kCFTypeDictionaryValueCallBacks_ptr - 0x17C9E)) STR.W R0, [R8,#0x14] ADD R1, PC ; _kCFTypeDictionaryValueCallBacks_ptr MOVS R0, #0 ; R0 = allocator = NULL LDR R3, [R1] ; _kCFTypeDictionaryValueCallBacks MOVS R1, #0 ; R1 = capacity = 0 BLX.W _CFDictionaryCreateMutable STR.W R0, [R8,#0x18] LDR.W R0, [R8,#0x14] loc_17CAE: MOV R1, R5 ; R1 = R5 = imageCacheName BLX.W _CFDictionaryContainsKey CBNZ R0, loc_17CF8 ; if has cached, goto the label MOVW R0, #(:lower16:(selRef__setNamed_ - 0x17CC4)) MOVS R2, #1 ; R2 = YES MOVT.W R0, #(:upper16:(selRef__setNamed_ - 0x17CC4)) ADD R0, PC ; selRef__setNamed_ LDR R1, [R0] ; "_setNamed:" MOV R0, R6 ; R0 = R6 = UIImageObject BLX.W _objc_msgSend ; [UIImageObject _setNamed:YES] MOVW R0, #(:lower16:(selRef__setCached_ - 0x17CD8)) MOVS R2, #1 MOVT.W R0, #(:upper16:(selRef__setCached_ - 0x17CD8)) ADD R0, PC ; selRef__setCached_ LDR R1, [R0] ; "_setCached:" MOV R0, R6 BLX.W _objc_msgSend ; [UIImageObject _setCached:YES] LDR.W R0, [R8,#0x14] ; R0 = cachedImageMap MOV R1, R5 ; R1 = R5 = imageCacheName MOV R2, R6 ; R2 = R6 = UIImageObject BLX.W _CFDictionarySetValue ; arg_0:cachedImageMap, arg_1 = imageCacheName, arg_2 = imageObject LDR.W R0, [R8,#0x18] MOV R1, R6 ; R1 = R6 = UIImageObject MOV R2, R5 ; R2 = R5 = imageCacheName BLX.W _CFDictionarySetValue ; arg_0: dictionary, arg_1: imageObject, arg_2 = imageCacheName B loc_17D16 loc_17CF8: MOV R0, #(selRef_release - 0x17D04) ; selRef_release ADD R0, PC ; selRef_release LDR R1, [R0] ; "release" MOV R0, R6 ; R0 = R6 = UIImageObject BLX.W _objc_msgSend ; [UIImageObject release] LDR.W R0, [R8,#0x14] ; R0 = cachedImageMap MOV R1, R5 ; R1 = R5 = imageCacheName BLX.W _CFDictionaryGetValue MOV R6, R0 ; R6 = R0 = result UIImage instance loc_17D16: MOV R0, R11 ; lock BLX.W _OSSpinLockUnlock ; release spin lock loc_17D1C: MOV R0, R6 ; R0 = R6 = nil ADD SP, SP, #4 POP.W {R8,R10,R11} POP {R4-R7,PC} |
伪代码:
NSDictionary *gCachedImageMapNameToImage = nil; NSDictionary *gCachedImageMapImageToName = nil; _UIImageAtPath(NSString *imageFileName, NSBundle *mainBundle, BOOL isRetina) { if ([imageFileName length] == 0) returnnil; if (gCachedImageMapNameToImage == nil) { gCachedImageMapNameToImage = [[NSMutableDictionaryalloc] init]; gCachedImageMapImageToName = [[NSMutableDictionaryalloc] init]; } NSString *imageCacheName = _UICacheNameForImageAtPath(imageFileName, mainBundle); UIImage *cachedImage = [gCachedImageMapNameToImageobjectForKey:imageCacheName]; if (cachedImage == nil) { cachedImage = _UIImageCallFunctionForAppropriatePath(imageFileName, mainBundle, isRetina, _UIImageAtPath); if (cachedImage == nil) { returnnil; } else { [gCachedImageMapNameToImagesetObject:cachedImage forKey:imageCacheName]; [gCachedImageMapImageToNamesetObject:imageCacheName forKey:cachedImage]; [cachedImage _setNamed:YES]; [cachedImage _setCached:YES]; } } else { if (![cachedImage _isCached]) { [cachedImage _setCached:YES]; } } return cachedImage; } |
[原]逆向iOS SDK -- _UIImageAtPath 的实现(SDK 6.1)的更多相关文章
- [原]逆向iOS SDK -- _UIImageAtPath 的实现(SDK 5.1)
注释过的反汇编代码:http://pan.baidu.com/share/link?shareid=3491166579&uk=537224442 伪代码(不精确,仅供参考): NSStrin ...
- [原]逆向iOS SDK -- “添加本地通知”的流程分析
观点: 代码面前没有秘密 添加通知的 Demo 代码 - (void)scheduleOneLocalNotification { [[UIApplication sharedApplication] ...
- [原]逆向iOS SDK -- +[UIImage imageNamed:] 的实现
汇编代码: ; Dump of assembler code for function +[UIImage imageNamed:] ; R0 = UIImage, R1 = "imageN ...
- [Office][C#] NPOI、OpenXML SDK、OpenOffice.org SDK 写入资料到 EXCEL 档案[转]
原文地址:http://www.dotblogs.com.tw/chou/archive/2010/04/29/14912.aspx 一.簡介 要將資料寫入 EXCEL 檔案有許多的方法,但假如電腦不 ...
- Android SDK Tools和Android SDK Platform-tools
SDK Platform 可以理解为版本,因此有 SDK Platform 7,SDK Platform 8等等Android SDK Tools 是各个版本都可通用的工具文件夹,里面有draw9pa ...
- 阿里云SDK手册之java SDK
进行阿里云sdk开发的前提是已经购买阿里云的相关服务才能调用阿里的相关接口进行开发.最近公司在做云管控的项目,于是进行下摘录总结. 一. 环境准备 阿里云针对不同的开发语言提供不同的sdk,由于项目用 ...
- 打开SDK Manager检查Android SDK下载和更新失败的解决方法
[故障描述] 打开SDK Manager检查Android SDK状况,出现以下情况: Failed to fetch URL https://dl-ssl.google.com/android/r ...
- “AIR SDK 0.0: AIR SDK location “...\devsdks\AIRSDK\Win” does not exist.”问题解决~
原文同步至:http://www.waylau.com/air-sdk-0-0-air-sdk-location-does-not-exist-address/ 导入AS3项目时提示“AIR SDK ...
- Android sdk platform,sdk tools,sdk Build tools,sdk platform tools 的关系
1. sdk platform 简单理解为系统版本 最新级别: 28:Android 9 27:Android 8.1 26:Android 8.0 25:Android 7.1 24:Android ...
随机推荐
- xcode于Archive当产生安装包遇到ld: library not found for -lPods
此问题是由能力很困扰,通常有以下几个方案 进target的 Build Phases- Link binary Library.到场libPods.a,假设是红.删,能够 其他解决方案 Build S ...
- [ACM] POJ 3061 Subsequence (仿真足)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8403 Accepted: 3264 Descr ...
- utf8 和 UTF-8 在使用中的差别
在使用中经常遇到utf-8和utf8,如今最终弄明确他们的使用不同之处了,如今来和大家分享一下,以下我们看一下utf8 和 UTF-8 有什么差别 "UTF-8"是标准写法,ph ...
- 使用WebBrowser控件时在网页元素上绘制文本或其他自定义内容
原文:使用WebBrowser控件时在网页元素上绘制文本或其他自定义内容 第一次在CNBlogs上发Post是提出一个有关使用WebBrowser控件时对SELECT网页元素操作的疑惑,这个问题至今也 ...
- NotePad++ for PHP
原文:NotePad++ for PHP 一.安装设置 1.首先根据你的系统下载相应的安装文件.http://notepad-plus-plus.org/ Notepad++插件:http://sou ...
- iOS 学习
iOS 学习资料 (适合初学者) 本文资料来源于GitHub 一.视频教程(英文) Developing iOS 7 Apps for iPhone and iPad斯坦福开放教程之一, 课程主要讲解 ...
- dozer-初识
1.简介 dozer是一种JavaBean的映射工具,类似于apache的BeanUtils.但是dozer更强大,它可以灵活的处理复杂类型之间的映射.不 但可以进行简单的属性映射.复杂的类型 ...
- selenium之多线程启动grid分布式测试框架封装(一)
一.设计思路 在国内市场上,IE内核的浏览器占据了绝大部分的市场份额,那么此次框架封装将进行IE系列的浏览器进行多线程并发执行分布式测试的封装. 运行时主进程与多线程关系如下:
- td中的值自动换行
设置td中的值自动换行在<td ></td> 中加上这样一句代码,可以简省设置,使长字符串换行.而不用设置width,height. style="word-wrap ...
- IntelliJ IDEA对开发者的三大诱惑
IntelliJ IDEA作为最聪明的Java开发工具,不在只是对Java语言的支持,其中还包括Scala,Groovy 和其他语言. 对于任何一个开发者,好的工具就是为提高开发效率的.那么Intel ...