mirror of
https://github.com/akemin-dayo/simject.git
synced 2025-11-01 08:55:00 +00:00
Updated.
This commit is contained in:
@@ -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.
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -4,4 +4,4 @@
|
||||
-(NSDictionary *) environmentVariables {
|
||||
return simjectEnvironmentVariables(%orig(), self);
|
||||
}
|
||||
%end
|
||||
%end
|
||||
+2
-2
@@ -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);
|
||||
+18
-7
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user