如何使用proguard混淆除公共方法名称和属性以外的所有内容? [英] How to obfuscate everything but public method names and attributes with proguard?

查看:481
本文介绍了如何使用proguard混淆除公共方法名称和属性以外的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个android框架,我需要混淆并缩小jar才能将其发送给用户.

I'm building an android framework and I need to obfuscate and shrink the jar to ship it to users.

我正在使用android SDK中包含的proguard工具,对输出jar的要求如下:

I'm using the proguard tool included in the android SDK and I have the following requirements for the output jar:

  • 保留输入jar中包含的所有类,但对其进行混淆.
  • 不要混淆在`AndroidManifest.xml
  • 中调用的类的类名
  • 不要混淆所使用的类的类名和公共方法名称/属性,该类具有用户接口,但要为其内容提供接口.
  • keep all the classes included in the input jar, but obfuscate them.
  • don't obfuscate the class names of the classes called in the `AndroidManifest.xml
  • don't obfuscate the class name and public method names/attributes for the class that is used has an interface for the user, however do it for their contents.

为此,我使用以下配置:

To do so, I use the following configuration :

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-keep, allowobfuscation class com.company.*
-keepclassmembers, allowobfuscation class * {
    *;
}


-keepnames class com.company.MyClass { *; }
-keepclassmembernames class com.company.MyClass {
    public <methods>;
    public <fields>;
    #!private *; also tried this but it didn't work
}

但是,即使对内容进行了模糊处理,我的私有类名称和属性仍然具有相同的名称.我是否遗漏了通配符中的某些内容?

However my private classes names and attributes still have the same name even though the content is obfuscated. Did I miss something in my wildcards?

推荐答案

玩了一段时间之后,我发现以下内容有效

After playing a bit, I found the following to be working

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-keep, allowobfuscation class com.company.*
-keepclassmembers, allowobfuscation class * {
    *;
}

-keepnames class com.company.MyClass
-keepclassmembernames class com.company.MyClass {
    public <methods>;
    public <fields>;
    #!private *; also tried this but it didn't work
}

您的配置中的错误是-keepnames选项结尾处存在{ *; }.

The error in your configuration is the presence of { *; } at the end of the -keepnames option.

我使用了以下课程:

package com.company;

public class MyClass {
  public static void main(String[] args) {
    int longVariableName = publicStaticMethod();
    String abcxyz = privateStaticMethod("abc", "xyz");
    System.out.println("longVariableName: " + longVariableName);
    System.out.println("abcxyz: " + abcxyz);
  }

  public static int publicStaticMethod() {
    return 9000;
  }

  private static String privateStaticMethod(String first, String second) {
    return first + second;
  }
}

反编译后的结果类是这样的:

and the decompiled resulting class was this:

package com.company;

import java.io.PrintStream;

public class MyClass {
  public static void main(String[] paramArrayOfString) {
    paramArrayOfString = publicStaticMethod();
    String str = a("abc", "xyz");
    System.out.println("longVariableName: " + paramArrayOfString);
    System.out.println("abcxyz: " + str);
  }

  public static int publicStaticMethod() {
    return 9000;
  }

  private static String a(String paramString1, String paramString2) {
    return paramString1 + paramString2;
  }
}

这篇关于如何使用proguard混淆除公共方法名称和属性以外的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆