1

I'm trying to use ProGuard to obfuscate a Java application. I'm experiencing a problem where all of my text and images disappear from the GUI (Swing) forms. I've tried disabling optimizations and including more libraries, but nothing seems to be working.

I've inspected the output generated by the obfuscator with a decompiler, and my resource paths seem to still be correct.

  1. Do I need to be including more core Java libraries outside of jre/lib/rt.jar?
  2. Are there more settings I should disable?
  3. ...other suggestions?

Thanks.

jocull
  • 20,008
  • 22
  • 105
  • 149

2 Answers2

3

Most likely your resources are either (a) being accessed via a path which ProGuard is changing when the package containing the resource is obfuscated, or (b) being dropped because they are not copied to the output JAR.

You should not need to be explicitly including the Java runtime classes in your configuration.

You might want to look at the following options:

-adaptclassstrings [class_filter] Specifies that string constants that correspond to class names should be obfuscated as well. Without a filter, all string constants that correspond to class names are adapted. With a filter, only string constants in classes that match the filter are adapted. For example, if your code contains a large number of hard-coded strings that refer to classes, and you prefer not to keep their names, you may want to use this option. Primarily applicable when obfuscating, although corresponding classes are automatically kept in the shrinking step too.

-adaptresourcefilenames [file_filter] Specifies the resource files to be renamed, based on the obfuscated names of the corresponding class files (if any). Without a filter, all resource files that correspond to class files are renamed. With a filter, only matching files are renamed. For example, see processing resource files. Only applicable when obfuscating.

-adaptresourcefilecontents [file_filter] Specifies the resource files whose contents are to be updated. Any class names mentioned in the resource files are renamed, based on the obfuscated names of the corresponding classes (if any). Without a filter, the contents of all resource files updated. With a filter, only matching files are updated. The resource files are parsed and written using the platform's default character set. You can change this default character set by setting the environment variable LANG or the Java system property file.encoding. For an example, see processing resource files. Only applicable when obfuscating.

And see http://proguard.sourceforge.net/manual/examples.html#resourcefiles for more detail.

Community
  • 1
  • 1
Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
  • Thanks for the ideas, I'll give those a shot. – jocull Feb 11 '11 at 14:42
  • I do know ProGuard works with this kind of thing. I have several GUI applications that I bundle with icons and other images and it works fine for those. Though, in my case, I think the images are bundled into the root of the JAR, most often. – Lawrence Dol Feb 11 '11 at 18:47
  • This problem has to do with NetBean's GUI builder and *.property files associated to the classes. It puts them in a resources folder, and that's not being obfuscated... so there are problems. The solution here says to just not obfuscate those class names. http://sourceforge.net/projects/proguard/forums/forum/182456/topic/3983208 I wonder if there is a better solution, though? – jocull Feb 11 '11 at 23:57
0
  1. Improbable. OTOH, what do you mean? Isn't "core Java libraries outside of jre/lib/rt.jar" an oxymoron?

  2. As I had a similar problem,. I started with letting PG do nothing at all, then allowed obfuscation of a part of my classes, etc., a sort of binary search for the problem. At the end I found the culprit and could let obfuscate nearly everything.

  3. Make sure you don't swallow any exception. Try to access the images using Class.getResource, so you find out if it works. Disable everything.

maaartinus
  • 44,714
  • 32
  • 161
  • 320
  • Sorry, still a bit new to Java. I saw some other jars in the Java install directory like `charsets.jar` and thought it may be related my missing text. Thanks for the suggestions, I'll see where I can get. – jocull Feb 11 '11 at 14:41