Android:如何从堆栈中还原ProGuard混淆后的代码
本文翻译自Android: How To Decode ProGuard’s Obfuscated Code From Stack Trace
本篇文章是写给那些在他们的应用中使用ProGuard并且需要从堆栈信息中进行调试的Android开发者。这是一种非常简单就将混淆的错误信息转化为可读的方法。
还原前
以下是ProGuard混淆过的堆栈信息:
Caused by: java.lang.NullPointerException
at net.simplyadvanced.ltediscovery.be.u(Unknown Source)
at net.simplyadvanced.ltediscovery.at.v(Unknown Source)
at net.simplyadvanced.ltediscovery.at.d(Unknown Source)
at net.simplyadvanced.ltediscovery.av.onReceive(Unknown Source)
还原后
只要在命令行写一行命令,混淆都将会被移除,如下所示:
Caused by: java.lang.NullPointerException
at net.simplyadvanced.ltediscovery.UtilTelephony.boolean is800MhzNetwork()(Unknown Source)
at net.simplyadvanced.ltediscovery.ServiceDetectLte.void checkAndAlertUserIf800MhzConnected()(Unknown Source)
at net.simplyadvanced.ltediscovery.ServiceDetectLte.void startLocalBroadcastReceiver()(Unknown Source)
at net.simplyadvanced.ltediscovery.ServiceDetectLte$2.void onReceive(android.content.Context,android.content.Intent)(Unknown Source)
如何还原堆栈信息
可以选择命令行或者GUI
GUI
- 1.打开
/tools/proguard/bin/proguardgui.bat
- 2.选择左边栏的
ReTrace
选项 - 3.添加你的mapping文件和混淆过的堆栈信息
- 4.点击
ReTrace!
如下图所示(译者注)
命令行
- 1.需要你的ProGuard的mapping文件和你想要还原的堆栈信息(如stacktrace.txt)
- 2.最简单的方法就是将这些文件拷贝到
/tools/proguard/bin/
目录 - 3.运行以下命令
//Windows
retrace.bat -verbose mapping.txt stacktrace.txt > out.txt
//Mac/Linux
retrace.sh -verbose mapping.txt stacktrace.txt > out.txt