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

fishhook would call the new function once when I just hook the old one? #45

Open
yehot opened this issue Aug 9, 2017 · 2 comments
Open

Comments

@yehot
Copy link

yehot commented Aug 9, 2017

#import "fishhook.h"

static void (*orig_NSLog)(NSString *format, ...);

void my_NSLog(NSString *format, ...) {
    va_list args;
    va_start(args, format);
    NSLogv(format, args);
    va_end(args);
    orig_NSLog(@"---do record log things---", nil);
}


int main(int argc, char * argv[]) {
    @autoreleasepool {
        
        struct rebinding reb_logs[1] = {
            {
                "NSLog",
                my_NSLog,
                (void *)&orig_NSLog
            }
        };
        rebind_symbols(reb_logs, 1);

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
// console output:
2017-08-09 19:09:33.015 TestA[35807:551088] ---do record log things---

I use fishhook to hook the NSLog function, just use 'rebind_symbols', no any NSLog calling.
but my_NSLog been called once, and console output the log.
I wonder why fishhook do calling things when hook?
or, iOS system called NSLog ?

@kastiglione
Copy link
Contributor

or, iOS system called NSLog?

I think it's probably this. You can set a breakpoint on my_NSLog and look at the stack trace to see which functions/classes/methods led to it being called.

@yehot
Copy link
Author

yehot commented Aug 10, 2017

Indeed, as you said, I look at the stack trace and found this:
calltree

It's being called by a symbolic breakpoint which added by myself to start a Reveal service:

expr (Class)NSClassFromString(@"IBARevealLoader") == nil ? (void *)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/RevealServer.framework/RevealServer", 0x2) : ((void*)0)

After I disable the breakpoint, it's OK.
Thanks a lot !

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