How to decode ProGuard's obfuscated code precisely?

泪湿孤枕 提交于 2019-12-02 11:51: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.



来源:https://stackoverflow.com/questions/32182300/how-to-decode-proguards-obfuscated-code-precisely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!