我尝试修改apk中的dex文件,以便混淆我的代码。
我在eclipse上编译以下代码:
boolean test = false;
SmsManager sm = SmsManager.getDefault();
if (test){ // always false
test = true; // this branch is never taken
} else {
String messageBody = "sms";
sm.sendTextMessage("5556", null, messageBody, null, null);
}
所以只执行“else分支”。另一个分支是死代码。 然后我将我的代码导出到带有eclipse的apk中。
之后,我用apktools打开apk,我拿起dex文件,所以我有以下字节码:
CODE:3EE80 const/4 v2, 0
CODE:3EE82 206F 001C 0087 invoke-super {this, p0}, <void Activity.onCreate(ref) imp. @ _def_Activity_onCreate@VL>
CODE:3EE88 0115 7F03 const/high16 v1, 0x7F030000
CODE:3EE8C 206E 12C9 0017 invoke-virtual {this, v1}, <void MainActivity.setContentView(int) imp. @ _def_MainActivity_setContentView@VI>
CODE:3EE92 0612 const/4 v6, 0
CODE:3EE94 0071 0FD3 0000 invoke-static {}, <ref SmsManager.getDefault() imp. @ _def_SmsManager_getDefault@L>
CODE:3EE9A 000C move-result-object v0
CODE:3EE9C 0638 0003 if-eqz v6, loc_3EEA2
CODE:3EEA0 1612 const/4 v6, 1
CODE:3EEA2
CODE:3EEA2 031A 143A const-string v3, aSmsI # "sms"
CODE:3EEA6 011A 00BE const-string v1, a5556 # "5556"
CODE:3EEAA 2407 move-object v4, v2
CODE:3EEAC 2507 move-object v5, v2
CODE:3EEAE 0674 0FD4 0000 invoke-virtual/range {v0..v5}, <void SmsManager.sendTextMessage(ref, ref, ref, ref, ref) imp. @ _def_SmsManager_sendTextMessage@VLLLLL>
CODE:3EEB4 000E return-void
CODE:3EEB4 Method End
我在0x3eea0的if / else构造中更改死代码以重叠并隐藏“else分支”中的一些代码:
CODE:3EEA0 0218 031A 143A 011A+ const-wide v2:v3, 0xBE011A143A031A
CODE:3EEAA 2407 move-object v4, v2
CODE:3EEAC 2507 move-object v5, v2
CODE:3EEAE 0674 0FD4 0000 invoke-virtual/range {v0..v5}, <void SmsManager.sendTextMessage(ref, ref, ref, ref, ref) imp. @ _def_SmsManager_sendTextMessage@VLLLLL>
CODE:3EEB4 000E return-void
CODE:3EEB4 Method End
然后我更改了校验和和dex文件的哈希值。我用apktools关闭我的apk并用jarsigner签名。
使用adb我在我的模拟设备上安装apk。一切都是成功的。
但是当我尝试启动应用程序时,它崩溃了,我的设备上出现以下错误:“不幸的是,myApps已停止”。
logcat给我这个:
09-06 08:31:13.126: E/AndroidRuntime(874): FATAL EXCEPTION: main
09-06 08:31:13.126: E/AndroidRuntime(874): java.lang.VerifyError: trust/vuln/myApps/MainActivity
09-06 08:31:13.126: E/AndroidRuntime(874): at java.lang.Class.newInstanceImpl(Native Method)
09-06 08:31:13.126: E/AndroidRuntime(874): at java.lang.Class.newInstance(Class.java:1130)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.os.Looper.loop(Looper.java:137)
09-06 08:31:13.126: E/AndroidRuntime(874): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-06 08:31:13.126: E/AndroidRuntime(874): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 08:31:13.126: E/AndroidRuntime(874): at java.lang.reflect.Method.invoke(Method.java:525)
09-06 08:31:13.126: E/AndroidRuntime(874): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-06 08:31:13.126: E/AndroidRuntime(874): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-06 08:31:13.126: E/AndroidRuntime(874): at dalvik.system.NativeStart.main(Native Method)
09-06 08:31:13.226: W/ActivityManager(288): Force finishing activity com.vuln.myApps/.MainActivity
java.lang.VerifyError是因为我的应用程序中的字节码重叠了吗?无论如何要在Android应用程序中实现重叠的字节码?
答案 0 :(得分:1)
Dalvik验证程序不允许您分支到指令的中间。你正在尝试的是特别禁止的。
如果您在logcat输出中查看问题中显示的异常之上几行,您应该会看到一堆“VFY”消息,指出特定的关注点。