注释过的反汇编代码: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. jQuery自定义右键菜单

    首先看下效果,效果在最下面: 代码: body { font-size: 12px; margin: 0px; padding: 0px; } form,div,ul,li { margin: 0px ...

  2. nginx 开展对RT5350

    编译成功nginx的mips该平台后,,至make install生成的文件到一个角落rt5350文件系统. 必须指出的是,在,被放置在文件系统中需要安装文件夹和编译一致:候有release的文件夹, ...

  3. Java8的日期和时间的库20经常使用的演示样本

    除了lambda表达,stream以及从一些小的改进,Java 8还推出了新的日期和时间API,在本教程中,我们将展示通过几个简单的任务来学习如何使用示例Java 8这组API.Java至今.日历和时 ...

  4. exec 重定向

    文件中常用的重定向: command > filename把把标准输出重定向到一个新文件中command >> filename 把把标准输出重定向到一个文件中 (追加)comman ...

  5. hdu1848 Fibonacci again and again(SG游戏功能)

    现在的变化是看不清楚SG功能什么寻求方法 临时模板标题是首当 性能mex1它正在寻求g(x) 然后XOR #include<cstdio> #include<iostream> ...

  6. [SQLXML]FOR XML语法导出XML的易错之处

    原文:[SQLXML]FOR XML语法导出XML的易错之处 [SQLXML]FOR XML语法导出XML的易错之处 Version Date Creator Description 1.0.0.1 ...

  7. SSH深度历险记(两) Jboss+EJB一审

    学习感悟:每次学习新知识.通过初审会从小事做起,获得成就感.经典Hello Workd我们成功的例子奠定了门哈,呢.非常好的理解了.Ejb的核心. 今天主要以这个小实例,来学习EJB的分布式,我们能够 ...

  8. 《java系统性能优化》--2.高速缓存

    上一节.简介了怎样发现性能瓶颈.从这节開始.我会和大家分享我在项目中做的一些性能调优工作.这个系列没有什么顺序可言,认为什么重要.就说说什么. 这节.我们聊缓存. 最開始接触缓存这个词,是学习硬件知识 ...

  9. linux下编译安装mysql5.5以上版本

    安装cmake: tar zxvf cmake-2.8.4.tar.gz cd cmake-2.8.4 ./configure  --prefix=/usr/local/cmake make & ...

  10. Web应用程序整体测试基础——单元测试

    近年来,随着基于B/S结构的大型应用越来越多,Web应用程序测试问题也在逐步完善中.但Web应用程序测试既可以在系统开发中实施,也可以独立于系统单独完成,这取决于Web应用程序的复杂性和多样性.同时程 ...