How to decode ProGuard's obfuscated code preci

2019-03-03 01:48发布

问题:

I am using ProGuard in my application and problem is when users report some problem to my console and I can't decode it precisely because of "Unknown source".

Here is example of stacktrace:

java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.my.package.j.a(Unknown Source)
at com.a.a.c.c.j(Unknown Source)
at com.a.a.c.c.b(Unknown Source)
at com.a.a.c.e.run(Unknown Source)
at java.lang.Thread.run(Thread.java:856)

Then I am using this code to decode it:

./retrace.sh -verbose mapping.txt stacktrace.txt > out.txt

And here is output:

java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.my.package.MyFragment$10.void output(int,java.lang.String)(Unknown Source)
at com.stericson.RootTools.execution.Shell.void readOutput()(Unknown Source)
at com.stericson.RootTools.execution.Shell.void closeCustomShell()(Unknown Source)
                                           com.stericson.RootTools.execution.Shell startShell(int)
                                           void access$200(com.stericson.RootTools.execution.Shell)
at com.stericson.RootTools.execution.Shell$2.void run()(Unknown Source)
at java.lang.Thread.run(Thread.java:856)

It only shows name of Fragment when error occurred, but I also need exact line and method.

回答1:

Your question has actually two parts.

1) Why are you missing the line information?

You are removing the line information during obfuscation. You need the following rules in your proguard.cfg

-renamesourcefileattribute MyApplication
-keepattributes SourceFile,LineNumberTable

Find details for retracing line numbers here: http://proguard.sourceforge.net/manual/retrace/examples.html#with

2) Why is it missing some method/class name, in your example

com.my.package.MyFragment$10.void

This is because $10 is most likely an anonymous class declaration which will be treated differently during compiling and subsequent obfuscation. First easy solution is of course to get rid of the anonymous declaration and declare it somewhere. Another solution would be to add the following line again to your proguard.cfg

-keepattributes EnclosingMethod

This of course will again not remove some information and will reduce your obfuscation.