mirror of
https://github.com/akemin-dayo/simject.git
synced 2025-11-01 08:55:00 +00:00
Simplified logic
* simjectGenerateDylibList returns formatted string for insertion. * Search results are filtered before enumeration. * Proper Foundation methods for the uses.
This commit is contained in:
@@ -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) componentsJoinedByString:@":"]) ? [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)) ? [NSString stringWithFormat:@" --environment DYLD_INSERT_LIBRARIES=%@", envVars] : nil] UTF8String]);
|
||||
printf("Respringing...\n");
|
||||
system("xcrun simctl spawn booted launchctl stop com.apple.SpringBoard");
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@
|
||||
-(NSString *) bundleIdentifier;
|
||||
@end
|
||||
|
||||
NSArray *simjectGenerateDylibList(SBApplicationInfo *appInfo);
|
||||
NSString *simjectGenerateDylibList(SBApplicationInfo *appInfo);
|
||||
NSDictionary *simjectEnvironmentVariables(NSDictionary *origVars, SBApplicationInfo *appInfo);
|
||||
|
||||
+25
-21
@@ -1,41 +1,45 @@
|
||||
#import "simjectCore.h"
|
||||
|
||||
NSArray *simjectGenerateDylibList(SBApplicationInfo *appInfo) {
|
||||
NSString *simjectGenerateDylibList(SBApplicationInfo *appInfo) {
|
||||
// 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];
|
||||
// Create an array containing all the filenames in dylibDir (/opt/simject)
|
||||
NSArray *dylibDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dylibDir error:nil];
|
||||
// Loop through the entirety of dylibDir
|
||||
for (NSString *plist in dylibDirContents) {
|
||||
// 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
|
||||
plist = [dylibDir stringByAppendingString:[NSString stringWithFormat:@"/%@", plist]];
|
||||
// Now, we're only interested in the file if it's a plist
|
||||
if ([[plist pathExtension] compare:@"plist" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||
for (NSString *entry in [NSDictionary dictionaryWithContentsOfFile:plist][@"Filter"][@"Bundles"]) {
|
||||
// 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...
|
||||
// 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"]];
|
||||
}
|
||||
NSString *plistPath = [dylibDir stringByAppendingPathComponent:plist];
|
||||
NSDictionary *filter = [NSDictionary dictionaryWithContentsOfFile:plist];
|
||||
for (NSString *entry in filter[@"Filter"][@"Bundles"]) {
|
||||
// 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...
|
||||
// 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"]];
|
||||
}
|
||||
}
|
||||
}
|
||||
return dylibsToInject;
|
||||
return [dylibsToInject componentsJoinedByString:@":"];
|
||||
}
|
||||
|
||||
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) componentsJoinedByString:@":"];
|
||||
envVars[@"DYLD_INSERT_LIBRARIES"] = simjectGenerateDylibList(appInfo);
|
||||
return envVars;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user