-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappinfo.mm
78 lines (62 loc) · 2.16 KB
/
appinfo.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// creative commons blah blah
// @krit nov 2020
@import Foundation;
#include <objc/runtime.h>
#include <dlfcn.h>
#include <CoreServices/CoreServices.h>
#include <unistd.h>
@interface LSApplicationProxy : NSObject
@property (nonatomic, retain) NSString *itemName;
@property (nonatomic, retain) NSString *applicationIdentifier;
@property (nonatomic, retain) NSString *bundleExecutable;
@property (nonatomic, retain) NSURL *dataContainerURL;
@property (nonatomic, retain) NSString *canonicalExecutablePath;
@end
NSMutableArray *apps;
NSString *idToExecutable(char *bundle);
NSString *idToPath(char *bundle);
NSString *idToContainer(char *bundle);
void pout(NSString *out)
{
printf([out UTF8String]);
}
int main(int argc, char *argv[])
{
dlopen("/System/Library/Frameworks/CoreServices.framework/CoreServices", 0x4);
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
//Class LSApplicationProxy_class = objc_getClass("LSApplicationProxy");
SEL selector = NSSelectorFromString(@"defaultWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];
SEL selectorALL = NSSelectorFromString(@"allInstalledApplications");
apps = [workspace performSelector:selectorALL];
if (strncmp(argv[1], "-e", 2) == 0)
pout(idToExecutable(argv[2]));
if (strncmp(argv[1], "-p", 2) == 0)
pout(idToPath(argv[2]));
if (strncmp(argv[1], "-c", 2) == 0)
pout(idToContainer(argv[2]));
}
NSString *idToExecutable(char *bundle)
{
for (LSApplicationProxy *app in apps)
{
if ([app.applicationIdentifier isEqualToString:[NSString stringWithUTF8String:bundle]])
return app.bundleExecutable;
}
}
NSString *idToPath(char *bundle)
{
for (LSApplicationProxy *app in apps)
{
if ([app.applicationIdentifier isEqualToString:[NSString stringWithUTF8String:bundle]])
return app.canonicalExecutablePath;
}
}
NSString *idToContainer(char *bundle)
{
for (LSApplicationProxy *app in apps)
{
if ([app.applicationIdentifier isEqualToString:[NSString stringWithUTF8String:bundle]])
return app.dataContainerURL.absoluteString;
}
}