diff options
author | comex | 2015-02-18 02:22:36 -0500 |
---|---|---|
committer | comex | 2015-02-18 02:22:36 -0500 |
commit | 7c26a1964d2d2e54f87d9c42735f6c99b546abd4 (patch) | |
tree | f50838e492aa101a4d87e6ef01d1dc2611f32f97 /lib/darwin/inject.c | |
parent | more fixes (diff) | |
download | substitute-7c26a1964d2d2e54f87d9c42735f6c99b546abd4.tar.gz |
Fix hook-function:
- Thread stoppage is now complemented by sigaction to catch injected
threads (sigaction is not used exclusively because the rest of the
program could be trying to use sigaction itself in the meantime - this
is a real thing, ask Dolphin)
- mprotect is no longer used due to max_protection possibly getting in
the way; instead, a copy is created and mapped onto the original.
Diffstat (limited to 'lib/darwin/inject.c')
-rw-r--r-- | lib/darwin/inject.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/lib/darwin/inject.c b/lib/darwin/inject.c index 6ec07fa..6e0c50e 100644 --- a/lib/darwin/inject.c +++ b/lib/darwin/inject.c @@ -646,10 +646,14 @@ int substitute_dlopen_in_pid(int pid, const char *filename, int options, goto fail; union { - struct _x86_thread_state_32 x32; - struct _x86_thread_state_64 x64; - struct _arm_thread_state_32 a32; - struct _arm_thread_state_64 a64; +#if defined(__x86_64__) || defined(__i386__) + struct __darwin_i386_thread_state x32; + struct __darwin_x86_thread_state64 x64; +#endif +#if defined(__arm__) || defined(__arm64__) + struct __darwin_arm_thread_state a32; + struct __darwin_arm_thread_state64 a64; +#endif } u; size_t state_size; thread_state_flavor_t flavor; @@ -658,34 +662,34 @@ int substitute_dlopen_in_pid(int pid, const char *filename, int options, switch (cputype) { #if defined(__x86_64__) || defined(__i386__) case CPU_TYPE_X86_64: - u.x64.rsp = target_stack_top; - u.x64.rdi = target_stack_top; - u.x64.rip = target_code_page + (inject_start_x86_64 - inject_page_start); + u.x64.__rsp = target_stack_top; + u.x64.__rdi = target_stack_top; + u.x64.__rip = target_code_page + (inject_start_x86_64 - inject_page_start); state_size = sizeof(u.x64); - flavor = _x86_thread_state_64_flavor; + flavor = x86_THREAD_STATE64; break; case CPU_TYPE_I386: - u.x32.esp = target_stack_top; - u.x32.ecx = target_stack_top; - u.x32.eip = target_code_page + (inject_start_i386 - inject_page_start); + u.x32.__esp = target_stack_top; + u.x32.__ecx = target_stack_top; + u.x32.__eip = target_code_page + (inject_start_i386 - inject_page_start); state_size = sizeof(u.x32); - flavor = _x86_thread_state_32_flavor; + flavor = x86_THREAD_STATE32; break; #endif #if defined(__arm__) || defined(__arm64__) case CPU_TYPE_ARM: - u.a32.sp = target_stack_top; - u.a32.r[0] = target_stack_top; - u.a32.pc = target_code_page + (inject_start_arm - inject_page_start); + u.a32.__sp = target_stack_top; + u.a32.__r[0] = target_stack_top; + u.a32.__pc = target_code_page + (inject_start_arm - inject_page_start); state_size = sizeof(u.a32); - flavor = _arm_thread_state_32_flavor; + flavor = ARM_THREAD_STATE; break; case CPU_TYPE_ARM64: - u.a64.sp = target_stack_top; - u.a64.x[0] = target_stack_top; - u.a64.pc = target_code_page + (inject_start_arm64 - inject_page_start); + u.a64.__sp = target_stack_top; + u.a64.__x[0] = target_stack_top; + u.a64.__pc = target_code_page + (inject_start_arm64 - inject_page_start); state_size = sizeof(u.a64); - flavor = _arm_thread_state_64_flavor; + flavor = ARM_THREAD_STATE64; break; #endif default: |