代码混淆后日志的解读工具-retrace

Android开发应该都知道代码混淆工具Proguard的使用 来保护app源码在被反编译后不会被轻易地解读 但这样也会导致我们自身收集到的诸如Crash等stacktrace的信息变得难以读懂,好在有补救的措施,这里就介绍一个工具-retrace,用来将混淆后的stacktrace还原成混淆之前的信息.

Android SDK默认带着retrace脚本,一般情况下路径为

./tools/proguard/bin/retrace.bat

Proguard进行混淆之后,会生成一个映射表,文件名为mapping.txt

下面来看:

E/AndroidRuntime(24006): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
E/AndroidRuntime(24006):    at com.example.admin.proguardsample.a.a(Utils.java:10)
E/AndroidRuntime(24006):    at com.example.admin.proguardsample.MainActivity.onCreate(MainActivity.java:22)
E/AndroidRuntime(24006):    at android.app.Activity.performCreate(Activity.java:6106)
E/AndroidRuntime(24006):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
E/AndroidRuntime(24006):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2566)
E/AndroidRuntime(24006):    ... 10 more
对上面的信息处理,去掉 E/AndroidRuntime(24006): 这些字符串retrace才能正常工作.得到 的字符串是

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.example.admin.proguardsample.a.a(Utils.java:10)
at com.example.admin.proguardsample.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:6106)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2566)
... 10 more
将上面的stacktrace保存成一个文本文件,比如名称为 tm_stacktrace.txt

./tools/proguard/bin/retrace.bat/Users/admin/Downloads/ProguardSample/app/build/outputs/mapping/release/mapping.txt/tmp/tm_stacktrace.txt

得到的易读的stacktrace是

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.example.admin.proguardsample.Utils.int getBitmapWidth(android.graphics.Bitmap)(Utils.java:10)
at com.example.admin.proguardsample.MainActivity.void onCreate(android.os.Bundle)(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:6106)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2566)
... 10 more
为了更加容易和高效分析stacktrace,建议 保留SourceFile和LineNumber属性

-keepattributesSourceFile,LineNumberTable




你可能感兴趣的:(Android代码混淆后的解读)