如题,介绍下如何在mac下查看二进制文件,以.heic heif文件举例。
1. heif 文件格式判断
+ (SDImageFormat)sd_imageFormatForImageData:(nullable NSData *)data {if (!data) {return SDImageFormatUndefined;}// File signatures table: /library/file_sigs.htmluint8_t c;[data getBytes:&c length:1];switch (c) {case 0xFF:return SDImageFormatJPEG;case 0x89:return SDImageFormatPNG;case 0x47:return SDImageFormatGIF;case 0x49:case 0x4D:return SDImageFormatTIFF;case 0x52: {if (data.length >= 12) {//RIFF....WEBPNSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {return SDImageFormatWebP;}}break;}case 0x00: {if (data.length >= 12) {//....ftypheic ....ftypheix ....ftyphevc ....ftyphevxNSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(4, 8)] encoding:NSASCIIStringEncoding];if ([testString isEqualToString:@"ftypheic"]|| [testString isEqualToString:@"ftypheix"]|| [testString isEqualToString:@"ftyphevc"]|| [testString isEqualToString:@"ftyphevx"]) {return SDImageFormatHEIC;}if ([testString isEqualToString:@"ftypmif1"] || [testString isEqualToString:@"ftypmsf1"]) {return SDImageFormatHEIF;}}break;}}return SDImageFormatUndefined;}
摘自SDWebImage,
/SDWebImage/SDWebImage/blob/3378cc38d44e95cdd474c50fe9e9e14fafa1098b/SDWebImage/NSData%2BImageContentType.m
如代码,heif判断需要读取 *.heic *.heif 文件,判断二进制数据,第0个字节为 0x00,第4~11 个字节为ftypheic
ftypheix、ftyphevc、ftyphevx、ftypmif1、ftypmsf1即为heif。
2. 通过ios 13机器拍一张heif,导出,如保查看是否是heif呢?
Mac下的 Sublime Text的插件包里面有一个HexViewer,可以查看二进制文件。
操作:
(1)打开sublime Text;
(2)Command+Shift+P,选择“Package Control: Install Package”安装插件
(3)安装完会打开一个窗口,在窗口搜索“HexViewer”并等待安装成功;
(4)打开要查看的二进制文件,默认没有以HexViewer模式打开; (5)Command+Shift+P,搜索并选择HexViewer: Toggle Hex View,回车即可
效果如下图
heif的图片文件可以拿一台ios 13机器拍一张,或者直接拿现有的,参见这里的资源/download/minibird1/10273244
如果觉得《Mac 下如保查看二进制文件 比如.heic文件》对你有帮助,请点赞、收藏,并留下你的观点哦!