YGuard obfuscate single class, package and exclude libraries

2.6k views Asked by At

I'm trying to use YGuard to obfuscate some parts of my program which contain encryption methods and other sensitive information (which I'll further protect in other ways once I figure this out).

Because the program is quite complex and contains quite many libraries it obviously gives a series of warning and finally fails with:

  WARNING: Method initialize_ffi_type is native but com/sun/jna/Native is not kept/exposed.
  WARNING: Method getAPIChecksum is native but com/sun/jna/Native is not kept/exposed.
  [...]
  yGuard was unable to resolve a class (java.lang.ClassNotFoundException: com.sun.tools.javac.parser.Parser$Factory)

Now whatever that means I'd like to

  • exclude libraries which being all open source have nothing to hide so far
  • obfuscate just the methods and variables of some Class or some package and leave the rest untouched.

So far in YGuard it seems I have to specify what I don't want to be obfuscated, however I have far too many classes, I'd like instead to do the opposite: Specify what I'd like to obfuscate and proceed increasing the number of Classes and packages I want obfuscated.

Thanks

1

There are 1 answers

0
zhujik On

It is the normal practice for obfuscators to specify what should be kept and not the other way around.

However, you can define library classpaths with the externalclasses rule (link). Classes that are defined in this path are neither obfuscated nor shrinked. The second error you are getting (ClassNotFoundException) indicates that you have not specified all libraries that your project depends on.

In order to obfuscate your code now, what you could do is:

  • Pack the code that you want to be obfuscated in one jar and define everything else as a library
  • use a patternset in your keep rule (link) to define everything to be kept except the classes that you want to have obfuscated.