Aliucord / hook

Java Xposed Api for LSPlant
Open Software License 3.0
123 stars 28 forks source link

problem with hook function #3

Closed wolfnightblack closed 1 year ago

wolfnightblack commented 1 year ago

Hello ! thank for your lib. Can you guide how to hook function: __system_property_get

rushiiMachine commented 1 year ago

Are you referring to native method hooking?

wolfnightblack commented 1 year ago

Are you referring to native method hooking?

Yes ! i want use Alicord to return system_prop form native

wolfnightblack commented 1 year ago

hook like this: https://github.com/rk700/ChangePhoneInfo/blob/master/app/src/main/jni/hookprop.c

rushiiMachine commented 1 year ago

This library is for hooking Java code, not native functions. For that you'd need something like Dobby

Vendicated commented 1 year ago

Hi! This library actually performs native hooking using the aforementioned dobby library, but the api is not exposed because it's not really its purpose

However, you could just copy that code into your own project:

https://github.com/Aliucord/hook/blob/7849e04e5820248c755c3e9d90c234df5f9dabc0/core/src/main/cpp/aliuhook.cpp#L30-L63

and then usage is pretty straight forward:

void* backup = nullptr;

int replace_func(const char *name, char *value) {
    printf("get prop called with name %s", name);
    auto original = reinterpret_cast<int (*)(const char *, char *)>(backup);
    return original(name, value);
}

void perform_hook() {
    backup = InlineHooker(reinterpret_cast<void *>(__system_property_get), reinterpret_cast<void *>(replace_func));
    if (!backup) {} // hook failed
}

Hope this helps!