Cleaned up.

This commit is contained in:
Thatchapon Unprasert
2017-07-04 17:36:10 +07:00
parent 073746c811
commit 062f782c6f
5 changed files with 5 additions and 81 deletions
+2 -2
View File
@@ -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/
@cp $(THEOS_OBJ_DIR)/respring_simulator ../bin/
+1
View File
@@ -0,0 +1 @@
#define dylibDir @"/opt/simject"
+2 -2
View File
@@ -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/
@cp $(THEOS_OBJ_DIR)/simject.dylib ../bin/
-14
View File
@@ -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);
-63
View File
@@ -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;
}