diff --git a/MJAppTools/Models/MJMachO.m b/MJAppTools/Models/MJMachO.m index cf8f373..772a496 100644 --- a/MJAppTools/Models/MJMachO.m +++ b/MJAppTools/Models/MJMachO.m @@ -24,17 +24,9 @@ + (instancetype)machOWithFileHandle:(NSFileHandle *)handle - (instancetype)initWithFileHandle:(NSFileHandle *)handle { if (self = [super init]) { - // 开始的偏移 - unsigned long long beginOffset = handle.offsetInFile; - - // magic - uint32_t magic = [handle mj_readUint32]; - - // 恢复偏移 - [handle seekToFileOffset:beginOffset]; - + uint32_t magic = [handle mj_staticReadUint32]; if (magic == FAT_CIGAM || magic == FAT_MAGIC) { // FAT - [self setupFat:handle bigEndian:magic == FAT_CIGAM]; + [self setupFat:handle]; } else { [self setupMachO:handle]; } @@ -102,13 +94,14 @@ - (void)setupMachO:(NSFileHandle *)handle } } -- (void)setupFat:(NSFileHandle *)handle bigEndian:(BOOL)bigEndian +- (void)setupFat:(NSFileHandle *)handle { self.fat = YES; // fat头 struct fat_header header; [handle mj_readData:&header length:sizeof(struct fat_header)]; + BOOL bigEndian = (header.magic == FAT_CIGAM); // 架构数量 uint32_t archCount = MJEndianConvert(bigEndian, header.nfat_arch); @@ -123,7 +116,8 @@ - (void)setupFat:(NSFileHandle *)handle bigEndian:(BOOL)bigEndian // 偏移到架构具体数据的开始 [handle seekToFileOffset:MJEndianConvert(bigEndian, arch.offset)]; - MJMachO *machO = [[self class] machOWithFileHandle:handle]; + MJMachO *machO = [[[self class] alloc] init]; + [machO setupMachO:handle]; if (machO.isEncrypted) { self.encrypted = YES; } diff --git a/MJAppTools/Tools/MJPrintTools.m b/MJAppTools/Tools/MJPrintTools.m index 617dc32..9494691 100644 --- a/MJAppTools/Tools/MJPrintTools.m +++ b/MJAppTools/Tools/MJPrintTools.m @@ -23,47 +23,58 @@ const NSString *MJPrintColorError = @"\033[1;31m"; const NSString *MJPrintColorStrong = @"\033[1;32m"; +#define MJBeginFormat \ +if (!format) return; \ +va_list args; \ +va_start(args, format); \ +format = [[NSString alloc] initWithFormat:format arguments:args]; + +#define MJEndFormat va_end(args); + @implementation MJPrintTools + (void)printError:(NSString *)format, ... { + MJBeginFormat; + format = [@"Error: " stringByAppendingString:format]; [self printColor:(NSString *)MJPrintColorError format:format]; } + (void)printWarning:(NSString *)format, ... { + MJBeginFormat; + format = [@"Warning: " stringByAppendingString:format]; [self printColor:(NSString *)MJPrintColorWarning format:format]; + MJEndFormat; } + (void)printStrong:(NSString *)format, ... { + MJBeginFormat; [self printColor:(NSString *)MJPrintColorStrong format:format]; + MJEndFormat; } + (void)print:(NSString *)format, ... { + MJBeginFormat; [self printColor:nil format:format]; + MJEndFormat; } + (void)printColor:(NSString *)color format:(NSString *)format, ... { - if (!format) return; + MJBeginFormat; - va_list args; - va_start(args, format); - NSString *formatStr = [[NSString alloc] initWithFormat:format arguments:args]; NSString *printStr = nil; - - if (color) { - printStr = [color stringByAppendingString:formatStr]; + if (color && ![color isEqual:MJPrintColorDefault]) { + printStr = [color stringByAppendingFormat:@"%@%@", format, MJPrintColorDefault]; } else { - printStr = [MJPrintColorDefault stringByAppendingString:formatStr]; + printStr = [MJPrintColorDefault stringByAppendingString:format]; } - - printStr = [printStr stringByAppendingString:(NSString *)MJPrintColorDefault]; - printf("%s", printStr.UTF8String); - va_end(args); + + MJEndFormat; } @end diff --git a/Release/MJAppTools b/Release/MJAppTools deleted file mode 100755 index 70e0d18..0000000 Binary files a/Release/MJAppTools and /dev/null differ