Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With ProGuard, how do I obfuscate just one class?

Tags:

proguard

What would be a smart ProGuard configuration to obfuscate just the private methods and constants of one particular class com.acme.Algorithm?

I would like to obfuscate just that, because it contains an algorithm that should not be plain obvious when accidentally opening the .jar.

I'm a ProGuard newbie. AFAIU, you have to use "keep", but the positive logic of "do obfuscate" is not available, right? So how to exlude my class from a "keep everything" config? Note: I don't want to obfuscate other classes for the moment, because I want to allow the customer to see meaningful stacktraces.

like image 361
leo Avatar asked Jul 26 '13 11:07

leo


People also ask

How do you keep a class in ProGuard?

-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.

How does ProGuard obfuscation work?

In the obfuscation step, ProGuard renames classes and class members that are not entry points. In this entire process, keeping the entry points ensures that they can still be accessed by their original names. The preverification step is the only step that doesn't have to know the entry points.

Does ProGuard obfuscate package name?

Obfuscating package names myapplication. MyMain is the main application class that is kept by the configuration. All other class names can be obfuscated. Note that not all levels of obfuscation of package names may be acceptable for all code.

How to obfuscate a plugin using ProGuard?

Resource [Tutorial] How to obfuscate a plugin using ProGuard 1 Add your plugin, the file the obfuscated plugin should be saved to and the dependencies (also the spigot api / the... 2 Disable shrinking and optimization. 3 Enable "Obfuscation Dictionary", "Class obfuscation dictionary", "Package obfuscation dictionary" and use a... More ...

How can I obfuscate my Java class files?

As I've written before in Java decompilers and obfuscators, if you're sharing a Java application with other people, and you don't want them to be able to easily decompile your Java class files, you're going to want to obfuscate your Java class files. One way to obfuscate your class files is with a tool named ProGuard.

What is ProGuard?

What is Proguard? ProGuard is a free Java tool in Android that performs three major roles: 1. Shrink/minify the code (remove unused code in the project)

Should I obfuscate my code to prevent it from being cracked?

Yes but obfuscating stops the majority of people from accessing your code, Plus for a good obfuscare it would tkae tens if not hundereds of hours to crack as a user once tried to crack EWG and gave up after about 15 hours of trying. As a User, Does this not require more load on my Server to use your plugin? Click to expand... 1.


1 Answers

Obfuscating a single class won't have much effect: it may change the class name and a few field names and methods names, and it may optimize some code. Obfuscation tends to be less effective for hiding small pieces of information. The more application code you obfuscate, the more difficult it becomes to understand.

That being said, you can specify:

-keep class !com.acme.Algorithm { *; }

It keeps all classes/fields/methods outside of com.acme.Algorithm.

like image 198
Eric Lafortune Avatar answered Oct 15 '22 01:10

Eric Lafortune