Setting ProGuard to obfuscate local variables and arguments

走远了吗. 提交于 2019-11-30 18:51:54

问题


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>;
}

回答1:


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



来源:https://stackoverflow.com/questions/20334584/setting-proguard-to-obfuscate-local-variables-and-arguments

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