asLody / SandHook

Android ART Hook/Native Inline Hook/Single Instruction Hook - support 4.4 - 11.0 32/64 bit - Xposed API Compat
Other
2.03k stars 443 forks source link

调用原函数时出现NoSuchMethodError #48

Open Mivik opened 4 years ago

Mivik commented 4 years ago
2020-03-30 11:58:21.487 16795-16795/com.mivik.cymoe W/SandHook-Native: JNI Loaded
2020-03-30 11:58:21.506 16795-16795/com.mivik.cymoe E/SandHook-Native: ErrorCodeException: switch to arm32! not impl!
2020-03-30 11:58:21.506 16795-16795/com.mivik.cymoe D/SandHook: method <protected void android.app.Activity.attachBaseContext(android.content.Context)> hook <replacement> success!
2020-03-30 11:56:49.990 16213-16213/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mivik.cymoe, PID: 16213
    java.lang.NoSuchMethodError: No static method attachBaseContext_old(Landroid/content/ContextWrapper;Landroid/content/Context;)V in class Lcom/mivik/cymoe/hook/TestHook; or its super classes (declaration of 'com.mivik.cymoe.hook.TestHook' appears in base.apk)
        at com.mivik.cymoe.hook.TestHook.attachBaseContext_new(Hooks.kt:98)
        at com.mivik.cymoe.CymoeApplication.attachBaseContext(CymoeApplication.kt:13)
        at android.app.Application.attach(Application.java:376)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1157)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1222)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6558)
        at com.elderdrivers.riru.edxp._hooker.yahfa.HandleBindAppHooker.hook(HandleBindAppHooker.java:21)
        at android.app.ActivityThread.access$1400(ActivityThread.java:228)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1893)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7567)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

由于是需要加载目标应用到自己进程中,而目标应用只提供了arm32的native lib,因此不得不使用arm32

值得一提的是,找不到原函数的NoSuchMethodError只在release架构下出现,debug架构时无问题

ganyao114 commented 4 years ago

如果是用注解 api 的话,建议使用以下方式 call 原方法 @HookMethodBackup("onPause") static HookWrapper.HookEntity onPauseBackup;

@HookMethod("onPause")
public static void onPause(@ThisObject Activity thiz) throws Throwable {
    Log.e("ActivityHooker", "hooked onPause success " + thiz);
    onPauseBackup.callOrigin(thiz);
}