Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook called in iOS simulator but not called on-device #75

Closed
NSExceptional opened this issue Feb 19, 2020 · 2 comments
Closed

Hook called in iOS simulator but not called on-device #75

NSExceptional opened this issue Feb 19, 2020 · 2 comments

Comments

@NSExceptional
Copy link

NSExceptional commented Feb 19, 2020

I'm trying to hook os_log_shim_enabled, a private function in CoreFoundation that changes how NSLog() behaves. Here's my code:

static BOOL FLEXDidHookNSLog = NO;
BOOL (*orig_os_log_shim_enabled)() = nil;
BOOL my_os_log_shim_enabled() {
    return NO;
}

@implementation FLEXSystemLogViewController

+ (void)load {
    FLEXDidHookNSLog = rebind_symbols((struct rebinding[1]) {
        "os_log_shim_enabled",
        (void *)my_os_log_shim_enabled,
        (void **)&orig_os_log_shim_enabled
    }, 1) == 0;
}

...

As the title says, it works in the simulator, but has no effect on-device. I came across this issue, but I don't really understand what might be going wrong. rebind_symbols returns 0 in both cases, and stepping through the code running on-device I can see that fishhook does indeed find the symbol and does replace it here from within __la_symbol_ptr:

static void perform_rebinding_with_section(...) {
    ...
--> indirect_symbol_bindings[i] = cur->rebindings[j].replacement;
    ...
}

When I set a breakpoint for the original function, I can see it's being called instead of my replacement. Here's a screenshot of the debugger:

Screenshot 2020-02-19 at 1 37 20 PM

Is _CFLogvEx3 just not using the lazy binding in this case? Does that mean I'll need to use another hooking library that uses trampolines?

@NSExceptional NSExceptional changed the title Hook works in iOS simulator but not on-device Hook works in iOS simulator but not called on-device Feb 19, 2020
@NSExceptional NSExceptional changed the title Hook works in iOS simulator but not called on-device Hook called in iOS simulator but not called on-device Feb 19, 2020
@saagarjha
Copy link

I think calls to symbols in the shared cache just go through directly, since they're all linked together? Since the simulator doesn't use a shared cache (to my knowledge) it must go through a PLT stub, which fishhook can intercept.

@NSExceptional
Copy link
Author

Ah, that makes sense. Well, now anyone else running into this will hopefully find this issue through Google with this explanation. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants