Android: How To Decode ProGuard’s Obfuscated Code From Stack Trace

(This post is for Android developers who use ProGuard in their app and need to do some debugging with the encrypted stack trace. It’s really simple to return the file to a human-readable condition.)

BEFORE
Here’s the stack trace as obfuscated by 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)

AFTER
All you need to do is write one line in the command prompt, and the obfuscation will be removed, as you can see here:

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)

HOW TO DECODE STACK TRACE
You can choose either the command line method or GUI (Graphical User Interface) method.


HOW TO DECODE STACK TRACE VIA GUI
1) Open <android-sdk>/tools/proguard/bin/proguardgui.bat
2) Select the “ReTrace” option on the left column.
3) Add your mapping file and obfuscated stack trace.
4) Click “ReTrace!”

Thanks to David Bilik for mentioning this GUI method.

HOW TO DECODE STACK TRACE VIA COMMAND LINE
1) You will need your ProGuard’s mapping.txt file and the stack trace (Ex: stacktrace.txt) that you want to de-obfuscate.
2) The easiest way to do the next step is copy both these files into your <android_sdk_root>/tools/proguard/bin.
3) If you are on Windows, run the following command in the same directory as the files (make sure you change to your own file names):

retrace.bat -verbose mapping.txt stacktrace.txt > out.txt

4) out.txt will have the stack trace de-obfuscated. Now you can debug much easier and faster than before.

ADVANCED INFO
Technically, you don’t need the -verbose command or  > out.txt. But, I choose to add them in order to make debugging even easier. I give an example with and without the -verbose command above. If you don’t include  > out.txt in the command line, then the results will just appear in the command prompt. This command basically says to “send all output to out.txt”. “out.txt” is just an arbitrary name that I made up.

NOTE
Make sure your ProGuard’s mapping.txt is from the same version of your compiled version. Mapping.txt gets replaced and changes every time you export your APK from Eclipse. A good idea is to copy and store all of your mapping.txt files in a safe location that won’t get rewritten. Also, adding your app’s version number at the end will make your process a lot simpler also, i.e., “mapping_v3p0p8.txt”.

For Linux/Mac users, replace retrace.bat with retrace.sh.

Here’s some more information about ProGuard Decoding.

I hope this was direct enough for those Android developers that use ProGuard.

 - Danial Goodwin -
Co-Founder and Lead Developer of Simply Advanced, LLC

ps – Check out my Simply Advanced Android apps on Google Play: SA Unit Converter and LTE Discovery.

2 Responses to “Android: How To Decode ProGuard’s Obfuscated Code From Stack Trace”

  1. [...] 今天的奇技淫巧是由 Danial 带来的如何还原 ProGuard 混淆后的代码。 ProGuard 在 Android 应用发布的时候经常会用来混淆代码。 混淆后的应用发布到市场上,当用户反馈 Crash 的时候, 开发者看起来就不那么好定位问题根源了。 [...]

  2. […] How To Decode ProGuard’s Obfuscated Code From Stack Trace […]

Leave a Reply

You must be logged in to post a comment.