From 062f782c6fc4a20fa4191ec27cc3ade2491f2eb4 Mon Sep 17 00:00:00 2001 From: Thatchapon Unprasert Date: Tue, 4 Jul 2017 17:36:10 +0700 Subject: [PATCH] Cleaned up. --- respring_simulator/Makefile | 4 +-- simject.h | 1 + simject/Makefile | 4 +-- simjectCore.h | 14 --------- simjectCore.mm | 63 ------------------------------------- 5 files changed, 5 insertions(+), 81 deletions(-) create mode 100644 simject.h delete mode 100644 simjectCore.h delete mode 100644 simjectCore.mm diff --git a/respring_simulator/Makefile b/respring_simulator/Makefile index 8465a88..435e0a8 100644 --- a/respring_simulator/Makefile +++ b/respring_simulator/Makefile @@ -6,7 +6,7 @@ GO_EASY_ON_ME = 1 include $(THEOS)/makefiles/common.mk TOOL_NAME = respring_simulator -respring_simulator_FILES = respring_simulator.mm ../simjectCore.mm +respring_simulator_FILES = respring_simulator.mm respring_simulator_CFLAGS = -Wno-deprecated-declarations include $(THEOS_MAKE_PATH)/tool.mk @@ -14,4 +14,4 @@ include $(THEOS_MAKE_PATH)/tool.mk after-all:: @echo Copying binaries... @mkdir -p ../bin - @cp $(THEOS_OBJ_DIR)/respring_simulator ../bin/ \ No newline at end of file + @cp $(THEOS_OBJ_DIR)/respring_simulator ../bin/ diff --git a/simject.h b/simject.h new file mode 100644 index 0000000..e11d633 --- /dev/null +++ b/simject.h @@ -0,0 +1 @@ +#define dylibDir @"/opt/simject" diff --git a/simject/Makefile b/simject/Makefile index de391da..778fb3e 100644 --- a/simject/Makefile +++ b/simject/Makefile @@ -6,11 +6,11 @@ GO_EASY_ON_ME = 1 include $(THEOS)/makefiles/common.mk TWEAK_NAME = simject -simject_FILES = simject.xm ../simjectCore.mm +simject_FILES = simject.xm include $(THEOS_MAKE_PATH)/tweak.mk after-all:: @echo Copying binaries... @mkdir -p ../bin - @cp $(THEOS_OBJ_DIR)/simject.dylib ../bin/ \ No newline at end of file + @cp $(THEOS_OBJ_DIR)/simject.dylib ../bin/ diff --git a/simjectCore.h b/simjectCore.h deleted file mode 100644 index 8f7c32c..0000000 --- a/simjectCore.h +++ /dev/null @@ -1,14 +0,0 @@ -#define dylibDir @"/opt/simject" - -@interface SBApplication : NSObject -@end - -@interface FBApplicationInfo : NSObject -@end - -@interface SBApplicationInfo : FBApplicationInfo --(NSString *) bundleIdentifier; -@end - -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 deleted file mode 100644 index 7173cd6..0000000 --- a/simjectCore.mm +++ /dev/null @@ -1,63 +0,0 @@ -#import "simjectCore.h" - -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 - NSString *bundleIdentifier = (appInfo) ? [appInfo bundleIdentifier] : @"com.apple.springboard"; - // Create an array containing all the filenames in dylibDir (/opt/simject) - NSError *e = nil; - NSArray *dylibDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dylibDir error:&e]; - if (e) { - return nil; - } - // We're only interested in the plist files - NSArray *plists = [dylibDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF endswith %@", @"plist"]]; - // Create an empty mutable array that will contain a list of dylib paths to be injected into the target process - NSMutableArray *dylibsToInject = [NSMutableArray array]; - // Loop through the list of plists - 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: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] doubleValue] > kCFCoreFoundationVersionNumber) { - continue; // doesn't meet lower bound - } - if (supportedVersions.count == 2) { - if ([supportedVersions[0] doubleValue] > kCFCoreFoundationVersionNumber || [supportedVersions[1] doubleValue] < kCFCoreFoundationVersionNumber) { - continue; // outside bounds - } - } - } - // Now, check if the selected app's bundle ID matches anything in the plist - if ([entry isEqualToString:bundleIdentifier] || [entry hasPrefix:@"com.apple.UIKit"] || [entry hasPrefix:@"com.apple.Security"]) { - // If either of those conditions are met, inject the dylib - // Any app being injected here meant to be an UIKit app, so we have com.apple.UIKit bundle check - // com.apple.Security can also be added, because CydiaSubstrate injects into everything with that included - // 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 - - // At this point, simjectUIKit should be loaded without CoreFoudationVersion restriction - [dylibsToInject addObject:[[plistPath stringByDeletingPathExtension] stringByAppendingString:@".dylib"]]; - } - } - } - 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"]); - return envVars; -}