From 0821ef5ce5e9af2cf4e1bfe9d04d5c17c18b3dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=E4=BA=86=E4=B8=AAJ?= <199109106@qq.com> Date: Wed, 31 Jan 2018 13:15:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=B3=BB=E7=BB=9F=E5=BA=94?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加显示系统应用的功能 --- MJAppTools/Models/MJApp.h | 2 ++ MJAppTools/Models/MJApp.m | 11 ++++---- MJAppTools/Models/MJMachO.m | 15 ++++++----- MJAppTools/Tools/MJAppTools.h | 3 ++- MJAppTools/Tools/MJAppTools.m | 18 +++++++++++-- MJAppTools/main.m | 49 ++++++++++++++++++++++++----------- README.md | 24 ++++++++++++++--- 7 files changed, 90 insertions(+), 32 deletions(-) diff --git a/MJAppTools/Models/MJApp.h b/MJAppTools/Models/MJApp.h index 60951e1..df14158 100644 --- a/MJAppTools/Models/MJApp.h +++ b/MJAppTools/Models/MJApp.h @@ -17,6 +17,8 @@ @property(copy, nonatomic, readonly) NSString *bundleIdentifier; @property(copy, nonatomic, readonly) NSString *displayName; @property(copy, nonatomic, readonly) NSString *executableName; +@property(assign, nonatomic, readonly, getter=isSystemApp) BOOL systemApp; +@property(assign, nonatomic, readonly, getter=isHidden) BOOL hidden; @property (strong, nonatomic, readonly) MJMachO *executable; - (instancetype)initWithInfo:(FBApplicationInfo *)info; diff --git a/MJAppTools/Models/MJApp.m b/MJAppTools/Models/MJApp.m index 291b5a4..4118a60 100644 --- a/MJAppTools/Models/MJApp.m +++ b/MJAppTools/Models/MJApp.m @@ -18,6 +18,8 @@ @interface MJApp() @property(copy, nonatomic) NSString *bundleIdentifier; @property(copy, nonatomic) NSString *displayName; @property(copy, nonatomic) NSString *executableName; +@property(assign, nonatomic, getter=isSystemApp) BOOL systemApp; +@property(assign, nonatomic, getter=isHidden) BOOL hidden; @property (strong, nonatomic) MJMachO *executable; @end @@ -31,14 +33,13 @@ + (instancetype)appWithInfo:(FBApplicationInfo *)info - (instancetype)initWithInfo:(FBApplicationInfo *)info { if (self = [super init]) { - NSString *displayName = ((LSApplicationProxy*)info).itemName; - if (!displayName) { - displayName = ((LSApplicationProxy*)info).localizedName; - } - self.displayName = displayName; + LSApplicationProxy *appProxy = (LSApplicationProxy*)info; + self.displayName = appProxy.localizedName ? appProxy.localizedName : appProxy.itemName; self.bundleIdentifier = info.bundleIdentifier; self.bundlePath = info.bundleURL.path; self.dataPath = info.dataContainerURL.path; + self.hidden = [appProxy.appTags containsObject:@"hidden"]; + self.systemApp = [info.applicationType isEqualToString:@"System"]; } return self; } diff --git a/MJAppTools/Models/MJMachO.m b/MJAppTools/Models/MJMachO.m index 772a496..1fa6829 100644 --- a/MJAppTools/Models/MJMachO.m +++ b/MJAppTools/Models/MJMachO.m @@ -27,8 +27,11 @@ - (instancetype)initWithFileHandle:(NSFileHandle *)handle uint32_t magic = [handle mj_staticReadUint32]; if (magic == FAT_CIGAM || magic == FAT_MAGIC) { // FAT [self setupFat:handle]; - } else { + } else if (magic == MH_MAGIC || magic == MH_CIGAM + || magic == MH_MAGIC_64 || magic == MH_CIGAM_64) { [self setupMachO:handle]; + } else { + return nil; } } return self; @@ -63,16 +66,16 @@ - (void)setupMachO:(NSFileHandle *)handle self.architecture = @"x86"; } } else if (cputype == CPU_TYPE_ARM64) { - self.architecture = @"arm64"; + self.architecture = @"arm_64"; } else if (cputype == CPU_TYPE_ARM) { if (cpusubtype == CPU_SUBTYPE_ARM_V6) { - self.architecture = @"armv6"; + self.architecture = @"arm_v6"; } else if (cpusubtype == CPU_SUBTYPE_ARM_V6) { - self.architecture = @"armv6"; + self.architecture = @"arm_v6"; } else if (cpusubtype == CPU_SUBTYPE_ARM_V7) { - self.architecture = @"armv7"; + self.architecture = @"arm_v7"; } else if (cpusubtype == CPU_SUBTYPE_ARM_V7S) { - self.architecture = @"armv7s"; + self.architecture = @"arm_v7s"; } } diff --git a/MJAppTools/Tools/MJAppTools.h b/MJAppTools/Tools/MJAppTools.h index 7ff602a..7e9de3a 100644 --- a/MJAppTools/Tools/MJAppTools.h +++ b/MJAppTools/Tools/MJAppTools.h @@ -12,7 +12,8 @@ typedef enum { MJListAppsTypeUser, MJListAppsTypeUserEncrypted, - MJListAppsTypeUserDecrypted + MJListAppsTypeUserDecrypted, + MJListAppsTypeSystem } MJListAppsType; @interface MJAppTools : NSObject diff --git a/MJAppTools/Tools/MJAppTools.m b/MJAppTools/Tools/MJAppTools.m index fd7743a..1080863 100644 --- a/MJAppTools/Tools/MJAppTools.m +++ b/MJAppTools/Tools/MJAppTools.m @@ -39,14 +39,28 @@ + (void)listUserAppsWithType:(MJListAppsType)type regex:(NSString *)regex operat for (FBApplicationInfo *appInfo in appInfos) { if (!appInfo.bundleURL) continue; - if (![appInfo.applicationType isEqualToString:@"User"]) continue; - MJApp *app = [MJApp appWithInfo:appInfo]; + // 类型 + if (type != MJListAppsTypeSystem && app.isSystemApp) continue; + if (type == MJListAppsTypeSystem && !app.isSystemApp) continue; + + // 隐藏 + if (app.isHidden) continue; + + // 过滤 + if ([app.bundleIdentifier containsString:@"com.apple.webapp"]) continue; + + // 正则 if (![self match:exp app:app]) continue; + // 可执行文件 [app setupExecutable]; + if (!app.executable) continue; + + // 加密 if (type == MJListAppsTypeUserDecrypted && app.executable.isEncrypted) continue; if (type == MJListAppsTypeUserEncrypted && !app.executable.isEncrypted) continue; + [apps addObject:app]; } diff --git a/MJAppTools/main.m b/MJAppTools/main.m index eed9957..6288338 100644 --- a/MJAppTools/main.m +++ b/MJAppTools/main.m @@ -29,6 +29,7 @@ static NSString *MJPrintColorArch; static NSString *MJPrintColorTip; +void print_usage(void); void list_machO(MJMachO *machO); void list_app(MJApp *app, int index); void list_apps(MJListAppsType type, NSString *regex); @@ -45,18 +46,7 @@ int main(int argc, const char * argv[]) { } if (argc == 1) { // 参数不够 - [MJPrintTools printColor:MJPrintColorTip format:@" -l "]; - [MJPrintTools print:@"\t列出用户安装的应用\n"]; - - [MJPrintTools printColor:MJPrintColorTip format:@" -le "]; - [MJPrintTools print:@"\t列出用户安装的"]; - [MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString]; - [MJPrintTools print:@"应用\n"]; - - [MJPrintTools printColor:MJPrintColorTip format:@" -ld "]; - [MJPrintTools print:@"\t列出用户安装的"]; - [MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString]; - [MJPrintTools print:@"应用\n"]; + print_usage(); return 0; } @@ -71,9 +61,13 @@ int main(int argc, const char * argv[]) { list_apps(MJListAppsTypeUserEncrypted, regex); } else if (strcmp(firstArg, "-ld") == 0) { list_apps(MJListAppsTypeUserDecrypted, regex); + } else if (strcmp(firstArg, "-ls") == 0) { + list_apps(MJListAppsTypeSystem, regex); } else { list_apps(MJListAppsTypeUser, regex); } + } else { + print_usage(); } } return 0; @@ -91,6 +85,27 @@ void init_colors() MJPrintColorTip = MJPrintColorCyan; } +void print_usage() +{ + [MJPrintTools printColor:MJPrintColorTip format:@" -l "]; + [MJPrintTools print:@"\t列出用户安装的应用\n"]; + + [MJPrintTools printColor:MJPrintColorTip format:@" -le "]; + [MJPrintTools print:@"\t列出用户安装的"]; + [MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString]; + [MJPrintTools print:@"应用\n"]; + + [MJPrintTools printColor:MJPrintColorTip format:@" -ld "]; + [MJPrintTools print:@"\t列出用户安装的"]; + [MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString]; + [MJPrintTools print:@"应用\n"]; + + [MJPrintTools printColor:MJPrintColorTip format:@" -ls "]; + [MJPrintTools print:@"\t列出"]; + [MJPrintTools printColor:MJPrintColorCrypt format:@"系统"]; + [MJPrintTools print:@"的应用\n"]; +} + void list_app(MJApp *app, int index) { [MJPrintTools print:@"# "]; @@ -106,9 +121,11 @@ void list_app(MJApp *app, int index) [MJPrintTools print:@" "]; [MJPrintTools printColor:MJPrintColorPath format:app.bundlePath]; - MJPrintNewLine; - [MJPrintTools print:@" "]; - [MJPrintTools printColor:MJPrintColorPath format:app.dataPath]; + if (app.dataPath.length) { + MJPrintNewLine; + [MJPrintTools print:@" "]; + [MJPrintTools printColor:MJPrintColorPath format:app.dataPath]; + } if (app.executable.isFat) { MJPrintNewLine; @@ -136,6 +153,8 @@ void list_apps(MJListAppsType type, NSString *regex) [MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString]; } else if (type == MJListAppsTypeUserEncrypted) { [MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString]; + } else if (type == MJListAppsTypeSystem) { + [MJPrintTools printColor:MJPrintColorCrypt format:@"系统"]; } [MJPrintTools print:@"应用"]; diff --git a/README.md b/README.md index ae7096a..1b54f50 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ - 正则搜索 - 列出用户安装的所有应用 - - 列出用户安装的所有加壳应用 - - 列出用户安装的所有未加壳应用 + - 列出用户安装的所有**加壳**应用 + - 列出用户安装的所有**未加壳**应用 + - 列出**系统**的应用 - 应用信息 - 应用名称 - Bundle Identifier @@ -35,6 +36,8 @@ ![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180128160439272-1085020939.png) + + - 生成命令行工具 ![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180128160450287-718908728.png) @@ -59,7 +62,7 @@ chmod +x /usr/bin/MJAppTools ### 5、开始使用MJAppTools -![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122122859-304167009.png) +![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180131130946984-630357232.png) @@ -68,12 +71,27 @@ chmod +x /usr/bin/MJAppTools ### 搜索用户安装的所有应用 ![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122149625-343565107.png) + + +### 搜索系统的应用 + +![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180131131158718-689866113.png) + + + ### 支持正则搜索 + - 搜索名称 ![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122156265-61789802.png) + + + - 搜索ID ![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122206250-1877490399.png) + + + - 搜索路径 ![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122212906-911472208.png)