diff options
author | Sam Bingner <sam@bingner.com> | 2018-12-24 11:20:51 -1000 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2018-12-24 11:20:51 -1000 |
commit | 340496f25f661f9dc2c46976c2be96fd2d94b406 (patch) | |
tree | 08331d30d36877e4c17942135a54584d6b78a893 /main.m | |
parent | 6409e172da5ff0e98345b21d07bc699c653ef099 (diff) |
Use an NSArray for inject argumentsv0.3
Diffstat (limited to 'main.m')
-rw-r--r-- | main.m | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -0,0 +1,61 @@ +/* + * inject.m + * + * Created by Sam Bingner on 9/27/2018 + * Copyright 2018 Sam Bingner. All Rights Reserved. + * + */ + +#include <CoreFoundation/CoreFoundation.h> +#include <mach/mach.h> +#include <dlfcn.h> +#include "patchfinder64.h" +#include "CSCommon.h" +#include "kern_funcs.h" +#include "inject.h" + + +mach_port_t try_restore_port() { + mach_port_t port = MACH_PORT_NULL; + kern_return_t err; + + err = host_get_special_port(mach_host_self(), 0, 4, &port); + if (err == KERN_SUCCESS && port != MACH_PORT_NULL) { + fprintf(stderr, "got persisted port!\n"); + // make sure rk64 etc use this port + return port; + } + fprintf(stderr, "unable to retrieve persisted port\n"); + return MACH_PORT_NULL; +} + +int main(int argc, char* argv[]) { + if (argc < 2) { + fprintf(stderr,"Usage: inject /full/path/to/executable\n"); + fprintf(stderr,"Inject executables to trust cache\n"); + return -1; + } + mach_port_t tfp0 = try_restore_port(); + if (tfp0 == MACH_PORT_NULL) + return -2; + set_tfp0(tfp0); + uint64_t kernel_base = get_kernel_base(tfp0); + init_kernel(kernel_base, NULL); + uint64_t trust_chain = find_trustcache(); + term_kernel(); + printf("Injecting to trust cache...\n"); + @autoreleasepool { + NSMutableArray *files = [NSMutableArray new]; + for (int i=1; i<argc; i++) { + [files addObject:@( argv[i] )]; + } + int errs = injectTrustCache(files, trust_chain); + if (errs < 0) { + printf("Error %d injecting to trust cache.\n", errs); + } else { + printf("Successfully injected [%d/%d] to trust cache.\n", (int)files.count - errs, (int)files.count); + } + + return errs; + } +} |