首页 > 解决方案 > 将变量添加到 framework.jar 后,它仍然无法访问

问题描述

我正在尝试通过添加静态布尔变量(仅用于测试)来修改 frameworks.jar。为此,我从模拟器中提取了 frameworks.jar,将其反编译并添加到 LocationManager 中:

.field public static TEST:Z = 0x0

为了测试这个变量,我创建了一个小应用程序,我试图使用这行代码访问这个变量

sget-boolean v1, Landroid/location/LocationManager;->TEST:Z

但这给了我一个例外。我检查了修改的framework.jar 是否通过拉取和反编译来替换原来的。我在我从手机中提取的 framework.jar 中找到了这个变量。如果这个变量存在,为什么它仍然告诉我它不存在

例外

06-30 02:16:53.388 E/AndroidRuntime(10801): FATAL EXCEPTION: main
06-30 02:16:53.388 E/AndroidRuntime(10801): Process: com.greedycat.smalitest, PID: 10801
06-30 02:16:53.388 E/AndroidRuntime(10801): java.lang.IllegalStateException: Could not execute method for android:onClick
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.view.View.performClick(View.java:6302)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.view.View$PerformClick.run(View.java:24782)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.os.Handler.handleCallback(Handler.java:790)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.os.Looper.loop(Looper.java:164)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.app.ActivityThread.main(ActivityThread.java:6518)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at java.lang.reflect.Method.invoke(Native Method)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
06-30 02:16:53.388 E/AndroidRuntime(10801): Caused by: java.lang.reflect.InvocationTargetException
06-30 02:16:53.388 E/AndroidRuntime(10801):     at java.lang.reflect.Method.invoke(Native Method)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
06-30 02:16:53.388 E/AndroidRuntime(10801):     ... 9 more
06-30 02:16:53.388 E/AndroidRuntime(10801): Caused by: java.lang.NoSuchFieldError: No static field TEST of type Z in class Landroid/location/LocationManager; or its superclasses (declaration of 'android.location.LocationManager' appears in /system/framework/framework.jar)
06-30 02:16:53.388 E/AndroidRuntime(10801):     at com.greedycat.smalitest.MainActivity.click(MainActivity.java:20)
06-30 02:16:53.388 E/AndroidRuntime(10801):     ... 11 more
06-30 02:16:53.392 W/ActivityManager( 1237):   Force finishing activity com.greedycat.smalitest/.MainActivity

标签: javaandroidsmali

解决方案


变量名称是 TEST,异常提到 IS_MOCKING 所以你没有正确重新编译应用程序或类似的东西。


推荐阅读