Git Product home page Git Product logo

Comments (10)

caikelun avatar caikelun commented on July 18, 2024

崩溃的问题,你需要调试一下自己的 old_mmap11 函数了,可以把 old_mmap11 改为直接调用系统
mmap 看看还会崩吗?

你的第二种写法中正则有错误,应改为:

xhook_register("^/system/.*$", "mmap", my_mmap, NULL);

from xhook.

zhangxy123666 avatar zhangxy123666 commented on July 18, 2024

void *(*old_mmap)(void *start, size_t len, int prot, int flags, int fd, off_t offset);
void *(my_mmap)(void *start, size_t len, int prot, int flags, int fd, off_t offset){
LOGD("[mmap] ==============");
return old_mmap(start, len, prot, flags, fd, offset);
};

我是这样写的,然后传入的,大佬帮忙看下哪里不对吗

from xhook.

zhangxy123666 avatar zhangxy123666 commented on July 18, 2024

image

syscall调用,会导致

image

from xhook.

caikelun avatar caikelun commented on July 18, 2024
void *my_mmap(void *start, size_t len, int prot, int flags, int fd, off_t offset)
{
    LOGD("[mmap] =========");
    return mmap(start, len, prot, flags, fd, offset);
};

xhook_register("^/system/.*$", "mmap", my_mmap, NULL);

这样调用会崩溃吗?

from xhook.

zhangxy123666 avatar zhangxy123666 commented on July 18, 2024

这样调用正常了,请教一下,我觉得这样不是会陷入死循环吗,为什么没有呢

from xhook.

caikelun avatar caikelun commented on July 18, 2024

因为你的代码只对符合 ^/system/.*$ 正则的 ELF 做了hook,而 my_mmap 所在的so库不在 /system 目录下,所以没有被hook到。

如果你配置的正则包含了 my_mmap 所在的so库,就会陷入死循环。如果要避免死循环,就需要避免对 mmap 的直接依赖,改成这样:

typedef void (*my_mmap_t)(void *, size_t, int, int, int, off_t);
my_mmap_t old_mmap = NULL;

void *my_mmap(void *start, size_t len, int prot, int flags, int fd, off_t offset)
{
    LOGD("[mmap] =========");
    return old_mmap(start, len, prot, flags, fd, offset);
};

xhook_register("^/.*$", "mmap", my_mmap, (void **)&old_mmap);

from xhook.

zhangxy123666 avatar zhangxy123666 commented on July 18, 2024

我的理解是:

hook了 libc.so中的 mmap函数,然后所有调用mmap的时候都执行钩子函数,
你在上面提到的 my_mmap
image

不是很理解这句话,我要Hook的是mmap,我理解为my_mmap替换了mmap

为什么你提到了是我要hook my_mmap,大佬帮忙解惑下

是不是可以理解为:hook到的只是用正则匹配到的调用mmap的地方

from xhook.

caikelun avatar caikelun commented on July 18, 2024

xhook是通过替换PLT/GOT中的函数地址达到hook效果的,不是inline hook的方式。通俗的说:假设mmap的实现在libc.so中,libbiz.so中有逻辑调用了mmap函数,xhook替换的是“libbiz.so运行时指向libc.so中的mmap函数的指针”,并不是替换libc.so中mmap的实现逻辑。

建议看一下这篇文字:https://github.com/iqiyi/xHook/blob/master/docs/overview/android_plt_hook_overview.zh-CN.md

from xhook.

zhangxy123666 avatar zhangxy123666 commented on July 18, 2024

谢谢啦,这个问题搞懂了,给你点个赞 :)

from xhook.

caikelun avatar caikelun commented on July 18, 2024

不客气的

from xhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.