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

Hooking multiple functions causes SEGV #4

Open
steve-lorimer opened this issue Jul 26, 2016 · 0 comments
Open

Hooking multiple functions causes SEGV #4

steve-lorimer opened this issue Jul 26, 2016 · 0 comments

Comments

@steve-lorimer
Copy link

I'm trying to hook the posix socket api

elf_hook(handle, base_address, "socket", hook_socket);
elf_hook(handle, base_address, "bind", hook_bind);
elf_hook(handle, base_address, "connect", hook_connect);
elf_hook(handle, base_address, "getpeername", hook_getpeername);
elf_hook(handle, base_address, "getsockname", hook_getsockname);
elf_hook(handle, base_address, "getsockopt", hook_getsockopt);
elf_hook(handle, base_address, "listen", hook_listen);
elf_hook(handle, base_address, "recv", hook_recv);
elf_hook(handle, base_address, "recvfrom", hook_recvfrom);
elf_hook(handle, base_address, "recvmsg", hook_recvmsg);
elf_hook(handle, base_address, "send", hook_send);
elf_hook(handle, base_address, "sendmsg", hook_sendmsg);
elf_hook(handle, base_address, "sendto", hook_sendto);
elf_hook(handle, base_address, "setsockopt", hook_setsockopt);
elf_hook(handle, base_address, "shutdown", hook_shutdown);
elf_hook(handle, base_address, "socketpair", hook_socketpair);

I can hook the first 6 functions

hooked(socket) original_function(0x7f8279c3c936)
hooked(bind) original_function(0xff04f3a7a808)
hooked(connect) original_function(0x4a8e56)
hooked(getpeername) original_function(0x4a8ff0)
hooked(getsockname) original_function(0x4a9126)
hooked(getsockopt) original_function(0x4a92c7)

and then it seg faults

#0  0x00000000004b2b59 in elf_hook \
    (module_filename=0x1498200 "/src/build/elfhook/libtest_api.so", \
     module_address=0x7f8279c3c000, \
     name=0x5671b2 "listen", \
     substitution=0x4a96a5 <hook_listen(int, int)>) at /src/elfhook/elf_hook.c:479
479             *(size_t *)(((size_t)module_address) + rel_plt_table[i].r_offset) = (size_t)substitution;  \
    //and replace it with the substitutional
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

1 participant