Skip to content

Commit

Permalink
显示系统应用
Browse files Browse the repository at this point in the history
增加显示系统应用的功能
  • Loading branch information
CoderMJLee committed Jan 31, 2018
1 parent 3d531ba commit 0821ef5
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 32 deletions.
2 changes: 2 additions & 0 deletions MJAppTools/Models/MJApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions MJAppTools/Models/MJApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
}
Expand Down
15 changes: 9 additions & 6 deletions MJAppTools/Models/MJMachO.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
}
}

Expand Down
3 changes: 2 additions & 1 deletion MJAppTools/Tools/MJAppTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
typedef enum {
MJListAppsTypeUser,
MJListAppsTypeUserEncrypted,
MJListAppsTypeUserDecrypted
MJListAppsTypeUserDecrypted,
MJListAppsTypeSystem
} MJListAppsType;

@interface MJAppTools : NSObject
Expand Down
18 changes: 16 additions & 2 deletions MJAppTools/Tools/MJAppTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
49 changes: 34 additions & 15 deletions MJAppTools/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -45,18 +46,7 @@ int main(int argc, const char * argv[]) {
}

if (argc == 1) { // 参数不够
[MJPrintTools printColor:MJPrintColorTip format:@" -l <regex>"];
[MJPrintTools print:@"\t列出用户安装的应用\n"];

[MJPrintTools printColor:MJPrintColorTip format:@" -le <regex>"];
[MJPrintTools print:@"\t列出用户安装的"];
[MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString];
[MJPrintTools print:@"应用\n"];

[MJPrintTools printColor:MJPrintColorTip format:@" -ld <regex>"];
[MJPrintTools print:@"\t列出用户安装的"];
[MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString];
[MJPrintTools print:@"应用\n"];
print_usage();
return 0;
}

Expand All @@ -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;
Expand All @@ -91,6 +85,27 @@ void init_colors()
MJPrintColorTip = MJPrintColorCyan;
}

void print_usage()
{
[MJPrintTools printColor:MJPrintColorTip format:@" -l <regex>"];
[MJPrintTools print:@"\t列出用户安装的应用\n"];

[MJPrintTools printColor:MJPrintColorTip format:@" -le <regex>"];
[MJPrintTools print:@"\t列出用户安装的"];
[MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString];
[MJPrintTools print:@"应用\n"];

[MJPrintTools printColor:MJPrintColorTip format:@" -ld <regex>"];
[MJPrintTools print:@"\t列出用户安装的"];
[MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString];
[MJPrintTools print:@"应用\n"];

[MJPrintTools printColor:MJPrintColorTip format:@" -ls <regex>"];
[MJPrintTools print:@"\t列出"];
[MJPrintTools printColor:MJPrintColorCrypt format:@"系统"];
[MJPrintTools print:@"的应用\n"];
}

void list_app(MJApp *app, int index)
{
[MJPrintTools print:@"# "];
Expand All @@ -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;
Expand Down Expand Up @@ -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:@"应用"];

Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

- 正则搜索
- 列出用户安装的所有应用
- 列出用户安装的所有加壳应用
- 列出用户安装的所有未加壳应用
- 列出用户安装的所有**加壳**应用
- 列出用户安装的所有**未加壳**应用
- 列出**系统**的应用
- 应用信息
- 应用名称
- Bundle Identifier
Expand All @@ -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)
Expand All @@ -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)



Expand All @@ -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)

0 comments on commit 0821ef5

Please sign in to comment.