注释过的反汇编代码: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 ...
随机推荐
-
LeetCode Online Judge 1. Two Sum
刷个题,击败0.17%... Given an array of integers, return indices of the two numbers such that they add up t ...
-
PostgreSQL 杂志
pgmag 团队刚发布了头两期 PostgreSQL 杂志,还有中文版http://pgmag.org/download,推荐广大 PostgreSQL 数据库管理员及开发者阅读: Issue #01 ...
-
WPF 自定义雷达图
自定义雷达图表如下: Git下载地址:https://github.com/Kybs0/RadarChartControl 1.创建UserControl,名为“RadarChartControl” ...
-
linux read简单用法
#!/bin/bash #read chars into var read -n var echo $var #read chars without showing it read -s var ec ...
-
二模 (7) day1
第一题: 题目大意: 给出数轴上N棵树的坐标和高度,如果两棵树之间的距离小于其中一颗树的高度,那么就有树会被挡住.因此要把一些树砍矮一点.求砍树的总高度最小值. N<=100000; 解题过程: ...
-
[topcoder]LongLongTripDiv2
http://community.topcoder.com/stat?c=problem_statement&pm=13091 解方程,对中国孩子太简单了. #include <vect ...
-
javascript每日一练(二)——javascript(函数,数组)
一.函数 什么是函数 function show(){}//不带参数 function show(){return 123;}//不带参数,有返回值 function show(arg1, arg2, ...
-
centos中apache-tomcat的配置
在centos中配置Apache-toncat需要先安装jdk,前面文章已经写了怎么配置jdk,这里略过. 首先到官网下载好Apache-tomcat安装包,我这里下载的是apache-tomcat- ...
-
Byte数组和Int的互相转换
public static int bytesToInt(byte[] bytes) { int addr = bytes[0] & 0xFF; addr |= ((bytes[1] < ...
-
SpringBoot乱码
第一步: 第一步,约定好传参编码格式 不管是运用httpclient,还是原生http,都要设置传参的编码,为了统一,这儿全部设置为utf-8 第二步,修正application.properties ...