Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting ProGuard to obfuscate local variables and arguments

Tags:

java

proguard

I can't seem to find the setting that will obfuscate the local variables, inside methods of a class which is obfuscated.

Here's an excerpt from one of the classes I've decompiled, with some obvious missing parts. Ideally, the arguments for the methods, and the local variables, would be obfuscated too.

public class eA extends gu
{
  private final gt a;
  private final gt b;

  public static boolean a(fy game)
  {
    boolean playerDead = game.k().j() <= 0;
    boolean enemyDead = game.g().a().size <= 0;
    boolean wavesRemain = game.r() > 0;
    return (playerDead) || ((!wavesRemain) && (enemyDead));
  }

  public eA(gt gameState, gt boardState)
  {
    this.b = gameState;
    this.a = boardState;
  }

  public void a()
  {
    n();
    boolean playerDead = this.f.k().j() <= 0;
    boolean enemyDead = this.f.g().a().size <= 0;
    if (a(this.f)) {
      if (enemyDead) {
        this.f.a(new eG(1));
        this.e.a(new eW());
      } else if (playerDead) {
        this.f.a(new eF());

Edit, I'm also attaching the proguard config

-dontskipnonpubliclibraryclassmembers
-dontshrink
-dontoptimize
-printmapping build/libs/output/obfuscation.map
-keepattributes
-adaptclassstrings
-dontnote
-dontwarn

# Keep Android classes
-keep class ** extends android.** {
    <fields>;
    <methods>;
}

# Keep serializable classes & fields
-keep class ** extends java.io.Serializable {
    <fields>;
}

# Keep - Applications. Keep all application classes, along with their 'main'
# methods.
-keepclasseswithmembers public class * {
    public static void main(java.lang.String[]);
}

# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum  * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
    native <methods>;
}
like image 794
Richard Taylor Avatar asked Dec 02 '25 05:12

Richard Taylor


1 Answers

You should remove or refine the option -keepattributes. It implies keeping attributes with local variable names:

-keepattributes LocalVariableTable,LocalVariableTypeTable

You could at least exclude those

-keepattributes !LocalVariableTable,!LocalVariableTypeTable

Ideally, you'd only preserve the attributes that are strictly required.

See the ProGuard manual > Usage > -keepattributes

like image 131
Eric Lafortune Avatar answered Dec 03 '25 21:12

Eric Lafortune



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!