Skip to content

Full Shadow hook setup guide #163

@doviettung96

Description

@doviettung96

Hi guys, I've used the default setting with Dobby but since that can only work with an emulator (not real device) or just my bad.
This is my native-lib.cpp

#include "BNM/Loading.hpp"
#include "BNM/Class.hpp"
#include "BNMResolve.hpp"
void OnLoaded_Example() {
    BNM_LOG_INFO("OnLoaded_Example Called");
}


JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
    JNIEnv *env;
    vm->GetEnv((void **) &env, JNI_VERSION_1_6);

    BNM::Loading::AllowLateInitHook();
    BNM::Loading::AddOnLoadedEvent(OnLoaded_Example);
    BNM::Loading::TryLoadByJNI(env);
    BNM_LOG_INFO("JNI_OnLoad");
    
    return JNI_VERSION_1_6;
}

I started to try shadowhook by first following https://github.com/bytedance/android-inline-hook/blob/main/doc/manual.md#integration and add shadowhook_init before the BNM::Loading. Also, uncomment the section in GlobalSettings.hpp and add #include <shadowhook.h>

// Shadowhook
template<typename PTR_T, typename NEW_T, typename T_OLD>
inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &oldBytes) {
    if ((void *) ptr != nullptr) return shadowhook_hook_func_addr((void *)ptr, (void *) newMethod, (void **) &oldBytes);
    return nullptr;
}

template<typename PTR_T, typename NEW_T, typename T_OLD>
inline void *BasicHook(PTR_T ptr, NEW_T newMethod, T_OLD &&oldBytes) {
    if ((void *) ptr != nullptr) return shadowhook_hook_func_addr((void *)ptr, (void *) newMethod, (void **) &oldBytes);
    return nullptr;
}

template<typename PTR_T>
inline void Unhook(PTR_T ptr) {
    if ((void *) ptr != nullptr) shadowhook_unhook((void *)ptr);
}

I also remove dobby related stuffs in CMakeLists.txt and replace with shadowhook.
I'm using AndKittyInjector to inject the final lib.so but constantly get

I: inject_lib: Stopped target process threads.
I: inject_lib: Attaching to target process...
I: inject_lib: Attached successfully.
I: injectLibrary: [native=arm64 | lib=arm64].
I: injectLibrary: lib handle = 0x0.
I: injectLibrary: lib Base = 0x0.
E: injectLibrary: failed )':
E: injectLibrary: calling dlerror...
E: injectLibrary: dlopen failed: library "libshadowhook.so" not found
I: inject_lib: Killing target process...
E: Injection failed.

even though I pushed that libshadowhook.so into the device and even add LD_LIBRARY_PATH point to /data/local/tmp..
What did I do wrong? If possible, can you show your full configs to make shadowhook work? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions