[原]逆向iOS SDK -- _UIImageAtPath 的实现(SDK 5.1)
注释过的反汇编代码:http://pan.baidu.com/share/link?shareid=3491166579&uk=537224442
伪代码(不精确,仅供参考):
|
NSString* _UICacheNameForImageAtPath(NSString *imageName, NSBundle *bundle); NSString* ProductSuffix(); UIImage* GetImageAtPath(NSString *imageFilePath, CGFloat scale); NSMutableDictionary *gCacheNameToImageMap = nil; NSMutableDictionary *gImageToCacheNameMap = nil; BOOL __prefer2xImages = NO; UIImage *_UIImageAtPath(NSString *imageFileName, NSBundle *mainBundle, BOOL shouldForce1xScale) { // imageFileName = @"Default.png" if ([imageFileName length] == 0) returnnil; // bundleIdentifier_imageFileName NSString *cacheNameOfImage = _UICacheNameForImageAtPath(imageFileName, mainBundle); UIImage *resultImage = nil; if (gCacheNameToImageMap != nil) { resultImage = [gCacheNameToImageMapobjectForKey:cacheNameOfImage]; if (resultImage != nil) { if (![resultImage _isCached]) { [resultImage retain]; } [resultImage _setCached:YES]; return resultImage; } } else { gCacheNameToImageMap = [NSMutableDictionarydictionary]; gImageToCacheNameMap = [NSMutableDictionarydictionary]; } BOOL force1xScale = NO; if (__prefer2xImages) { force1xScale = shouldForce1xScale; } NSString *imageExt = [imageFileName pathExtension]; if ([imageExt length] == 0) { imageExt = @"png"; } NSString *bundlePath = nil; if (mainBundle != nil) { bundlePath = [mainBundle bundlePath]; } NSString *productSuffix = ProductSuffix();// ~iphone, ~ipad NSString *imageNameWithoutSuffix = [imageFileName stringByReplacingOccurrencesOfString:productSuffix withString:@""]; // Default NSString *imageNameWithoutSuffixAndExt = [imageNameWithoutSuffix stringByDeletingPathExtension]; // Default~iphone NSString *imageNameWithSuffix = [imageNameWithoutSuffixAndExt stringByAppendingString:productSuffix]; // Default@1x NSString *imageName1x = [imageNameWithoutSuffixAndExt stringByAppendingString:@"@1x"]; // Default@1x~iphone NSString *imageName1xWithSuffix = [imageName1x stringByAppendingString:productSuffix]; // Default_1only_ NSString *imageName_1only_ = [imageNameWithoutSuffixAndExt stringByAppendingString:@"_1only_"]; // Default_1only_~ipnone NSString *imageName_1only_WithSuffix = [imageName_1only_ stringByAppendingString:productSuffix]; // Default@2x NSString *imageName2x = [imageNameWithoutSuffixAndExt stringByAppendingString:@"@2x"]; // Default@2x~iphone NSString *imageName2xWithSuffix = [imageName2x stringByAppendingString:productSuffix]; // Default_2only_@2x NSString *imageName_2only_2x = [imageNameWithoutSuffixAndExt stringByAppendingString:@"_2only_@2x"]; // Default_2only_@2x~iphone NSString *imageName_2only_2xWithSuffix = [imageName_2only_2x stringByAppendingString:productSuffix]; NSString *targetFileName = nil; NSString *targetFilePath = nil; if (!force1xScale) { // Default@2x~iphone.png targetFileName = [imageName2xWithSuffix stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 2.0f); // Default_2only_@2x~iphone.png if (resultImage == nil) { targetFileName = [imageName_2only_2xWithSuffix stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 2.0f); } // Default@2x.png if (resultImage == nil) { targetFileName = [imageName2x stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 2.0f); } // Default_2only_@2x.png if (resultImage == nil) { targetFileName = [imageName_2only_2x stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 2.0f); } } if (resultImage == nil) { // Default~iphone.png targetFileName = [imageNameWithSuffix stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 1.0f); // Default.png if (resultImage == nil) { targetFileName = [imageNameWithoutSuffixAndExt stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default@1x~iphone.png if (resultImage == nil) { targetFileName = [imageName1xWithSuffix stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default_1only_~ipnone.png if (resultImage == nil) { targetFileName = [imageName_1only_WithSuffix stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default@1x.png if (resultImage == nil) { targetFileName = [imageName1x stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default_1only.png if (resultImage == nil) { targetFileName = [imageName_1only_ stringByAppendingPathExtension:imageExt]; targetFilePath = [bundlePath stringByAppendingPathComponent:targetFileName]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default~iphone if (resultImage == nil) { targetFilePath = [bundlePath stringByAppendingPathComponent:imageNameWithSuffix]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default if (resultImage == nil) { targetFilePath = [bundlePath stringByAppendingPathComponent:imageNameWithoutSuffixAndExt]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } } if (resultImage == nil) { if (!force1xScale) { // Default@2x.png targetFilePath = [mainBundle pathForResource:imageName2x ofType:imageExt]; resultImage = GetImageAtPath(targetFilePath, 2.0f); // Default_2only_@2x.png if (resultImage == nil) { targetFilePath = [mainBundle pathForResource:imageName_2only_2x ofType:imageExt]; resultImage = GetImageAtPath(targetFilePath, 2.0f); } } // Default.png if (resultImage == nil) { targetFilePath = [mainBundle pathForResource:imageNameWithoutSuffixAndExt ofType:imageExt]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default@1x.png if (resultImage == nil) { targetFilePath = [mainBundle pathForResource:imageName1x ofType:imageExt]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } // Default_1only_.png if (resultImage == nil) { targetFilePath = [mainBundle pathForResource:imageName_1only_ ofType:imageExt]; resultImage = GetImageAtPath(targetFilePath, 1.0f); } } if (resultImage != nil) { [gCacheNameToImageMapsetValue:resultImage forKey:cacheNameOfImage]; [gImageToCacheNameMapsetValue:cacheNameOfImage forKey:resultImage]; [resultImage _setNamed:YES]; [resultImage _setCached:YES]; } return resultImage; } |
[原]逆向iOS SDK -- _UIImageAtPath 的实现(SDK 5.1)的更多相关文章
- [原]逆向iOS SDK -- _UIImageAtPath 的实现(SDK 6.1)
汇编代码: ; 状态:R0 = imageFileName, R1 = mainBundle, R2 = isRetina PUSH {R4-R7,LR} ; R0 = imageFileNam ...
- [原]逆向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 ...
随机推荐
- 基于STM32旋转编码器
..\..\SYSTEM\usart\usart.c(1): error: #5: cannot open source input file "sys.h": No such ...
- ASP.NET MVC2.0 自定义filters
今天大家共同学习下ASP.NET MVC2.0中自定义filters,这一节主要学习下ActionFilterAttribute, ActionFilterAttribute继承IActionFilt ...
- 抓取数据同步备份hive
1:创建表 CREATE external TABLE `tbl_spider`( `url` string, `html` string ) partitioned by ( `site` stri ...
- 【云图】如何制作全国KTV查询系统?
原文:[云图]如何制作全国KTV查询系统? 摘要:本文以[唱吧]531麦霸音乐节为案例,详细解读了如何导入自有数据到高德云图,并进行检索和展示.最后,调起高德mobile地图来进行路线规划和周边查询. ...
- java编程接口(5) ------ button和button组
这篇文章是由自己的学习笔记,欢迎转载,但请注明出处:http://blog.csdn.net/jesson20121020 了解了布局管理器和Swing事件模型,那么剩下的就是Swing 的各个组件了 ...
- Spring IOC之 使用JSR 330标准注解
从Spring 3.0开始,Spring提供了对 JSR 330标准注解的支持.这些注解可以喝Spring注解一样被扫描到.你只需要将相关的Jar包加入到你的classpath中即可. 注意:如果你使 ...
- HTML5学习资源
http://www.silverlightchina.net/html/HTML_5/study/ 我们一起学:HTML5标签系列教程(一)-video标签 版权声明:本文博客原创文章.博客,未经同 ...
- ASP.NET WebForm路由模拟
一.ASP.NET MVC 路由(一)--- ASP.NET WebForm路由模拟 2014-11-08 11:49 by 郝喜路, 232 阅读, 0 评论, 收藏, 编辑 ASP.NET Web ...
- memcpy源代码
7月22号去面试开发的职位,面试官先问我在以前项目中写了什么程序.我就巴拉巴拉的说了一堆写过的code,主要还是测试工具和自动化测试代码.之后让我写memcpy的函数,面试官还挺好的,帮我把函数原型都 ...
- 继承,is,as,多态
继承中的构造方法:1.创建子类对象时,一定会先创建父类对象2.如果调用的子类构造方法没有使用base,就会自动调用父类无参的构造方法, 如果父类没有无参的构造方法就会报错3.如果调用的子类构造方法 ...