diff --git a/src/DEBIAN/control b/src/DEBIAN/control index dd23a3f..c04fcb0 100644 --- a/src/DEBIAN/control +++ b/src/DEBIAN/control @@ -8,4 +8,4 @@ Name: dmon Package: com.github.clburlison.dmon Section: Tweaks Tag: purpose::extension, role::enduser -Version: 0.0.8 +Version: 0.0.9 diff --git a/src/DEBIAN/postinst b/src/DEBIAN/postinst index a7a9902..2aa00a3 100755 --- a/src/DEBIAN/postinst +++ b/src/DEBIAN/postinst @@ -1,5 +1,6 @@ #!/usr/bin/bash +/usr/bin/rm /usr/bin/dmon_old 2>/dev/null /usr/bin/launchctl unload /Library/LaunchDaemons/com.github.clburlison.dmon.plist 2>/dev/null /usr/bin/sleep 2 /usr/bin/launchctl load /Library/LaunchDaemons/com.github.clburlison.dmon.plist diff --git a/src/usr/bin/dmon b/src/usr/bin/dmon index f1432ed..827f8da 100755 Binary files a/src/usr/bin/dmon and b/src/usr/bin/dmon differ diff --git a/src/usr/bin/dmon_old b/src/usr/bin/dmon_old deleted file mode 100755 index f383b69..0000000 --- a/src/usr/bin/dmon_old +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/bash - -# Not perfect. It takes iOS ~10 seconds to register -# the application has been sent to the background -# or crashed. Need to test and see if this is consistent. -get_pogo_pid() { - # echo $(ps aux | grep -i "PokmonGO.app" | grep -v grep | tr -s ' ' | cut -d ' ' -f 2) - echo $(ps ax | grep -i "PokmonGO.app" | grep -v grep | cut -d ' ' -f 2) -} - -get_kernbypass_pid() { - echo $(ps ax | grep -i "/usr/bin/kernbypass" | grep -v grep | cut -d ' ' -f 2) -} - -get_substrate_pid() { - echo $(ps ax | grep -i "/etc/rc.d/substitute-launcher" | grep -v grep | cut -d ' ' -f 2) -} - -restart_pogo() { - echo Restarting POGO and SERVICES - # killall pokemongo - # killall kernbypass - # sleep 1 - # killall substrate - # sleep 2 - # /etc/rc.d/substitute-launcher - # sleep 5 - # sbreload - local pogo_pid=$(get_pogo_pid) - kill -9 $pogo_pid 2>/dev/null - local bypass_pid=$(get_kernbypass_pid) - kill -9 $bypass_pid 2>/dev/null - sleep 5 - open com.nianticlabs.pokemongo - echo "done" -} - -main() { - local pid=$(get_pogo_pid) - if [ -z "$pid" ]; then - restart_pogo - fi -} - -main diff --git a/tools/dmon.m b/tools/dmon.m index a75bda3..1046da6 100644 --- a/tools/dmon.m +++ b/tools/dmon.m @@ -42,30 +42,42 @@ - (id)applicationsOfType:(unsigned int)arg1; return (frontmostApp); } -NSString *getAptList(NSString *packageName) { - FILE *fp; - char path[1035]; - NSString *command = [NSString stringWithFormat:@"dpkg-query --showformat='${Version}' --show %@ 2>/dev/null", packageName]; - NSString *version = nil; - - // Open the command for reading - fp = popen([command UTF8String], "r"); - if (fp == NULL) { - NSLog(@"dmon: Failed to run command."); - return nil; - } +NSDictionary *getAptList(NSString *packageName) { + NSDictionary *result = [NSDictionary dictionary]; + NSString *dpkStatusFile = @"/var/lib/dpkg/status"; + NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:dpkStatusFile]; + + if (fileHandle) { + // Read the contents of the file + NSData *fileData = [fileHandle readDataToEndOfFile]; + // Convert the file data to a string + NSString *fileString = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; + // Close the file handle + [fileHandle closeFile]; + // Convert the file data to a dictionary + NSArray *packages = [fileString componentsSeparatedByString:@"\n\n"]; + + for (NSString *packageString in packages) { + NSMutableDictionary *packageDict = [NSMutableDictionary dictionary]; + NSArray *packageLines = [packageString componentsSeparatedByString:@"\n"]; + + for (NSString *line in packageLines) { + NSArray *keyValue = [line componentsSeparatedByString:@": "]; + if (keyValue.count == 2) { + packageDict[keyValue[0]] = keyValue[1]; + } + } - // Read the output from the command - if (fgets(path, sizeof(path)-1, fp) != NULL) { - version = [NSString stringWithUTF8String:path]; - version = [version stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; + if ([packageDict[@"Package"] isEqualToString:packageName]) { + NSLog(@"dmon: Version of %@: %@", packageName, packageDict[@"Version"]); + return packageDict; + } + } } - - // Close the file - pclose(fp); - - NSLog(@"dmon: Version of %@: %@", packageName, version); - return version; + else { + NSLog(@"dmon: Failed to open file for reading: %@", dpkStatusFile); + } + return result; } NSDictionary * parseConfig(void) { @@ -94,7 +106,6 @@ - (id)applicationsOfType:(unsigned int)arg1; NSMutableDictionary * parseKeyValueFileAtPath(NSString *filePath) { NSMutableDictionary *resultDict = [NSMutableDictionary dictionary]; - NSError *error = nil; NSString *fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error]; if (error) { @@ -227,7 +238,7 @@ void update(NSDictionary *config) { NSString *pogo_ipa = @"pogo.ipa"; NSString *gc_deb = @"gc.deb"; NSString *pogoVersion = installedAppInfo(@"com.nianticlabs.pokemongo")[@"bundle_version"]; - NSString *gcVersion = getAptList(@"com.gocheats.jb"); + NSString *gcVersion = getAptList(@"com.gocheats.jb")[@"Version"]; // getAptList(@"com.github.clburlison.dmon"); // Strip trailing forward slashes to make things consistent for users @@ -282,13 +293,6 @@ void monitor(void) { killall(@"pokemongo"); sleep(5); - // Attempt to check versions and update now that Pogo & Kernbypass are not running - NSDictionary *config = parseConfig(); - if (config[@"dmon_url"] != nil && [config[@"dmon_url"] isKindOfClass:[NSString class]] && ![config[@"dmon_url"] isEqualToString:@""]) { - // NSLog(@"dmon: Full config: %@", config); - update(config); - } - // Launch Pogo NSLog(@"dmon: Pogo not running. Launch it..."); void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY); @@ -303,6 +307,27 @@ void monitor(void) { int main(void) { NSLog(@"dmon: Starting..."); + // Start loop + int i = 0; + while (1) { + // Only call at the start of loop + NSDictionary *config = parseConfig(); + if (i == 0 && config[@"dmon_url"] != nil && [config[@"dmon_url"] isKindOfClass:[NSString class]] && ![config[@"dmon_url"] isEqualToString:@""]) { + // NSLog(@"dmon: Full config: %@", config); + update(config); + } + + // Call this function every loop + monitor(); + + // Restart loop on the 30th iteration + if (++i == 30) { + i = 0; + } + + sleep(30); + } + // Start loop while (1) { monitor();