本文主要是介绍android还原代码混淆proguard日志的工具--retrace和SmartRetrace,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
介绍
代码混淆时android反编译的常用方法,android SDK提供了Proguard工具,路径是
ANDROID_SDK_HOME/tools/proguard
命令行在ANDROID_SDK_HOME/tools/proguard/bin下,而实际的执行代码路径为ANDROID_SDK_HOME/tools/proguard/lib
apk经过混淆后,在闪退时只要有mapping文件,可以通过retrace工具恢复。SDK提供的retrace命令如下:
java -jar retrace.jar [options...] mapping_file [stacktrace_file]
例如下面的崩溃堆栈
08-24 00:39:08.406 31542 31542 I QarthLog: [PatchStore] create disable file for com.lucky.bamboo uid is 10185
--------- beginning of crash
08-24 00:39:08.407 31542 31542 E AndroidRuntime: FATAL EXCEPTION: main
08-24 00:39:08.407 31542 31542 E AndroidRuntime: Process: com.lucky.bamboo, PID: 31542
08-24 00:39:08.407 31542 31542 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lucky.bamboo/com.lucky.bamboo.MainActivity}: java.lang.ArithmeticException: divide by zero
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3895)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4074)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:110)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.os.Looper.loop(Looper.java:219)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8347)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: Caused by: java.lang.ArithmeticException: divide by zero
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.c.a.a(SourceFile:2)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.c.a.<init>(SourceFile:2)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.c.a.a(SourceFile:1)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.MainActivity.onCreate(SourceFile:3)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8085)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8073)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3868)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: ... 11 more
08-24 00:39:08.408 1750 2835 W ActivityManager: Process com.lucky.bamboo has crashed too many times: killing!
08-24 00:39:08.408 1750 2835 W ActivityTaskManager: handleAppCrashLocked Force finishing activity com.lucky.bamboo/.MainActivity
mapping文件为“mapping.txt”
方法一、retrace运行命令
retrace.bat mapping.txt error.txt
运行得到结果:
08-24 00:39:08.406 31542 31542 I QarthLog: [PatchStore] create disable file for com.lucky.bamboo uid is 10185
--------- beginning of crash
08-24 00:39:08.407 31542 31542 E AndroidRuntime: FATAL EXCEPTION: main
08-24 00:39:08.407 31542 31542 E AndroidRuntime: Process: com.lucky.bamboo, PID: 31542
08-24 00:39:08.407 31542 31542 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lucky.bamboo/com.lucky.bamboo.MainActivity}: java.lang.ArithmeticException: divide by zero
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3895)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4074)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:110)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.os.Looper.loop(Looper.java:219)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8347)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: Caused by: java.lang.ArithmeticException: divide by zero
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.db.BambooDatabaseHelper.testMapping(BambooDatabaseHelper.java:26)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.db.BambooDatabaseHelper.<init>(BambooDatabaseHelper.java:21)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.db.BambooDatabaseHelper.obtain(BambooDatabaseHelper.java:16)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at com.lucky.bamboo.MainActivity.onCreate(MainActivity.java:15)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8085)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8073)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3868)
08-24 00:39:08.407 31542 31542 E AndroidRuntime: ... 11 more
08-24 00:39:08.408 1750 2835 W ActivityManager: Process com.lucky.bamboo has crashed too many times: killing!
08-24 00:39:08.408 1750 2835 W ActivityTaskManager: handleAppCrashLocked Force finishing activity com.lucky.bamboo/.MainActivity
方法二:SmartRetrace UI工具
在实际项目中,经常为了查看某段堆栈的原始代码要把日志放在txt文件,然后再用命令行运行,而且还要找到mapping文件,用起来非常繁琐,命令行很长,而且操作步骤很多。
鉴于retrace本身就是jar包,所以本人想到能不能把retrace的命令做成UI模式,这样子很方便操作。经过两天的努力终于完成了一个勉强可用的UI工具——SmartRetrace
如果在SmartRetrace.jar的同级目录下新建一个目录“mappings”,里面可以存放多个mapping文件,并且可以使用下拉框。
工具下载链接:https://download.csdn.net/download/SweetTool/12741147
方法三、android sdk的tools下的proguard工具retraceui,不过感觉不好用,还不如命令行方便。
相对来说,官方的UI工具没那么好用,主要是选择文件的效率比命令行直接输出跟慢。
这篇关于android还原代码混淆proguard日志的工具--retrace和SmartRetrace的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!