facebook / fishhook

A library that enables dynamically rebinding symbols in Mach-O binaries running on iOS.
BSD 3-Clause "New" or "Revised" License
5.17k stars 965 forks source link

Hook should call the original method before #60

Open fangshufeng opened 5 years ago

fangshufeng commented 5 years ago
static int (*orig_strlen)(const char *__s);
int my_strlen(const char *__s) {
    printf("===\n");
    return orig_strlen(__s);
} 

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        strlen("s"); // 1
        struct rebinding strlen_rebinding = { "strlen", my_strlen,
            (void *)&orig_strlen };

        rebind_symbols((struct rebinding[1]){ strlen_rebinding }, 1);

        char *str = "HelloWorld";

        strlen(str);
}

hello : I think the old method (strlen("s")) should be called before calling the rebind_symbols method to ensure that lazy bind is already the real address, right?

sclcoder commented 3 years ago

I'm agree with you