Closed
Description
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);
}
Metadata
Metadata
Assignees
Labels
No labels