diff options
author | comex | 2015-01-28 01:16:49 -0500 |
---|---|---|
committer | comex | 2015-01-28 01:16:49 -0500 |
commit | 12efdc925f1ba8ba0616736b5b5351aa82667ff9 (patch) | |
tree | f738857392fd79dacf33f4eac6aa16c09b913427 /ios-bootstrap | |
parent | some more stuff compiles (diff) | |
download | substitute-12efdc925f1ba8ba0616736b5b5351aa82667ff9.tar.gz |
sorta
Diffstat (limited to 'ios-bootstrap')
-rw-r--r-- | ios-bootstrap/posixspawn-hook.c | 27 | ||||
-rw-r--r-- | ios-bootstrap/unrestrict-me.c | 6 |
2 files changed, 28 insertions, 5 deletions
diff --git a/ios-bootstrap/posixspawn-hook.c b/ios-bootstrap/posixspawn-hook.c index 1f1bae1..525b597 100644 --- a/ios-bootstrap/posixspawn-hook.c +++ b/ios-bootstrap/posixspawn-hook.c @@ -6,6 +6,7 @@ #include <sys/wait.h> #include <syslog.h> #include <malloc/malloc.h> +#include <assert.h> extern char ***_NSGetEnviron(void); @@ -66,6 +67,7 @@ static int hook_posix_spawn_generic(__typeof__(posix_spawn) *old, const char *p = orig_dyld_insert; while (*p) { /* W.N.H. */ const char *next = strchr(p, ':') ?: (p + strlen(p)); + printf("p:%s next:%s\n", p, next); /* append if it isn't a copy of ours */ if (!(next - p == sizeof(my_dylib) - 1 && memcmp(next, my_dylib, sizeof(my_dylib) - 1))) { @@ -74,7 +76,9 @@ static int hook_posix_spawn_generic(__typeof__(posix_spawn) *old, memcpy(newp, p, next - p); newp += next - p; } + p = next; } + printf("ok\n"); /* append ours if necessary */ if (!safe_mode) { if (newp != newp_orig) @@ -90,7 +94,7 @@ static int hook_posix_spawn_generic(__typeof__(posix_spawn) *old, envp_to_use = new_envp; char **outp = new_envp; for (size_t idx = 0; idx < env_count; idx++) { - char *env = envp[idx]; + char *env = my_envp[idx]; /* remove *all* D_I_L, including duplicates */ if (!advance(&env, "DYLD_INSERT_LIBRARIES=")) *outp++ = env; @@ -141,10 +145,13 @@ static int hook_posix_spawn_generic(__typeof__(posix_spawn) *old, goto cleanup; /* Since it returned, obviously it was not SETEXEC, so we need to * unrestrict ourself. */ - int sret = substitute_ios_unrestrict(*pid, !was_suspended); + char *error; + int sret = substitute_ios_unrestrict(*pid, !was_suspended, &error); if (sret) { - syslog(LOG_EMERG, "posixspawn-hook: substitute_ios_unrestrict => %d", sret); + syslog(LOG_EMERG, "posixspawn-hook: substitute_ios_unrestrict => %d (%s)", + sret, error); } + free(error); goto cleanup; crap: syslog(LOG_EMERG, "posixspawn-hook: weird error - OOM? skipping our stuff"); @@ -239,3 +246,17 @@ end: if (mach_msg_send(&done_hdr)) /* MOVE deallocates port */ syslog(LOG_EMERG, "posixspawn-hook: mach_msg_send failed"); } + +__attribute__((constructor)) +static void init() { + if (getenv("TEST_POSIXSPAWN_HOOK")) { + mach_port_t port; + assert(!mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_DEAD_NAME, + &port)); + struct shuttle shuttle = { + .type = SUBSTITUTE_SHUTTLE_MACH_PORT, + .u.mach.port = port + }; + substitute_init(&shuttle, 1); + } +} diff --git a/ios-bootstrap/unrestrict-me.c b/ios-bootstrap/unrestrict-me.c index 718e9f8..a297471 100644 --- a/ios-bootstrap/unrestrict-me.c +++ b/ios-bootstrap/unrestrict-me.c @@ -22,9 +22,11 @@ int main(int argc, char **argv) { return 1; } - int sret = substitute_ios_unrestrict((pid_t) pid, should_resume[0] == '1'); + char *err = NULL; + int sret = substitute_ios_unrestrict((pid_t) pid, should_resume[0] == '1', &err); if (sret) { - syslog(LOG_EMERG, "unrestrict-me: substitute_ios_unrestrict => %d", sret); + syslog(LOG_EMERG, "unrestrict-me: substitute_ios_unrestrict => %d (%s)", + sret, err); return 1; } |