当前位置: 首页 > news >正文

iOS - 解压ipa包中的Assert.car文件

项目在 Archive 打包后,生成ipa
在这里插入图片描述
xxx.ipa文件修改为zip后缀即 xxx.zip ,然后再双击解压,会生成一个 Payload 文件夹,里面一个文件 如下图:
在这里插入图片描述

然后显示改文件的包内容:
在这里插入图片描述
在这里插入图片描述

解压 Assets.car 文件的方式:

方法一、 插件 AssetCatalogTinkerer

下载插件 AssetCatalogTinkerer ,用【My Mac】模拟器运行,然后 Assets.car 使用 AssetCatalogTinkerer 打开 ,如下图:
在这里插入图片描述
可以选择到处一张图片,也可选择到处所有图片:
在这里插入图片描述

方式二、插件 cartool

下载插件 cartool ,用【My Mac】模拟器运行,这时候会报错,替换main.m文件内容,如下:

//
//  main.m
//  cartool
//
//  Created by Steven Troughton-Smith on 14/07/2013.
//  Copyright (c) 2013 High Caffeine Content. All rights reserved.
//#import <Foundation/Foundation.h>
#import <ImageIO/ImageIO.h>typedef enum _kCoreThemeIdiom {kCoreThemeIdiomUniversal,kCoreThemeIdiomPhone,kCoreThemeIdiomPad,kCoreThemeIdiomTV,kCoreThemeIdiomCar,kCoreThemeIdiomWatch,kCoreThemeIdiomMarketing
} kCoreThemeIdiom;typedef NS_ENUM(NSInteger, UIUserInterfaceSizeClass) {UIUserInterfaceSizeClassUnspecified = 0,UIUserInterfaceSizeClassCompact     = 1,UIUserInterfaceSizeClassRegular     = 2,
};@interface CUICommonAssetStorage : NSObject-(NSArray *)allAssetKeys;
-(NSArray *)allRenditionNames;-(id)initWithPath:(NSString *)p;-(NSString *)versionString;@end@interface CUINamedImage : NSObject@property(readonly) CGSize size;
@property(readonly) CGFloat scale;
@property(readonly) kCoreThemeIdiom idiom;
@property(readonly) UIUserInterfaceSizeClass sizeClassHorizontal;
@property(readonly) UIUserInterfaceSizeClass sizeClassVertical;-(CGImageRef)image;@end@interface CUIRenditionKey : NSObject
@end@interface CUIThemeFacet : NSObject+(CUIThemeFacet *)themeWithContentsOfURL:(NSURL *)u error:(NSError **)e;@end@interface CUICatalog : NSObject@property(readonly) bool isVectorBased;-(id)initWithURL:(NSURL *)URL error:(NSError **)error;
-(id)initWithName:(NSString *)n fromBundle:(NSBundle *)b;
-(id)allKeys;
-(id)allImageNames;
-(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s;
-(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s deviceIdiom:(int)idiom;
-(NSArray *)imagesWithName:(NSString *)n;@endvoid CGImageWriteToFile(CGImageRef image, NSString *path)
{CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path];CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);CGImageDestinationAddImage(destination, image, nil);if (!CGImageDestinationFinalize(destination)) {NSLog(@"Failed to write image to %@", path);}CFRelease(destination);
}NSString *idiomSuffixForCoreThemeIdiom(kCoreThemeIdiom idiom)
{switch (idiom) {case kCoreThemeIdiomUniversal:return @"";break;case kCoreThemeIdiomPhone:return @"~iphone";break;case kCoreThemeIdiomPad:return @"~ipad";break;case kCoreThemeIdiomTV:return @"~tv";break;case kCoreThemeIdiomCar:return @"~carplay";break;case kCoreThemeIdiomWatch:return @"~watch";break;case kCoreThemeIdiomMarketing:return @"~marketing";break;default:break;}return @"";
}NSString *sizeClassSuffixForSizeClass(UIUserInterfaceSizeClass sizeClass)
{switch (sizeClass){case UIUserInterfaceSizeClassCompact:return @"C";break;case UIUserInterfaceSizeClassRegular:return @"R";break;default:return @"A";}
}NSMutableArray *getImagesArray(CUICatalog *catalog, NSString *key)
{NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:5];for (NSNumber *scaleFactor in @[@1, @2, @3]){CUINamedImage *image = [catalog imageWithName:key scaleFactor:scaleFactor.doubleValue];if (image && image.scale == scaleFactor.floatValue) [images addObject:image];}return images;
}void exportCarFileAtPath(NSString * carPath, NSString *outputDirectoryPath)
{NSError *error = nil;outputDirectoryPath = [outputDirectoryPath stringByExpandingTildeInPath];//	CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error];
//
//	CUICatalog *catalog = [[CUICatalog alloc] init];// 替换成以下代码CUICatalog *catalog = nil;if ([CUICatalog instancesRespondToSelector:@selector(initWithURL:error:)]) {/* If CUICatalog has the URL API (Mojave), use it. */catalog = [[CUICatalog alloc] initWithURL:[NSURL fileURLWithPath:carPath] error:&error];} else {CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error];catalog = [[CUICatalog alloc] init];/* Override CUICatalog to point to a file rather than a bundle */[catalog setValue:facet forKey:@"_storageRef"];}/* Override CUICatalog to point to a file rather than a bundle */
//	[catalog setValue:facet forKey:@"_storageRef"];/* CUICommonAssetStorage won't link */CUICommonAssetStorage *storage = [[NSClassFromString(@"CUICommonAssetStorage") alloc] initWithPath:carPath];for (NSString *key in [storage allRenditionNames]){printf("%s\n", [key UTF8String]);NSArray* pathComponents = [key pathComponents];if (pathComponents.count > 1){// Create subdirectories for namespaced assets (those with names like "some/namespace/image-name")NSArray* subdirectoryComponents = [pathComponents subarrayWithRange:NSMakeRange(0, pathComponents.count - 1)];NSString* subdirectoryPath = [outputDirectoryPath copy];for (NSString* pathComponent in subdirectoryComponents){subdirectoryPath = [subdirectoryPath stringByAppendingPathComponent:pathComponent];}[[NSFileManager defaultManager] createDirectoryAtPath:subdirectoryPathwithIntermediateDirectories:YESattributes:nilerror:&error];}NSMutableArray *images = getImagesArray(catalog, key);for( CUINamedImage *image in images ){if( CGSizeEqualToSize(image.size, CGSizeZero) )printf("\tnil image?\n");else{CGImageRef cgImage = [image image];NSString *idiomSuffix = idiomSuffixForCoreThemeIdiom(image.idiom);NSString *sizeClassSuffix = @"";if (image.sizeClassHorizontal || image.sizeClassVertical){sizeClassSuffix = [NSString stringWithFormat:@"-%@x%@", sizeClassSuffixForSizeClass(image.sizeClassHorizontal), sizeClassSuffixForSizeClass(image.sizeClassVertical)];}NSString *scale = image.scale > 1.0 ? [NSString stringWithFormat:@"@%dx", (int)floor(image.scale)] : @"";NSString *name = [NSString stringWithFormat:@"%@%@%@%@.png", key, idiomSuffix, sizeClassSuffix, scale];printf("\t%s\n", [name UTF8String]);if( outputDirectoryPath )CGImageWriteToFile(cgImage, [outputDirectoryPath stringByAppendingPathComponent:name]);}}}
}int main(int argc, const char * argv[])
{@autoreleasepool {if (argc < 2){printf("Usage: cartool <path to Assets.car> [outputDirectory]\n");return -1;}exportCarFileAtPath([NSString stringWithUTF8String:argv[1]], argc > 2 ? [NSString stringWithUTF8String:argv[2]] : nil);}return 0;
}

然后修改 Edit Scheme ,如下:
在这里插入图片描述

在这里插入图片描述
设置好两个路径:
1.Assert.car文件的路径,我是放在桌面的上的,所以路径为:

/Users/xxx/Desktop/Assets.car

2.解压后的资源存在的路径,这里是一个文件夹路径,我是在桌面创建一个名为img的文件夹,所以路径为:

/Users/xxx/Desktop/img

替换完main.m文件,设置好路径后就可以运行该项目,然后可以看到控制台一直在输出内容,解压完成后,可以查看 img 文件夹里面解压后的资源图片 :
在这里插入图片描述
我们项目中是用的是 pdf 矢量图,所以打包后会自动生成 @1x、@2x、@3x图片,已适配不同分辨率的机型。

http://www.lryc.cn/news/107409.html

相关文章:

  • 【Jmeter】配置不同业务请求比例,应对综合场景压测
  • TCP拥塞控制详解 | 1. 概述
  • 使用IPSEC VPN 在有防火墙的场景和有NAT转换的场景下实现隧道通信实验
  • Go和Java实现适配器模式
  • 接口相似数据结构复用率高?Apipost这招搞定!
  • 【零基础学Rust | 基础系列 | Hello, Rust】编写并运行第一个Rust程序
  • 代理模式.
  • BS框架说明
  • iOS——Block签名
  • Flutter 图片选取及裁剪
  • C语言每日一题:11.《数据结构》链表分割。
  • 记一次Oracle归档日志异常增长问题的排查过程
  • Java设计模式——类之间的关系
  • Dockerfile构建Redis镜像
  • C高级DAY2
  • Linux 服务管理
  • 问题记录 1 页面初始化触发el-form必填校验
  • 后端整理(JVM、Redis、反射)
  • 1. CUDA中的grid和block
  • 宝存科技企业级固态硬盘解决方案助力企业应用性能提升
  • 《练习100》31~35
  • 额外题目第4天|132 673 841 127 684 657
  • HTTP 状态码的分类和含义
  • Linux Bridge(网桥)
  • 【数据结构】优先队列
  • 如何在 Ubuntu 22.04 下编译 StoneDB for MySQL 8.0 | StoneDB 使用教程 #1
  • AMEYA360:尼得科科宝旋转型DIP开关系列汇总
  • 为什么感觉 C/C++ 不火了?
  • 【Linux】在服务器上创建Crontab(定时任务),自动执行shell脚本
  • 内存分析工具之Mat