From b855b2f14d06e67c7a65316035cbc0785f5ecf7d Mon Sep 17 00:00:00 2001 From: Thatchapon Unprasert Date: Mon, 20 Jun 2016 08:03:10 +0700 Subject: [PATCH] Updated. --- README.md | 2 +- respring_simulator.mm | 2 +- simject.xm | 2 +- simjectCore.h | 4 ++-- simjectCore.mm | 25 ++++++++++++++++++------- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 12e19e4..00dcac5 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,4 @@ simject is BSD-licensed. See `LICENSE` for more information. Do keep in mind that just because your tweak works in the Simulator doesn't necessarily mean it'll work on an actual iOS device. Yes, in 99% of cases, it will work just fine, but there will always be some strange edge cases where this does not apply. -Also, special thanks to PoomSmart, who told me about the existence of `-[UIApplication environmentVariables]`, which is crucial to how simject works. +Also, special thanks to PoomSmart, who told me about the existence of `-[UIApplicationInfo environmentVariables]`, which is crucial to how simject works. \ No newline at end of file diff --git a/respring_simulator.mm b/respring_simulator.mm index d43c0ed..b5d4bcf 100644 --- a/respring_simulator.mm +++ b/respring_simulator.mm @@ -4,7 +4,7 @@ int main(int argc, const char * argv[]) { printf("respring_simulator (C) 2016 Karen Tsai (angelXwind)\n"); printf("Injecting appropriate dynamic libraries from /opt/simject...\n"); NSString *envVars; - system([[NSString stringWithFormat:@"xcrun simctl spawn booted launchctl debug system/com.apple.SpringBoard%@", (envVars = simjectGenerateDylibList(nil)) ? [NSString stringWithFormat:@" --environment DYLD_INSERT_LIBRARIES=%@", envVars] : nil] UTF8String]); + system([[NSString stringWithFormat:@"xcrun simctl spawn booted launchctl debug system/com.apple.SpringBoard%@", (envVars = simjectGenerateDylibList(nil, nil)) ? [NSString stringWithFormat:@" --environment DYLD_INSERT_LIBRARIES=%@", envVars] : nil] UTF8String]); printf("Respringing...\n"); system("xcrun simctl spawn booted launchctl stop com.apple.SpringBoard"); return 0; diff --git a/simject.xm b/simject.xm index a613643..bfdb346 100644 --- a/simject.xm +++ b/simject.xm @@ -4,4 +4,4 @@ -(NSDictionary *) environmentVariables { return simjectEnvironmentVariables(%orig(), self); } -%end +%end \ No newline at end of file diff --git a/simjectCore.h b/simjectCore.h index e921bed..8f7c32c 100644 --- a/simjectCore.h +++ b/simjectCore.h @@ -10,5 +10,5 @@ -(NSString *) bundleIdentifier; @end -NSString *simjectGenerateDylibList(SBApplicationInfo *appInfo); -NSDictionary *simjectEnvironmentVariables(NSDictionary *origVars, SBApplicationInfo *appInfo); +NSString *simjectGenerateDylibList(SBApplicationInfo *appInfo, NSString *originalEnv); +NSDictionary *simjectEnvironmentVariables(NSDictionary *origVars, SBApplicationInfo *appInfo); \ No newline at end of file diff --git a/simjectCore.mm b/simjectCore.mm index cab7da3..bbe3b4b 100644 --- a/simjectCore.mm +++ b/simjectCore.mm @@ -1,6 +1,6 @@ #import "simjectCore.h" -NSString *simjectGenerateDylibList(SBApplicationInfo *appInfo) { +NSString *simjectGenerateDylibList(SBApplicationInfo *appInfo, NSString *originalEnv) { // Store the selected app's CFBundleID in an NSString just for easy access // If appInfo is nil, then set bundleIdentifier to com.apple.springboard // Why? Because that means this function's probably being called by respring_simulator, which is targeting SpringBoard @@ -19,27 +19,38 @@ NSString *simjectGenerateDylibList(SBApplicationInfo *appInfo) { for (NSString *plist in plists) { // We'll want to deal with absolute paths, so append the filename to dylibDir NSString *plistPath = [dylibDir stringByAppendingPathComponent:plist]; - NSDictionary *filter = [NSDictionary dictionaryWithContentsOfFile:plist]; + NSDictionary *filter = [NSDictionary dictionaryWithContentsOfFile:plistPath]; for (NSString *entry in filter[@"Filter"][@"Bundles"]) { + // If supported iOS versions are specified, we check it first + NSArray *supportedVersions = filter[@"CoreFoundationVersion"]; + if (supportedVersions && (supportedVersions.count == 1 || supportedVersions.count == 2)) { + if (supportedVersions.count == 1 && [supportedVersions[0] floatValue] > kCFCoreFoundationVersionNumber) + continue; // doesn't meet lower bound + if ([supportedVersions[0] floatValue] > kCFCoreFoundationVersionNumber || [supportedVersions[1] floatValue] < kCFCoreFoundationVersionNumber) + continue; // outside bounds + } // Now, check if the selected app's bundle ID matches anything in the plist // Also check if any of the bundle IDs in the plist start with com.apple.* if ([entry isEqualToString:bundleIdentifier] || [entry hasPrefix:@"com.apple."]) { // If either of those conditions are met, inject the dylib // Why inject com.apple.*? If a dylib is targeting that, it's likely a framework (com.apple.UIKit, etc.) - // An improvement can be made here by checking if the bundle ID is an installed system app or not... + // An improvement can be made here by checking if the bundle ID is an installed system app or not... (-[SBApplicationInfo isSystemApplication]) // Such a check could be possible by using the MobileInstallationLookup function from the MobileInstallationInstall private framework // I had considered doing that, but for the sake of releasing this in a timely manner, chose not to - [dylibsToInject addObject:[[plist stringByDeletingPathExtension] stringByAppendingString:@".dylib"]]; + [dylibsToInject addObject:[[plistPath stringByDeletingPathExtension] stringByAppendingString:@".dylib"]]; } } } - return [dylibsToInject componentsJoinedByString:@":"]; + NSString *ourDylibs = [dylibsToInject componentsJoinedByString:@":"]; + if (originalEnv && originalEnv.length > 0) + ourDylibs = [NSString stringWithFormat:@"%@:%@", originalEnv, ourDylibs]; + return ourDylibs; } NSDictionary *simjectEnvironmentVariables(NSDictionary *origVars, SBApplicationInfo *appInfo) { // Create a mutable dictionary containing the original environment variables NSMutableDictionary *envVars = (origVars) ? [origVars mutableCopy] : [NSMutableDictionary dictionary]; // Add/replace DYLD_INSERT_LIBRARIES with our own - envVars[@"DYLD_INSERT_LIBRARIES"] = simjectGenerateDylibList(appInfo); + envVars[@"DYLD_INSERT_LIBRARIES"] = simjectGenerateDylibList(appInfo, envVars[@"DYLD_INSERT_LIBRARIES"]); return envVars; -} +} \ No newline at end of file