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

plthook failed to hook function calls of system library on macOS platform #19

Closed
JerryGinger opened this issue Sep 18, 2019 · 2 comments · Fixed by fengjixuchui/plthook#2

Comments

@JerryGinger
Copy link

When i hook read/write of socket function on macOS Platform as follows, it reported "segmentation fault".

ssize_t hook_read(int fildes, void *buf, size_t nbyte) {
    ssize_t rv;
    rv = read(fildes, buf, nbyte);
    printf("Hook read end\n");
    return rv;
}

void install_hook() {
    plthook_t *plthook;
    void *handle;
    // const char *filename = "/usr/lib/libc.dylib";  // this also not work
    const char *filename = "/usr/lib/libSystem.B.dylib";
	if (plthook_open(&plthook, filename) != 0) {
        printf("plthook_open error: %s\n", plthook_error());
        return;
    }
    if (plthook_replace(plthook, "read", (void*)hook_read, NULL) != 0) {
        printf("plthook_replace error: %s\n", plthook_error());
        plthook_close(plthook);
        return;
    }
    plthook_close(plthook);

}
@kubo
Copy link
Owner

kubo commented Sep 18, 2019

Thanks for reporting the issue. I'll fix the segmentation fault later.

I have a question. Do you want to hook read/write called by libSystem.B.dylib?
The _read symbol is undefined in libSystem.B.dylib.

$ nm /usr/lib/libSystem.B.dylib | grep ' _read$'
                 U _read

It is defined in /usr/lib/system/libsystem_kernel.dylib

$ nm /usr/lib/system/libsystem_kernel.dylib | grep ' _read$'
0000000000002ee8 T _read

Otherwise do you want to hook all read/write calls? If the latter, use funchook instead.

@JerryGinger
Copy link
Author

Thanks for your prompt reply. I tried to hook "/usr/lib/libc.dylib" but segmentation fault also happened. funchook tool really works well.

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

Successfully merging a pull request may close this issue.

2 participants