PAGalaxyLab / VirtualHook

Android application hooking tool based on VirtualApp
757 stars 128 forks source link

hook 文件方法导致虚拟app无法启动 #16

Closed wjy000 closed 7 years ago

wjy000 commented 7 years ago

例如file类,如果只hook构造函数那没问题,但是一旦hook其他方法,例如file.exists(); 就会导致虚拟app无法启动,而且报错我也看不懂,我测试了很多次,实在是无解了, hook IoBridge类的open方法也是同样问题,请问这是什么原因?

rk700 commented 7 years ago

Android 6.0模拟器未复现问题:

public class Hook_File_exists {
    public static String className = "java.io.File";
    public static String methodName = "exists";
    public static String methodSig = "()Z";
    public static boolean hook(File thiz) {
        Log.w("YAHFA", "file exists: "+thiz.getAbsolutePath());
        return origin(thiz);
    }   

    public static boolean origin(File thiz) {
        Log.w("YAHFA", "should not be here");
        return true;
    }   
}
wjy000 commented 7 years ago

也不是所有软件都打不开,我自己写的一个测试小demo也能正常打开,但是很多软件都无法打开,例如这个软件,一款很有名的硬件信息查看器(http://oj6tsgd72.bkt.clouddn.com/%E6%89%8B%E6%9C%BA%E5%8F%82%E6%95%B0%E6%9F%A5%E7%9C%8B%E5%99%A8aida64_1.4.apk)

rk700 commented 7 years ago

一般的app没有问题,部分app可能有特殊操作,需要针对其具体分析

wjy000 commented 7 years ago

说错了,其实连file 构造方法都会报错,下面是一些抱错信息,麻烦大神你给看看

5-31 16:33:36.649 11196-11196/zpp.wjy.testxvirtual I/MyLog: [HookFile_init]/data/miui/ 05-31 16:33:36.662 11196-11196/zpp.wjy.testxvirtual D/NativeEngine: DexOrJarPath = /system/framework/QPerformance.jar, OutputPath = null. 05-31 16:33:36.662 11196-11196/zpp.wjy.testxvirtual I/MyLog: [HookFile_init]/system/framework/QPerformance.jar 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: JNI GetObjectArrayElement called with pending exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at boolean java.io.File.isAbsolute() (File.java:510) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at java.lang.String java.io.File.getAbsolutePath() (File.java:373) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at java.lang.String java.io.File.getCanonicalPath() (File.java:412) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at void com.lody.virtual.client.NativeEngine.onOpenDexFileNative(java.lang.String[]) (NativeEngine.java:157) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at java.lang.Object dalvik.system.DexFile.openDexFileNative(java.lang.String, java.lang.String, int) (DexFile.java:-2) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at java.lang.Object dalvik.system.DexFile.openDexFile(java.lang.String, java.lang.String, int) (DexFile.java:295) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at void dalvik.system.DexFile.(java.lang.String) (DexFile.java:80) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at void dalvik.system.DexFile.(java.io.File) (DexFile.java:59) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at dalvik.system.DexFile dalvik.system.DexPathList.loadDexFile(java.io.File, java.io.File) (DexPathList.java:279) 05-31 16:33:36.680 11196-11196/zpp.wjy.testxvirtual A/art: art/runtime/java_vm_ext.cc:410] at dalvik.system.DexPathList$Element[] dalvik.system.DexPathList.makePathElements(java.util.List, java.io.File, java.util.List) (DexPathList.java:248)

rk700 commented 7 years ago

没有遇到你的问题,可能与环境和app都有关

wjy000 commented 7 years ago

我发现我真是个大傻逼,停了几天今天拿起项目,突然想到我hook了文件读取的方法,但是只打印了log,并没有调用原函数,导致应用无法读取到文件而崩溃,这么简单我竟然没有想到

回复一下,给后来人一个警示,也给自己一个大嘴巴子

感谢大神这几天的耐心回复