注释过的反汇编代码: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)的更多相关文章

  1. [原]逆向iOS SDK -- _UIImageAtPath 的实现(SDK 6.1)

    汇编代码: ; 状态:R0 = imageFileName, R1 = mainBundle, R2 = isRetina PUSH    {R4-R7,LR} ; R0 = imageFileNam ...

  2. [原]逆向iOS SDK -- “添加本地通知”的流程分析

    观点: 代码面前没有秘密 添加通知的 Demo 代码 - (void)scheduleOneLocalNotification { [[UIApplication sharedApplication] ...

  3. [原]逆向iOS SDK -- +[UIImage imageNamed:] 的实现

    汇编代码: ; Dump of assembler code for function +[UIImage imageNamed:] ; R0 = UIImage, R1 = "imageN ...

  4. [Office][C#] NPOI、OpenXML SDK、OpenOffice.org SDK 写入资料到 EXCEL 档案[转]

    原文地址:http://www.dotblogs.com.tw/chou/archive/2010/04/29/14912.aspx 一.簡介 要將資料寫入 EXCEL 檔案有許多的方法,但假如電腦不 ...

  5. Android SDK Tools和Android SDK Platform-tools

    SDK Platform 可以理解为版本,因此有 SDK Platform 7,SDK Platform 8等等Android SDK Tools 是各个版本都可通用的工具文件夹,里面有draw9pa ...

  6. 阿里云SDK手册之java SDK

    进行阿里云sdk开发的前提是已经购买阿里云的相关服务才能调用阿里的相关接口进行开发.最近公司在做云管控的项目,于是进行下摘录总结. 一. 环境准备 阿里云针对不同的开发语言提供不同的sdk,由于项目用 ...

  7. 打开SDK Manager检查Android SDK下载和更新失败的解决方法

    [故障描述] 打开SDK Manager检查Android  SDK状况,出现以下情况: Failed to fetch URL https://dl-ssl.google.com/android/r ...

  8. “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 ...

  9. 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 ...

随机推荐

  1. 什么时候rootViewController至tabbarController时刻,控制屏幕旋转法

    于ios6后,ios系统改变了屏幕旋转的方法,假设您想将屏幕旋转法,在需求rootvc里面制备,例如 UIViewController *viewCtrl = [[UIViewController a ...

  2. C++ Primer 学习笔记_54_类和数据抽象 --拷贝构造函数、赋值运算符

    拷贝控制 --复制构造函数.赋值操作符 引言: 当定义一个新类型时,须要显式或隐式地指定复制.赋值和撤销该类型的对象时会发生什么– 复制构造函数.赋值操作符和析构函数的作用!      复制构造函数: ...

  3. crawler_分布式网络爬虫的设计与实现_设计图

    一.集中调度式 二.p2p 三.混合调度式 四.大型集群

  4. 分享一下我的部分毕设内容:基于Windows Phone平台的污染源管理应用

    原文:分享一下我的部分毕设内容:基于Windows Phone平台的污染源管理应用 毕业半年,又总结了一下之前的工作,发现很多知识不复习都忘记了.最近新闻总是报道北京的空气污染,各种雾霾,各种PM X ...

  5. 用fcntl()设置堵塞函数的堵塞性质

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types. ...

  6. kobox : key_waitqueue.c -v1 如何内核线程,如何使用等待队列

    平台:TQ2440 按键驱动 (1)在init中创建一个内核线程作为等待队列的处理函数,该内核线程是一个while(1)死循环,一直检測等待队列的触发条件 DECLARE_WAIT_QUEUE_HEA ...

  7. Java数据结构与算法(1) - ch02有序表(OrderedArray)

    有序表需要掌握的插入方法,删除方法和二分法查找方法. 插入方法: 从前往后找到比要插入的值大的数组项,将该数组项及之后的项均后移一位(从最后一项起依次后移),最后将要插入的值插入当前数组项. 删除方法 ...

  8. PHP_零基础学php_2变量、预定义变量、预定义常量、表达式、运算符、程序控制流程

    1.变量 PHP中使用$后跟变量名表示一个变量,变量名区分大小写. 变量的数据类型 整数类型 浮点类型 字符串类型 布尔类型 数组类型 对象 <html> <head> < ...

  9. Php设计模式(三):行为型模式part1

    原文详见:http://www.ucai.cn/blogdetail/7023?mid=1&f=5 可以在线运行查看效果哦! 在上一篇我们讲了结构型模式,结构型模式是讨论类和对象的结构的.总共 ...

  10. 解决方案命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”(是否缺少程序集引用?)

    首先对System.Web.Mvc这个dll文件重新引用本地的,添加引用,搜索mvc就可以出来,选择相应的版本.如果还不能正常运行, 然后右键打开这个项目引用System.Web.Mvc, 将复制本地 ...