How to obfuscate everything except public names of methods and attributes using proguard?

I am creating an android framework and I need to confuse and compress the jar in order to send it to users.

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

  • save all classes included in the input jar, but obfuscate them.
  • do not obfuscate class class names called in `AndroidManifest.xml
  • do not obfuscate the class name and public method names / attributes for the class used, has an interface for the user, however do this for their contents.

To do this, 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 names and attributes of private classes still have the same name, even if the contents are obfuscated. Am I missing something in my wildcards?

+5
source share
1 answer

With a little work, I found the following:

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

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

I used the following class:

 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 result class was as follows:

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

Source: https://habr.com/ru/post/1236969/


All Articles