Skip to content

Commit 0821ef5

Browse files
committed
显示系统应用
增加显示系统应用的功能
1 parent 3d531ba commit 0821ef5

File tree

7 files changed

+90
-32
lines changed

7 files changed

+90
-32
lines changed

MJAppTools/Models/MJApp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
@property(copy, nonatomic, readonly) NSString *bundleIdentifier;
1818
@property(copy, nonatomic, readonly) NSString *displayName;
1919
@property(copy, nonatomic, readonly) NSString *executableName;
20+
@property(assign, nonatomic, readonly, getter=isSystemApp) BOOL systemApp;
21+
@property(assign, nonatomic, readonly, getter=isHidden) BOOL hidden;
2022
@property (strong, nonatomic, readonly) MJMachO *executable;
2123

2224
- (instancetype)initWithInfo:(FBApplicationInfo *)info;

MJAppTools/Models/MJApp.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ @interface MJApp()
1818
@property(copy, nonatomic) NSString *bundleIdentifier;
1919
@property(copy, nonatomic) NSString *displayName;
2020
@property(copy, nonatomic) NSString *executableName;
21+
@property(assign, nonatomic, getter=isSystemApp) BOOL systemApp;
22+
@property(assign, nonatomic, getter=isHidden) BOOL hidden;
2123
@property (strong, nonatomic) MJMachO *executable;
2224
@end
2325

@@ -31,14 +33,13 @@ + (instancetype)appWithInfo:(FBApplicationInfo *)info
3133
- (instancetype)initWithInfo:(FBApplicationInfo *)info
3234
{
3335
if (self = [super init]) {
34-
NSString *displayName = ((LSApplicationProxy*)info).itemName;
35-
if (!displayName) {
36-
displayName = ((LSApplicationProxy*)info).localizedName;
37-
}
38-
self.displayName = displayName;
36+
LSApplicationProxy *appProxy = (LSApplicationProxy*)info;
37+
self.displayName = appProxy.localizedName ? appProxy.localizedName : appProxy.itemName;
3938
self.bundleIdentifier = info.bundleIdentifier;
4039
self.bundlePath = info.bundleURL.path;
4140
self.dataPath = info.dataContainerURL.path;
41+
self.hidden = [appProxy.appTags containsObject:@"hidden"];
42+
self.systemApp = [info.applicationType isEqualToString:@"System"];
4243
}
4344
return self;
4445
}

MJAppTools/Models/MJMachO.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ - (instancetype)initWithFileHandle:(NSFileHandle *)handle
2727
uint32_t magic = [handle mj_staticReadUint32];
2828
if (magic == FAT_CIGAM || magic == FAT_MAGIC) { // FAT
2929
[self setupFat:handle];
30-
} else {
30+
} else if (magic == MH_MAGIC || magic == MH_CIGAM
31+
|| magic == MH_MAGIC_64 || magic == MH_CIGAM_64) {
3132
[self setupMachO:handle];
33+
} else {
34+
return nil;
3235
}
3336
}
3437
return self;
@@ -63,16 +66,16 @@ - (void)setupMachO:(NSFileHandle *)handle
6366
self.architecture = @"x86";
6467
}
6568
} else if (cputype == CPU_TYPE_ARM64) {
66-
self.architecture = @"arm64";
69+
self.architecture = @"arm_64";
6770
} else if (cputype == CPU_TYPE_ARM) {
6871
if (cpusubtype == CPU_SUBTYPE_ARM_V6) {
69-
self.architecture = @"armv6";
72+
self.architecture = @"arm_v6";
7073
} else if (cpusubtype == CPU_SUBTYPE_ARM_V6) {
71-
self.architecture = @"armv6";
74+
self.architecture = @"arm_v6";
7275
} else if (cpusubtype == CPU_SUBTYPE_ARM_V7) {
73-
self.architecture = @"armv7";
76+
self.architecture = @"arm_v7";
7477
} else if (cpusubtype == CPU_SUBTYPE_ARM_V7S) {
75-
self.architecture = @"armv7s";
78+
self.architecture = @"arm_v7s";
7679
}
7780
}
7881

MJAppTools/Tools/MJAppTools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
typedef enum {
1313
MJListAppsTypeUser,
1414
MJListAppsTypeUserEncrypted,
15-
MJListAppsTypeUserDecrypted
15+
MJListAppsTypeUserDecrypted,
16+
MJListAppsTypeSystem
1617
} MJListAppsType;
1718

1819
@interface MJAppTools : NSObject

MJAppTools/Tools/MJAppTools.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,28 @@ + (void)listUserAppsWithType:(MJListAppsType)type regex:(NSString *)regex operat
3939

4040
for (FBApplicationInfo *appInfo in appInfos) {
4141
if (!appInfo.bundleURL) continue;
42-
if (![appInfo.applicationType isEqualToString:@"User"]) continue;
43-
4442
MJApp *app = [MJApp appWithInfo:appInfo];
43+
// 类型
44+
if (type != MJListAppsTypeSystem && app.isSystemApp) continue;
45+
if (type == MJListAppsTypeSystem && !app.isSystemApp) continue;
46+
47+
// 隐藏
48+
if (app.isHidden) continue;
49+
50+
// 过滤
51+
if ([app.bundleIdentifier containsString:@"com.apple.webapp"]) continue;
52+
53+
// 正则
4554
if (![self match:exp app:app]) continue;
4655

56+
// 可执行文件
4757
[app setupExecutable];
58+
if (!app.executable) continue;
59+
60+
// 加密
4861
if (type == MJListAppsTypeUserDecrypted && app.executable.isEncrypted) continue;
4962
if (type == MJListAppsTypeUserEncrypted && !app.executable.isEncrypted) continue;
63+
5064
[apps addObject:app];
5165
}
5266

MJAppTools/main.m

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
static NSString *MJPrintColorArch;
3030
static NSString *MJPrintColorTip;
3131

32+
void print_usage(void);
3233
void list_machO(MJMachO *machO);
3334
void list_app(MJApp *app, int index);
3435
void list_apps(MJListAppsType type, NSString *regex);
@@ -45,18 +46,7 @@ int main(int argc, const char * argv[]) {
4546
}
4647

4748
if (argc == 1) { // 参数不够
48-
[MJPrintTools printColor:MJPrintColorTip format:@" -l <regex>"];
49-
[MJPrintTools print:@"\t列出用户安装的应用\n"];
50-
51-
[MJPrintTools printColor:MJPrintColorTip format:@" -le <regex>"];
52-
[MJPrintTools print:@"\t列出用户安装的"];
53-
[MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString];
54-
[MJPrintTools print:@"应用\n"];
55-
56-
[MJPrintTools printColor:MJPrintColorTip format:@" -ld <regex>"];
57-
[MJPrintTools print:@"\t列出用户安装的"];
58-
[MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString];
59-
[MJPrintTools print:@"应用\n"];
49+
print_usage();
6050
return 0;
6151
}
6252

@@ -71,9 +61,13 @@ int main(int argc, const char * argv[]) {
7161
list_apps(MJListAppsTypeUserEncrypted, regex);
7262
} else if (strcmp(firstArg, "-ld") == 0) {
7363
list_apps(MJListAppsTypeUserDecrypted, regex);
64+
} else if (strcmp(firstArg, "-ls") == 0) {
65+
list_apps(MJListAppsTypeSystem, regex);
7466
} else {
7567
list_apps(MJListAppsTypeUser, regex);
7668
}
69+
} else {
70+
print_usage();
7771
}
7872
}
7973
return 0;
@@ -91,6 +85,27 @@ void init_colors()
9185
MJPrintColorTip = MJPrintColorCyan;
9286
}
9387

88+
void print_usage()
89+
{
90+
[MJPrintTools printColor:MJPrintColorTip format:@" -l <regex>"];
91+
[MJPrintTools print:@"\t列出用户安装的应用\n"];
92+
93+
[MJPrintTools printColor:MJPrintColorTip format:@" -le <regex>"];
94+
[MJPrintTools print:@"\t列出用户安装的"];
95+
[MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString];
96+
[MJPrintTools print:@"应用\n"];
97+
98+
[MJPrintTools printColor:MJPrintColorTip format:@" -ld <regex>"];
99+
[MJPrintTools print:@"\t列出用户安装的"];
100+
[MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString];
101+
[MJPrintTools print:@"应用\n"];
102+
103+
[MJPrintTools printColor:MJPrintColorTip format:@" -ls <regex>"];
104+
[MJPrintTools print:@"\t列出"];
105+
[MJPrintTools printColor:MJPrintColorCrypt format:@"系统"];
106+
[MJPrintTools print:@"的应用\n"];
107+
}
108+
94109
void list_app(MJApp *app, int index)
95110
{
96111
[MJPrintTools print:@"# "];
@@ -106,9 +121,11 @@ void list_app(MJApp *app, int index)
106121
[MJPrintTools print:@" "];
107122
[MJPrintTools printColor:MJPrintColorPath format:app.bundlePath];
108123

109-
MJPrintNewLine;
110-
[MJPrintTools print:@" "];
111-
[MJPrintTools printColor:MJPrintColorPath format:app.dataPath];
124+
if (app.dataPath.length) {
125+
MJPrintNewLine;
126+
[MJPrintTools print:@" "];
127+
[MJPrintTools printColor:MJPrintColorPath format:app.dataPath];
128+
}
112129

113130
if (app.executable.isFat) {
114131
MJPrintNewLine;
@@ -136,6 +153,8 @@ void list_apps(MJListAppsType type, NSString *regex)
136153
[MJPrintTools printColor:MJPrintColorCrypt format:MJDecryptedString];
137154
} else if (type == MJListAppsTypeUserEncrypted) {
138155
[MJPrintTools printColor:MJPrintColorCrypt format:MJEncryptedString];
156+
} else if (type == MJListAppsTypeSystem) {
157+
[MJPrintTools printColor:MJPrintColorCrypt format:@"系统"];
139158
}
140159
[MJPrintTools print:@"应用"];
141160

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
- 正则搜索
99
- 列出用户安装的所有应用
10-
- 列出用户安装的所有加壳应用
11-
- 列出用户安装的所有未加壳应用
10+
- 列出用户安装的所有**加壳**应用
11+
- 列出用户安装的所有**未加壳**应用
12+
- 列出**系统**的应用
1213
- 应用信息
1314
- 应用名称
1415
- Bundle Identifier
@@ -35,6 +36,8 @@
3536

3637
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180128160439272-1085020939.png)
3738

39+
40+
3841
- 生成命令行工具
3942

4043
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180128160450287-718908728.png)
@@ -59,7 +62,7 @@ chmod +x /usr/bin/MJAppTools
5962

6063
### 5、开始使用MJAppTools
6164

62-
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122122859-304167009.png)
65+
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180131130946984-630357232.png)
6366

6467

6568

@@ -68,12 +71,27 @@ chmod +x /usr/bin/MJAppTools
6871
### 搜索用户安装的所有应用
6972
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122149625-343565107.png)
7073

74+
75+
76+
### 搜索系统的应用
77+
78+
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180131131158718-689866113.png)
79+
80+
81+
7182
### 支持正则搜索
83+
7284
- 搜索名称
7385
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122156265-61789802.png)
7486

87+
88+
89+
7590
- 搜索ID
7691
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122206250-1877490399.png)
7792

93+
94+
95+
7896
- 搜索路径
7997
![](https://images2017.cnblogs.com/blog/497279/201801/497279-20180129122212906-911472208.png)

0 commit comments

Comments
 (0)