Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont repeat names 6.2.2 #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ sourceSets.main {
}
}

sourceSets.test {
java {
srcDir "$projectDir/test"
}
}

test {
useJUnitPlatform()
maxHeapSize = '1G'
}

jar {
manifest.from 'src/META-INF/MANIFEST.MF'
}


dependencies {
compile "com.google.code.gson:gson:${gsonVersion}"
testImplementation "org.junit.jupiter:junit-jupiter:${jupiterVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}"
}
1 change: 1 addition & 0 deletions core/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
target = 1.8

gsonVersion = 2.8.5
jupiterVersion = 5.6.0
23 changes: 23 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
</parent>
<artifactId>proguard-base</artifactId>
<name>[${project.groupId}] ${project.artifactId}</name>
<version>6.2.2.1</version>

<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -33,9 +35,11 @@
</archive>
</configuration>
</plugin>
<!--
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
-->
</plugins>
</build>

Expand All @@ -46,6 +50,25 @@
<version>2.8.5</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
15 changes: 15 additions & 0 deletions core/src/proguard/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ public class Configuration
*/
public boolean obfuscate = true;

/**
* Specifies whether package naming factory should reset for each package or not.
*/
public boolean dontResetPackageNaming = false;

/**
* Specifies whether class naming factory should reset for each package or not.
*/
public boolean dontResetClassNaming = false;

/**
* Specifies whether class member naming factory should reset for each package or not.
*/
public boolean dontResetMemberNaming = false;

/**
* An optional output file for listing the obfuscation mapping.
* An empty file name means the standard output.
Expand Down
3 changes: 3 additions & 0 deletions core/src/proguard/ConfigurationConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class ConfigurationConstants
public static final String DONT_OBFUSCATE_OPTION = "-dontobfuscate";
public static final String PRINT_MAPPING_OPTION = "-printmapping";
public static final String APPLY_MAPPING_OPTION = "-applymapping";
public static final String DONT_RESET_PACKAGE_NAMING_OPTION = "-dontresetpackagenaming";
public static final String DONT_RESET_CLASS_NAMING_OPTION = "-dontresetclassnaming";
public static final String DONT_RESET_MEMBER_NAMING_OPTION = "-dontresetmembernaming";
public static final String OBFUSCATION_DICTIONARY_OPTION = "-obfuscationdictionary";
public static final String CLASS_OBFUSCATION_DICTIONARY_OPTION = "-classobfuscationdictionary";
public static final String PACKAGE_OBFUSCATION_DICTIONARY_OPTION = "-packageobfuscationdictionary";
Expand Down
3 changes: 3 additions & 0 deletions core/src/proguard/ConfigurationParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public void parse(Configuration configuration)
else if (ConfigurationConstants.DONT_OBFUSCATE_OPTION .startsWith(nextWord)) configuration.obfuscate = parseNoArgument(false);
else if (ConfigurationConstants.PRINT_MAPPING_OPTION .startsWith(nextWord)) configuration.printMapping = parseOptionalFile();
else if (ConfigurationConstants.APPLY_MAPPING_OPTION .startsWith(nextWord)) configuration.applyMapping = parseFile();
else if (ConfigurationConstants.DONT_RESET_PACKAGE_NAMING_OPTION .startsWith(nextWord)) configuration.dontResetPackageNaming = parseNoArgument(true);
else if (ConfigurationConstants.DONT_RESET_CLASS_NAMING_OPTION .startsWith(nextWord)) configuration.dontResetClassNaming = parseNoArgument(true);
else if (ConfigurationConstants.DONT_RESET_MEMBER_NAMING_OPTION .startsWith(nextWord)) configuration.dontResetMemberNaming = parseNoArgument(true);
else if (ConfigurationConstants.OBFUSCATION_DICTIONARY_OPTION .startsWith(nextWord)) configuration.obfuscationDictionary = parseURL();
else if (ConfigurationConstants.CLASS_OBFUSCATION_DICTIONARY_OPTION .startsWith(nextWord)) configuration.classObfuscationDictionary = parseURL();
else if (ConfigurationConstants.PACKAGE_OBFUSCATION_DICTIONARY_OPTION .startsWith(nextWord)) configuration.packageObfuscationDictionary = parseURL();
Expand Down
3 changes: 3 additions & 0 deletions core/src/proguard/ConfigurationWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public void write(Configuration configuration) throws IOException
writeOption(ConfigurationConstants.DONT_OBFUSCATE_OPTION, !configuration.obfuscate);
writeOption(ConfigurationConstants.PRINT_MAPPING_OPTION, configuration.printMapping);
writeOption(ConfigurationConstants.APPLY_MAPPING_OPTION, configuration.applyMapping);
writeOption(ConfigurationConstants.DONT_RESET_PACKAGE_NAMING_OPTION, !configuration.dontResetPackageNaming);
writeOption(ConfigurationConstants.DONT_RESET_CLASS_NAMING_OPTION, !configuration.dontResetClassNaming);
writeOption(ConfigurationConstants.DONT_RESET_MEMBER_NAMING_OPTION, !configuration.dontResetMemberNaming);
writeOption(ConfigurationConstants.OBFUSCATION_DICTIONARY_OPTION, configuration.obfuscationDictionary);
writeOption(ConfigurationConstants.CLASS_OBFUSCATION_DICTIONARY_OPTION, configuration.classObfuscationDictionary);
writeOption(ConfigurationConstants.PACKAGE_OBFUSCATION_DICTIONARY_OPTION, configuration.packageObfuscationDictionary);
Expand Down
22 changes: 16 additions & 6 deletions core/src/proguard/obfuscate/ClassObfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class ClassObfuscator
private final DictionaryNameFactory classNameFactory;
private final DictionaryNameFactory packageNameFactory;
private final boolean useMixedCaseClassNames;
private final boolean dontResetPackageNaming;
private final boolean dontResetClassNaming;
private final StringMatcher keepPackageNamesMatcher;
private final String flattenPackageHierarchy;
private final String repackageClasses;
Expand Down Expand Up @@ -86,6 +88,10 @@ public class ClassObfuscator
* dictionary.
* @param useMixedCaseClassNames specifies whether obfuscated packages and
* classes can get mixed-case names.
* @param dontResetPackageNaming specifies whether package naming factory should be
* package level or root level for all packages.
* @param dontResetClassNaming specifies whether class naming factory should be
* package level or root level for all classes.
* @param keepPackageNames the optional filter for which matching
* package names are kept.
* @param flattenPackageHierarchy the base package if the obfuscated package
Expand All @@ -100,6 +106,8 @@ public ClassObfuscator(ClassPool programClassPool,
DictionaryNameFactory classNameFactory,
DictionaryNameFactory packageNameFactory,
boolean useMixedCaseClassNames,
boolean dontResetPackageNaming,
boolean dontResetClassNaming,
List keepPackageNames,
String flattenPackageHierarchy,
String repackageClasses,
Expand All @@ -123,6 +131,8 @@ public ClassObfuscator(ClassPool programClassPool,
}

this.useMixedCaseClassNames = useMixedCaseClassNames;
this.dontResetPackageNaming = dontResetPackageNaming;
this.dontResetClassNaming = dontResetClassNaming;
this.keepPackageNamesMatcher = keepPackageNames == null ? null :
new ListParser(new FileNameParser()).parse(keepPackageNames);
this.flattenPackageHierarchy = flattenPackageHierarchy;
Expand Down Expand Up @@ -403,7 +413,7 @@ private String generateUniquePackagePrefix(String newSuperPackagePrefix)
{
// Find the right name factory for this package.
NameFactory packageNameFactory =
(NameFactory)packagePrefixPackageNameFactoryMap.get(newSuperPackagePrefix);
(NameFactory)packagePrefixPackageNameFactoryMap.get((dontResetPackageNaming) ? "_" : newSuperPackagePrefix);
if (packageNameFactory == null)
{
// We haven't seen packages in this superpackage before. Create
Expand All @@ -416,7 +426,7 @@ private String generateUniquePackagePrefix(String newSuperPackagePrefix)
packageNameFactory);
}

packagePrefixPackageNameFactoryMap.put(newSuperPackagePrefix,
packagePrefixPackageNameFactoryMap.put((dontResetPackageNaming) ? "_" : newSuperPackagePrefix,
packageNameFactory);
}

Expand Down Expand Up @@ -453,7 +463,7 @@ private String generateUniqueClassName(String newPackagePrefix)
{
// Find the right name factory for this package.
NameFactory classNameFactory =
(NameFactory)packagePrefixClassNameFactoryMap.get(newPackagePrefix);
(NameFactory)packagePrefixClassNameFactoryMap.get((dontResetClassNaming) ? "_" : newPackagePrefix);
if (classNameFactory == null)
{
// We haven't seen classes in this package before.
Expand All @@ -466,7 +476,7 @@ private String generateUniqueClassName(String newPackagePrefix)
classNameFactory);
}

packagePrefixClassNameFactoryMap.put(newPackagePrefix,
packagePrefixClassNameFactoryMap.put((dontResetClassNaming) ? "_" : newPackagePrefix,
classNameFactory);
}

Expand All @@ -481,14 +491,14 @@ private String generateUniqueNumericClassName(String newPackagePrefix)
{
// Find the right name factory for this package.
NameFactory classNameFactory =
(NameFactory)packagePrefixNumericClassNameFactoryMap.get(newPackagePrefix);
(NameFactory)packagePrefixNumericClassNameFactoryMap.get((dontResetClassNaming) ? "_" : newPackagePrefix);
if (classNameFactory == null)
{
// We haven't seen classes in this package before.
// Create a new name factory for them.
classNameFactory = new NumericNameFactory();

packagePrefixNumericClassNameFactoryMap.put(newPackagePrefix,
packagePrefixNumericClassNameFactoryMap.put((dontResetClassNaming) ? "_" : newPackagePrefix,
classNameFactory);
}

Expand Down
10 changes: 9 additions & 1 deletion core/src/proguard/obfuscate/MemberObfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class MemberObfuscator
implements MemberVisitor
{
private final boolean allowAggressiveOverloading;
private final boolean dontResetMemberNaming;
private final NameFactory nameFactory;
private final Map descriptorMap;

Expand All @@ -50,16 +51,20 @@ public class MemberObfuscator
* Creates a new MemberObfuscator.
* @param allowAggressiveOverloading a flag that specifies whether class
* members can be overloaded aggressively.
* @param dontResetMemberNaming a flag that specifies whether to reset
* naming factory for every new class or not.
* @param nameFactory the factory that can produce
* obfuscated member names.
* @param descriptorMap the map of descriptors to
* [new name - old name] maps.
*/
public MemberObfuscator(boolean allowAggressiveOverloading,
boolean dontResetMemberNaming,
NameFactory nameFactory,
Map descriptorMap)
{
this.allowAggressiveOverloading = allowAggressiveOverloading;
this.dontResetMemberNaming = dontResetMemberNaming;
this.nameFactory = nameFactory;
this.descriptorMap = descriptorMap;
}
Expand Down Expand Up @@ -98,7 +103,10 @@ public void visitAnyMember(Clazz clazz, Member member)
if (newName == null)
{
// Find an acceptable new name.
nameFactory.reset();
if(!dontResetMemberNaming)
{
nameFactory.reset();
}

do
{
Expand Down
7 changes: 7 additions & 0 deletions core/src/proguard/obfuscate/Obfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public void execute(ClassPool programClassPool,
classNameFactory,
packageNameFactory,
configuration.useMixedCaseClassNames,
configuration.dontResetPackageNaming,
configuration.dontResetClassNaming,
configuration.keepPackageNames,
configuration.flattenPackageHierarchy,
configuration.repackageClasses,
Expand Down Expand Up @@ -264,6 +266,7 @@ public void execute(ClassPool programClassPool,
programClassPool.classesAccept(
new AllMemberVisitor(
new MemberObfuscator(configuration.overloadAggressively,
configuration.dontResetMemberNaming,
nameFactory,
descriptorMap)));
}
Expand Down Expand Up @@ -292,6 +295,7 @@ public void execute(ClassPool programClassPool,
new AllMemberVisitor(
new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE,
new MemberObfuscator(configuration.overloadAggressively,
configuration.dontResetMemberNaming,
nameFactory,
descriptorMap))),

Expand Down Expand Up @@ -343,6 +347,7 @@ public void execute(ClassPool programClassPool,
new AllMemberVisitor(
new MemberAccessFilter(ClassConstants.ACC_PRIVATE, 0,
new MemberObfuscator(configuration.overloadAggressively,
configuration.dontResetMemberNaming,
nameFactory,
descriptorMap))),

Expand Down Expand Up @@ -400,6 +405,7 @@ public void execute(ClassPool programClassPool,
descriptorMap,
warningPrinter,
new MemberObfuscator(configuration.overloadAggressively,
configuration.dontResetMemberNaming,
specialNameFactory,
specialDescriptorMap))))),

Expand Down Expand Up @@ -431,6 +437,7 @@ public void execute(ClassPool programClassPool,
descriptorMap,
warningPrinter,
new MemberObfuscator(configuration.overloadAggressively,
configuration.dontResetMemberNaming,
specialNameFactory,
specialDescriptorMap)))),

Expand Down
51 changes: 51 additions & 0 deletions core/test/proguard/ProGuardTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package proguard;

import org.junit.jupiter.api.Test;

class ProGuardTest {

@Test
void main() {

// NOTE: Change targetLocation value here to the location where
// inputJar and all below required items are available / expected
String targetLocation = "\\";

String inputJar = "classes";
String outputJar = "proguardClasses";
String map_filename = "proguard_map.txt";
String seed_filename = "proguard_seed.txt";
String members_dir_filename = "members-dictionary.txt";
String classes_dir_filename = "classes-dictionary.txt";
String packages_dir_filename = "packages-dictionary.txt";

String [] arguments = {
"-dontshrink",
"-dontoptimize",
"-adaptclassstrings",
"-keepparameternames",
"-keep class com.study.Application",
"-ignorewarnings",
"-injars '" + targetLocation + inputJar + "'",
"-outjars '" + targetLocation + outputJar + "'",
"-printmapping '" + targetLocation + map_filename + "'",
"-printseeds '" + targetLocation + seed_filename + "'",

// This option makes sure that the obfuscation will use all unique names for members
"-dontresetmembernaming",
// This option makes sure that the obfuscation will use all unique names for classes
"-dontresetclassnaming",
// This option makes sure that the obfuscation will use all unique names for packages
"-dontresetpackagenaming",

"-obfuscationdictionary '" + targetLocation + members_dir_filename + "'",
"-classobfuscationdictionary '" + targetLocation + classes_dir_filename + "'",
"-packageobfuscationdictionary '" + targetLocation + packages_dir_filename + "'",

"-dontwarn java.lang.**",
"-dontwarn java.util.**"
};

ProGuard.main(arguments);
}
}