|
4 | 4 | #import <dlfcn.h>
|
5 | 5 | #include <curl/curl.h>
|
6 | 6 |
|
| 7 | +@interface LSResourceProxy : NSObject |
| 8 | +@end |
| 9 | + |
| 10 | +@interface LSBundleProxy : LSResourceProxy |
| 11 | + @property (nonatomic, readonly) NSString *localizedShortName; |
| 12 | +@end |
| 13 | + |
| 14 | +@interface LSApplicationProxy : LSBundleProxy |
| 15 | + @property (nonatomic, readonly) NSString *applicationType; |
| 16 | + @property (nonatomic, readonly) NSString *applicationIdentifier; |
| 17 | + @property(readonly) NSURL * dataContainerURL; |
| 18 | + @property(readonly) NSURL * bundleContainerURL; |
| 19 | + @property(readonly) NSString * localizedShortName; |
| 20 | + @property(readonly) NSString * localizedName; |
| 21 | +@end |
| 22 | + |
| 23 | +@interface LSApplicationWorkspace : NSObject |
| 24 | + + (id)defaultWorkspace; |
| 25 | + - (BOOL)installApplication:(NSURL *)path withOptions:(NSDictionary *)options; |
| 26 | + - (BOOL)uninstallApplication:(NSString *)identifier withOptions:(NSDictionary *)options; |
| 27 | + - (id)allApplications; |
| 28 | + - (id)allInstalledApplications; |
| 29 | + - (BOOL)applicationIsInstalled:(id)arg1; |
| 30 | + - (id)applicationsOfType:(unsigned int)arg1; |
| 31 | +@end |
| 32 | + |
7 | 33 |
|
8 | 34 | NSString * getFrontMostApplication() {
|
9 | 35 | mach_port_t p = SBSSpringBoardServerPort();
|
|
16 | 42 | return (frontmostApp);
|
17 | 43 | }
|
18 | 44 |
|
19 |
| -NSString * installedPogoVersion(void) { |
20 |
| - char path[1035]; |
21 |
| - FILE *pogo_cmd = popen("find /var/containers/Bundle/Application/ -type d -name 'PokmonGO.app'", "r"); |
22 |
| - NSString *bundlePath = nil; |
23 |
| - if (pogo_cmd == NULL) { |
24 |
| - NSLog(@"dmon: Unable to find PokemonGo on device"); |
25 |
| - return nil; |
26 |
| - } |
27 |
| - |
28 |
| - // Read the output from the command |
29 |
| - if (fgets(path, sizeof(path)-1, pogo_cmd) != NULL) { |
30 |
| - bundlePath = [NSString stringWithUTF8String:path]; |
31 |
| - bundlePath = [bundlePath stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; |
32 |
| - bundlePath = [bundlePath stringByAppendingPathComponent: @"Info.plist"]; |
33 |
| - } |
34 |
| - |
35 |
| - // Close the file |
36 |
| - pclose(pogo_cmd); |
37 |
| - |
38 |
| - NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:bundlePath]; |
39 |
| - |
40 |
| - if (fileHandle) { |
41 |
| - // Read the contents of the file |
42 |
| - NSData *fileData = [fileHandle readDataToEndOfFile]; |
43 |
| - // Close the file handle |
44 |
| - [fileHandle closeFile]; |
45 |
| - // Convert the file data to a dictionary |
46 |
| - NSDictionary *infoDict = [NSPropertyListSerialization propertyListWithData:fileData options:NSPropertyListImmutable format:NULL error:NULL]; |
47 |
| - if (infoDict) { |
48 |
| - NSString *versionString = [infoDict objectForKey:@"CFBundleShortVersionString"]; |
49 |
| - NSLog(@"dmon: Version of Pokemon Go: %@", versionString); |
50 |
| - return versionString; |
51 |
| - } |
52 |
| - } |
53 |
| - else { |
54 |
| - NSLog(@"dmon: Failed to open file for reading: %@", bundlePath); |
55 |
| - } |
56 |
| - |
57 |
| - return nil; |
58 |
| -} |
59 |
| - |
60 | 45 | NSString *getAptList(NSString *packageName) {
|
61 | 46 | FILE *fp;
|
62 | 47 | char path[1035];
|
@@ -214,11 +199,34 @@ int downloadFile(NSString *url, NSString *userpass, NSString *outfile) {
|
214 | 199 | return -1;
|
215 | 200 | }
|
216 | 201 |
|
| 202 | +NSDictionary *installedAppInfo(NSString * bundleID) { |
| 203 | + LSApplicationWorkspace *workspace = [NSClassFromString(@"LSApplicationWorkspace") defaultWorkspace]; |
| 204 | + for (LSApplicationProxy *proxy in [workspace applicationsOfType:0]) { |
| 205 | + if ([[proxy applicationIdentifier] isEqualToString: bundleID]) { |
| 206 | + NSString *bundlePath = [proxy bundleContainerURL].path; |
| 207 | + |
| 208 | + // This might be a bad assumption. I only checked it with PokemonGO |
| 209 | + NSString *infoFile = [NSString stringWithFormat:@"%@.app/Info.plist", [proxy localizedShortName]]; |
| 210 | + bundlePath = [bundlePath stringByAppendingPathComponent: infoFile]; |
| 211 | + NSDictionary *infoDict = [[NSDictionary alloc] initWithContentsOfFile:bundlePath]; |
| 212 | + NSString *versionString = [infoDict objectForKey:@"CFBundleShortVersionString"]; |
| 213 | + |
| 214 | + NSDictionary *dict = @{@"bundle_name" : [proxy localizedShortName], |
| 215 | + @"bundle_id" : [proxy applicationIdentifier], |
| 216 | + @"bundle_version" : versionString, |
| 217 | + @"bundle_path" : [proxy bundleContainerURL].path}; |
| 218 | + NSLog(@"dmon: Version of %@: %@", bundleID, versionString); |
| 219 | + return dict; |
| 220 | + } |
| 221 | + } |
| 222 | + return nil; |
| 223 | +} |
| 224 | + |
217 | 225 | void update(NSDictionary *config) {
|
218 | 226 | NSString *versionFile = @"version.txt";
|
219 | 227 | NSString *pogo_ipa = @"pogo.ipa";
|
220 | 228 | NSString *gc_deb = @"gc.deb";
|
221 |
| - NSString *pogoVersion = installedPogoVersion(); |
| 229 | + NSString *pogoVersion = installedAppInfo(@"com.nianticlabs.pokemongo")[@"bundle_version"]; |
222 | 230 | NSString *gcVersion = getAptList(@"com.gocheats.jb");
|
223 | 231 | // getAptList(@"com.github.clburlison.dmon");
|
224 | 232 |
|
|
0 commit comments