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

hook libc.so 的 clock_gettime 和 gettimeofday 成功,但修改函数返回值失败 #80

Open
fangshunbao opened this issue Sep 11, 2020 · 1 comment

Comments

@fangshunbao
Copy link

你好,我通过 xhook 成功 hook libc.so 了 clock_gettime 和 gettimeofday 函数,如下代码:
xhook_register(".*/libc.so", "gettimeofday", (void )gettimeofday_docker, (void **)&real_gettimeofday);
xhook_register(".
/libc.so", "clock_gettime", (void *)clock_gettime_docker, (void **)&real_clock_gettime);
xhook_refresh(0);

我的问题是:
问题现象:
我想通过 hook 的函数修改原有函数的返回值,这些返回值是通过函数的参数返回回去的,如 gettimeofday 函数的参数 timev 会返回用户需要获取的时间:int gettimeofday_docker(struct timeval *timev, struct timezone *timez),我先用 real_gettimeofday 函数获取系统真正的时间,进行修改后,通过 gettimeofday_docker 的参数 timev 返回给用户,但实际测试效果是修改不生效。

请问,我该如何做才能让返回值生效,感谢回复。

@derust
Copy link

derust commented Sep 14, 2020

第一个参数换成".*\.so$"试试,xhook修改的是其他so的对libc的引用,而不是libc本身

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