注释过的反汇编代码: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"

)

return nil;

// 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 = [imageFileNamepathExtension];

)

{

imageExt = @"png";

}

NSString *bundlePath = nil;

if (mainBundle != nil)

{

bundlePath = [mainBundle bundlePath];

}

NSString *productSuffix = ProductSuffix();// ~iphone, ~ipad

NSString *imageNameWithoutSuffix = [imageFileNamestringByReplacingOccurrencesOfString:productSuffixwithString:@""];

// Default

NSString *imageNameWithoutSuffixAndExt = [imageNameWithoutSuffixstringByDeletingPathExtension];

// Default~iphone

NSString *imageNameWithSuffix = [imageNameWithoutSuffixAndExtstringByAppendingString:productSuffix];

// Default@1x

NSString *imageName1x = [imageNameWithoutSuffixAndExtstringByAppendingString:@"@1x"];

// Default@1x~iphone

NSString *imageName1xWithSuffix = [imageName1xstringByAppendingString:productSuffix];

// Default_1only_

NSString *imageName_1only_ = [imageNameWithoutSuffixAndExtstringByAppendingString:@"_1only_"];

// Default_1only_~ipnone

NSString *imageName_1only_WithSuffix = [imageName_1only_stringByAppendingString:productSuffix];

// Default@2x

NSString *imageName2x = [imageNameWithoutSuffixAndExtstringByAppendingString:@"@2x"];

// Default@2x~iphone

NSString *imageName2xWithSuffix = [imageName2xstringByAppendingString:productSuffix];

// Default_2only_@2x

NSString *imageName_2only_2x = [imageNameWithoutSuffixAndExtstringByAppendingString:@"_2only_@2x"];

// Default_2only_@2x~iphone

NSString *imageName_2only_2xWithSuffix = [imageName_2only_2xstringByAppendingString: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)

{

[gCacheNameToImageMap setValue:resultImage forKey:cacheNameOfImage];

[gImageToCacheNameMap setValue:cacheNameOfImage forKey:resultImage];

[resultImage _setNamed:YES];

[resultImage _setCached:YES];

}

return resultImage;

}

逆向iOS SDK -- _UIImageAtPath 的实现(SDK 5.1)的更多相关文章

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

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

  2. Android SDK Tools和Android SDK Platform-tools

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

  3. 阿里云SDK手册之java SDK

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

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

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

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

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

  7. linux===启动sdk manager下载配置sdk的时候报错的解决办法

    当启动sdk manager下载配置sdk的时候,报错如下: botoo@botoo-virtual-machine:/opt/android-sdk-linux/tools$ sudo  ./and ...

  8. windows中android SDK manager安装更新sdk很慢,或者出现Done loading packages后不动甚至没有任何可用包

    出现问题: 1.windows中android SDK manager安装更新sdk很慢,或者出现Done loading packages后不动甚至没有任何可用包 2.Failed to fetch ...

  9. 修改android studio中的avd sdk路径、avd sdk找不到的解决方案

    要进行Android应用程序的开发,首先就要搭建好Android的开发环境,所需要的工具有如下4个:1.java JDK:2.Android SDK:3.Eclipse:4.ADT 1.java JD ...

  10. 轻量易用的微信Sdk发布——Magicodes.Wx.Sdk

    概述 最简洁最易于使用的微信Sdk,包括公众号Sdk.小程序Sdk.企业微信Sdk等,以及Abp VNext集成. GitHub地址:https://github.com/xin-lai/Magico ...

随机推荐

  1. 【转】google chrome如何设置主页

    原文网址:http://jingyan.baidu.com/article/8275fc86bf916c46a13cf666.html google chrome是一款拥有众多优秀插件的浏览器,是我们 ...

  2. 【转】Java 集合系列03之 ArrayList详细介绍(源码解析)和使用示例

    原文网址:http://www.cnblogs.com/skywang12345/p/3308556.html 上一章,我们学习了Collection的架构.这一章开始,我们对Collection的具 ...

  3. 动态规划:NOI2013 快餐店

    Description 小 T打算在城市C开设一家外送快餐店.送餐到某一个地点的时间与外卖店到该地点之间最短路径长度是成正比的,小T希望快餐店的地址选在离最远的顾客距离最近 的地方. 快餐店的顾客分布 ...

  4. 数学(莫比乌斯函数):BZOJ 2440 完全平方数

    Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些 数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而 这丝毫不影响他对其他数的热爱. 这 ...

  5. 数据结构(树链剖分,线段树):SDOI 2016 游戏

    4515: [Sdoi2016]游戏 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 351  Solved: 157[Submit][Status][ ...

  6. 使用DateAdd方法向指定日期添加一段时间间隔,使用TimeSpan对象获取时间间隔

    一:使用DateAdd方法向指定日期添加一段时间间隔,截图 二:代码 using System; using System.Collections.Generic; using System.Comp ...

  7. delphi笔记之nativeXml 转

    delphi笔记之nativeXml   使用 CreateName 建立可直接指定根节点的名称 var XmlDoc: TnativeXml; Node:TxmlNode; Begin XmlDoc ...

  8. evernote出现"Invalid username and/or password"的情况

    evernote出现"Invalid username and/or password"的情况 evernote挺好用的,可是这几年用下来也遇到过狗血情况,几乎每次都是更新后出状况 ...

  9. CF 295E Yaroslav and Points(Splay)

    题目大意: 两个操作 1 id op  把id的位置+op 2 id op  查询在[id.op]之间的全部的数的差 思路: 关键是pushup函数. 自己退一下会发现.跟区间的总和,区间的节点个数有 ...

  10. [Javascript] Writing conventional commits with commitizen

    Because semantic-release requires a specific message format, it's easier to follow this convention u ...