summaryrefslogtreecommitdiff
path: root/src/proguard/obfuscate
diff options
context:
space:
mode:
Diffstat (limited to 'src/proguard/obfuscate')
-rw-r--r--src/proguard/obfuscate/AttributeShrinker.java120
-rw-r--r--src/proguard/obfuscate/AttributeUsageMarker.java71
-rw-r--r--src/proguard/obfuscate/ClassObfuscator.java541
-rw-r--r--src/proguard/obfuscate/ClassRenamer.java109
-rw-r--r--src/proguard/obfuscate/DictionaryNameFactory.java189
-rw-r--r--src/proguard/obfuscate/MapCleaner.java57
-rw-r--r--src/proguard/obfuscate/MappingKeeper.java177
-rw-r--r--src/proguard/obfuscate/MappingPrinter.java158
-rw-r--r--src/proguard/obfuscate/MappingProcessor.java79
-rw-r--r--src/proguard/obfuscate/MappingReader.java199
-rw-r--r--src/proguard/obfuscate/MemberNameCleaner.java60
-rw-r--r--src/proguard/obfuscate/MemberNameCollector.java105
-rw-r--r--src/proguard/obfuscate/MemberNameConflictFixer.java158
-rw-r--r--src/proguard/obfuscate/MemberNameFilter.java120
-rw-r--r--src/proguard/obfuscate/MemberObfuscator.java229
-rw-r--r--src/proguard/obfuscate/MemberSpecialNameFilter.java101
-rw-r--r--src/proguard/obfuscate/MultiMappingProcessor.java96
-rw-r--r--src/proguard/obfuscate/NameFactory.java34
-rw-r--r--src/proguard/obfuscate/NameFactoryResetter.java59
-rw-r--r--src/proguard/obfuscate/NameMarker.java164
-rw-r--r--src/proguard/obfuscate/NumericNameFactory.java46
-rw-r--r--src/proguard/obfuscate/Obfuscator.java475
-rw-r--r--src/proguard/obfuscate/ParameterNameMarker.java128
-rw-r--r--src/proguard/obfuscate/SimpleNameFactory.java156
-rw-r--r--src/proguard/obfuscate/SourceFileRenamer.java84
-rw-r--r--src/proguard/obfuscate/SpecialNameFactory.java83
-rw-r--r--src/proguard/obfuscate/package.html3
27 files changed, 0 insertions, 3801 deletions
diff --git a/src/proguard/obfuscate/AttributeShrinker.java b/src/proguard/obfuscate/AttributeShrinker.java
deleted file mode 100644
index b1b6dd3..0000000
--- a/src/proguard/obfuscate/AttributeShrinker.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.*;
-
-import java.util.Arrays;
-
-/**
- * This ClassVisitor removes attributes that are not marked as being used or
- * required.
- *
- * @see AttributeUsageMarker
- *
- * @author Eric Lafortune
- */
-public class AttributeShrinker
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- AttributeVisitor
-{
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Compact the array for class attributes.
- programClass.u2attributesCount =
- shrinkArray(programClass.attributes,
- programClass.u2attributesCount);
-
- // Compact the attributes in fields, methods, and class attributes,
- programClass.fieldsAccept(this);
- programClass.methodsAccept(this);
- programClass.attributesAccept(this);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- // Library classes are left unchanged.
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramMember(ProgramClass programClass, ProgramMember programMember)
- {
- // Compact the attributes array.
- programMember.u2attributesCount =
- shrinkArray(programMember.attributes,
- programMember.u2attributesCount);
-
- // Compact any attributes of the remaining attributes.
- programMember.attributesAccept(programClass, this);
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- {
- // Compact the attributes array.
- codeAttribute.u2attributesCount =
- shrinkArray(codeAttribute.attributes,
- codeAttribute.u2attributesCount);
- }
-
-
- // Small utility methods.
-
- /**
- * Removes all VisitorAccepter objects that are not marked as being used
- * from the given array.
- * @return the new number of VisitorAccepter objects.
- */
- private static int shrinkArray(VisitorAccepter[] array, int length)
- {
- int counter = 0;
-
- // Shift the used objects together.
- for (int index = 0; index < length; index++)
- {
- if (AttributeUsageMarker.isUsed(array[index]))
- {
- array[counter++] = array[index];
- }
- }
-
- // Clear the remaining array elements.
- Arrays.fill(array, counter, length, null);
-
- return counter;
- }
-}
diff --git a/src/proguard/obfuscate/AttributeUsageMarker.java b/src/proguard/obfuscate/AttributeUsageMarker.java
deleted file mode 100644
index 81a4554..0000000
--- a/src/proguard/obfuscate/AttributeUsageMarker.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.Attribute;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-
-/**
- * This AttributeVisitor marks all attributes that it visits.
- *
- * @see AttributeShrinker
- *
- * @author Eric Lafortune
- */
-public class AttributeUsageMarker
-extends SimplifiedVisitor
-implements AttributeVisitor
-{
- // A visitor info flag to indicate the attribute is being used.
- private static final Object USED = new Object();
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute)
- {
- markAsUsed(attribute);
- }
-
-
- // Small utility methods.
-
- /**
- * Marks the given VisitorAccepter as being used (or useful).
- * In this context, the VisitorAccepter will be an Attribute object.
- */
- private static void markAsUsed(VisitorAccepter visitorAccepter)
- {
- visitorAccepter.setVisitorInfo(USED);
- }
-
-
- /**
- * Returns whether the given VisitorAccepter has been marked as being used.
- * In this context, the VisitorAccepter will be an Attribute object.
- */
- static boolean isUsed(VisitorAccepter visitorAccepter)
- {
- return visitorAccepter.getVisitorInfo() == USED;
- }
-}
diff --git a/src/proguard/obfuscate/ClassObfuscator.java b/src/proguard/obfuscate/ClassObfuscator.java
deleted file mode 100644
index 516c889..0000000
--- a/src/proguard/obfuscate/ClassObfuscator.java
+++ /dev/null
@@ -1,541 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.ClassConstant;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.ClassVisitor;
-import proguard.util.*;
-
-import java.util.*;
-
-/**
- * This <code>ClassVisitor</code> comes up with obfuscated names for the
- * classes it visits, and for their class members. The actual renaming is
- * done afterward.
- *
- * @see ClassRenamer
- *
- * @author Eric Lafortune
- */
-public class ClassObfuscator
-extends SimplifiedVisitor
-implements ClassVisitor,
- AttributeVisitor,
- InnerClassesInfoVisitor,
- ConstantVisitor
-{
- private final DictionaryNameFactory classNameFactory;
- private final DictionaryNameFactory packageNameFactory;
- private final boolean useMixedCaseClassNames;
- private final StringMatcher keepPackageNamesMatcher;
- private final String flattenPackageHierarchy;
- private final String repackageClasses;
- private final boolean allowAccessModification;
-
- private final Set classNamesToAvoid = new HashSet();
-
- // Map: [package prefix - new package prefix]
- private final Map packagePrefixMap = new HashMap();
-
- // Map: [package prefix - package name factory]
- private final Map packagePrefixPackageNameFactoryMap = new HashMap();
-
- // Map: [package prefix - numeric class name factory]
- private final Map packagePrefixClassNameFactoryMap = new HashMap();
-
- // Map: [package prefix - numeric class name factory]
- private final Map packagePrefixNumericClassNameFactoryMap = new HashMap();
-
- // Field acting as temporary variables and as return values for names
- // of outer classes and types of inner classes.
- private String newClassName;
- private boolean numericClassName;
-
-
- /**
- * Creates a new ClassObfuscator.
- * @param programClassPool the class pool in which class names
- * have to be unique.
- * @param classNameFactory the optional class obfuscation dictionary.
- * @param packageNameFactory the optional package obfuscation
- * dictionary.
- * @param useMixedCaseClassNames specifies whether obfuscated packages and
- * classes can get mixed-case names.
- * @param keepPackageNames the optional filter for which matching
- * package names are kept.
- * @param flattenPackageHierarchy the base package if the obfuscated package
- * hierarchy is to be flattened.
- * @param repackageClasses the base package if the obfuscated classes
- * are to be repackaged.
- * @param allowAccessModification specifies whether obfuscated classes can
- * be freely moved between packages.
- */
- public ClassObfuscator(ClassPool programClassPool,
- DictionaryNameFactory classNameFactory,
- DictionaryNameFactory packageNameFactory,
- boolean useMixedCaseClassNames,
- List keepPackageNames,
- String flattenPackageHierarchy,
- String repackageClasses,
- boolean allowAccessModification)
- {
- this.classNameFactory = classNameFactory;
- this.packageNameFactory = packageNameFactory;
-
- // First append the package separator if necessary.
- if (flattenPackageHierarchy != null &&
- flattenPackageHierarchy.length() > 0)
- {
- flattenPackageHierarchy += ClassConstants.PACKAGE_SEPARATOR;
- }
-
- // First append the package separator if necessary.
- if (repackageClasses != null &&
- repackageClasses.length() > 0)
- {
- repackageClasses += ClassConstants.PACKAGE_SEPARATOR;
- }
-
- this.useMixedCaseClassNames = useMixedCaseClassNames;
- this.keepPackageNamesMatcher = keepPackageNames == null ? null :
- new ListParser(new FileNameParser()).parse(keepPackageNames);
- this.flattenPackageHierarchy = flattenPackageHierarchy;
- this.repackageClasses = repackageClasses;
- this.allowAccessModification = allowAccessModification;
-
- // Map the root package onto the root package.
- packagePrefixMap.put("", "");
-
- // Collect all names that have been taken already.
- programClassPool.classesAccept(new MyKeepCollector());
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Does this class still need a new name?
- newClassName = newClassName(programClass);
- if (newClassName == null)
- {
- // Make sure the outer class has a name, if it exists. The name will
- // be stored as the new class name, as a side effect, so we'll be
- // able to use it as a prefix.
- programClass.attributesAccept(this);
-
- // Figure out a package prefix. The package prefix may actually be
- // the an outer class prefix, if any, or it may be the fixed base
- // package, if classes are to be repackaged.
- String newPackagePrefix = newClassName != null ?
- newClassName + ClassConstants.INNER_CLASS_SEPARATOR :
- newPackagePrefix(ClassUtil.internalPackagePrefix(programClass.getName()));
-
- // Come up with a new class name, numeric or ordinary.
- newClassName = newClassName != null && numericClassName ?
- generateUniqueNumericClassName(newPackagePrefix) :
- generateUniqueClassName(newPackagePrefix);
-
- setNewClassName(programClass, newClassName);
- }
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- // This can happen for dubious input, if the outer class of a program
- // class is a library class, and its name is requested.
- newClassName = libraryClass.getName();
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
- {
- // Make sure the outer classes have a name, if they exist.
- innerClassesAttribute.innerClassEntriesAccept(clazz, this);
- }
-
-
- public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute)
- {
- // Make sure the enclosing class has a name.
- enclosingMethodAttribute.referencedClassAccept(this);
-
- String innerClassName = clazz.getName();
- String outerClassName = clazz.getClassName(enclosingMethodAttribute.u2classIndex);
-
- numericClassName = isNumericClassName(innerClassName,
- outerClassName);
- }
-
-
- // Implementations for InnerClassesInfoVisitor.
-
- public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
- {
- // Make sure the outer class has a name, if it exists.
- int innerClassIndex = innerClassesInfo.u2innerClassIndex;
- int outerClassIndex = innerClassesInfo.u2outerClassIndex;
- if (innerClassIndex != 0 &&
- outerClassIndex != 0)
- {
- String innerClassName = clazz.getClassName(innerClassIndex);
- if (innerClassName.equals(clazz.getName()))
- {
- clazz.constantPoolEntryAccept(outerClassIndex, this);
-
- String outerClassName = clazz.getClassName(outerClassIndex);
-
- numericClassName = isNumericClassName(innerClassName,
- outerClassName);
- }
- }
- }
-
-
- /**
- * Returns whether the given inner class name is a numeric name.
- */
- private boolean isNumericClassName(String innerClassName,
- String outerClassName)
- {
- int innerClassNameStart = outerClassName.length() + 1;
- int innerClassNameLength = innerClassName.length();
-
- if (innerClassNameStart >= innerClassNameLength)
- {
- return false;
- }
-
- for (int index = innerClassNameStart; index < innerClassNameLength; index++)
- {
- if (!Character.isDigit(innerClassName.charAt(index)))
- {
- return false;
- }
- }
-
- return true;
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- {
- // Make sure the outer class has a name.
- classConstant.referencedClassAccept(this);
- }
-
-
- /**
- * This ClassVisitor collects package names and class names that have to
- * be kept.
- */
- private class MyKeepCollector implements ClassVisitor
- {
- public void visitProgramClass(ProgramClass programClass)
- {
- // Does the class already have a new name?
- String newClassName = newClassName(programClass);
- if (newClassName != null)
- {
- // Remember not to use this name.
- classNamesToAvoid.add(mixedCaseClassName(newClassName));
-
- // Are we not aggressively repackaging all obfuscated classes?
- if (repackageClasses == null ||
- !allowAccessModification)
- {
- String className = programClass.getName();
-
- // Keep the package name for all other classes in the same
- // package. Do this recursively if we're not doing any
- // repackaging.
- mapPackageName(className,
- newClassName,
- repackageClasses == null &&
- flattenPackageHierarchy == null);
- }
- }
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- }
-
-
- /**
- * Makes sure the package name of the given class will always be mapped
- * consistently with its new name.
- */
- private void mapPackageName(String className,
- String newClassName,
- boolean recursively)
- {
- String packagePrefix = ClassUtil.internalPackagePrefix(className);
- String newPackagePrefix = ClassUtil.internalPackagePrefix(newClassName);
-
- // Put the mapping of this package prefix, and possibly of its
- // entire hierarchy, into the package prefix map.
- do
- {
- packagePrefixMap.put(packagePrefix, newPackagePrefix);
-
- if (!recursively)
- {
- break;
- }
-
- packagePrefix = ClassUtil.internalPackagePrefix(packagePrefix);
- newPackagePrefix = ClassUtil.internalPackagePrefix(newPackagePrefix);
- }
- while (packagePrefix.length() > 0 &&
- newPackagePrefix.length() > 0);
- }
- }
-
-
- // Small utility methods.
-
- /**
- * Finds or creates the new package prefix for the given package.
- */
- private String newPackagePrefix(String packagePrefix)
- {
- // Doesn't the package prefix have a new package prefix yet?
- String newPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
- if (newPackagePrefix == null)
- {
- // Are we keeping the package name?
- if (keepPackageNamesMatcher != null &&
- keepPackageNamesMatcher.matches(packagePrefix.length() > 0 ?
- packagePrefix.substring(0, packagePrefix.length()-1) :
- packagePrefix))
- {
- return packagePrefix;
- }
-
- // Are we forcing a new package prefix?
- if (repackageClasses != null)
- {
- return repackageClasses;
- }
-
- // Are we forcing a new superpackage prefix?
- // Otherwise figure out the new superpackage prefix, recursively.
- String newSuperPackagePrefix = flattenPackageHierarchy != null ?
- flattenPackageHierarchy :
- newPackagePrefix(ClassUtil.internalPackagePrefix(packagePrefix));
-
- // Come up with a new package prefix.
- newPackagePrefix = generateUniquePackagePrefix(newSuperPackagePrefix);
-
- // Remember to use this mapping in the future.
- packagePrefixMap.put(packagePrefix, newPackagePrefix);
- }
-
- return newPackagePrefix;
- }
-
-
- /**
- * Creates a new package prefix in the given new superpackage.
- */
- private String generateUniquePackagePrefix(String newSuperPackagePrefix)
- {
- // Find the right name factory for this package.
- NameFactory packageNameFactory =
- (NameFactory)packagePrefixPackageNameFactoryMap.get(newSuperPackagePrefix);
- if (packageNameFactory == null)
- {
- // We haven't seen packages in this superpackage before. Create
- // a new name factory for them.
- packageNameFactory = new SimpleNameFactory(useMixedCaseClassNames);
- if (this.packageNameFactory != null)
- {
- packageNameFactory =
- new DictionaryNameFactory(this.packageNameFactory,
- packageNameFactory);
- }
-
- packagePrefixPackageNameFactoryMap.put(newSuperPackagePrefix,
- packageNameFactory);
- }
-
- return generateUniquePackagePrefix(newSuperPackagePrefix, packageNameFactory);
- }
-
-
- /**
- * Creates a new package prefix in the given new superpackage, with the
- * given package name factory.
- */
- private String generateUniquePackagePrefix(String newSuperPackagePrefix,
- NameFactory packageNameFactory)
- {
- // Come up with package names until we get an original one.
- String newPackagePrefix;
- do
- {
- // Let the factory produce a package name.
- newPackagePrefix = newSuperPackagePrefix +
- packageNameFactory.nextName() +
- ClassConstants.PACKAGE_SEPARATOR;
- }
- while (packagePrefixMap.containsValue(newPackagePrefix));
-
- return newPackagePrefix;
- }
-
-
- /**
- * Creates a new class name in the given new package.
- */
- private String generateUniqueClassName(String newPackagePrefix)
- {
- // Find the right name factory for this package.
- NameFactory classNameFactory =
- (NameFactory)packagePrefixClassNameFactoryMap.get(newPackagePrefix);
- if (classNameFactory == null)
- {
- // We haven't seen classes in this package before.
- // Create a new name factory for them.
- classNameFactory = new SimpleNameFactory(useMixedCaseClassNames);
- if (this.classNameFactory != null)
- {
- classNameFactory =
- new DictionaryNameFactory(this.classNameFactory,
- classNameFactory);
- }
-
- packagePrefixClassNameFactoryMap.put(newPackagePrefix,
- classNameFactory);
- }
-
- return generateUniqueClassName(newPackagePrefix, classNameFactory);
- }
-
-
- /**
- * Creates a new class name in the given new package.
- */
- private String generateUniqueNumericClassName(String newPackagePrefix)
- {
- // Find the right name factory for this package.
- NameFactory classNameFactory =
- (NameFactory)packagePrefixNumericClassNameFactoryMap.get(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,
- classNameFactory);
- }
-
- return generateUniqueClassName(newPackagePrefix, classNameFactory);
- }
-
-
- /**
- * Creates a new class name in the given new package, with the given
- * class name factory.
- */
- private String generateUniqueClassName(String newPackagePrefix,
- NameFactory classNameFactory)
- {
- // Come up with class names until we get an original one.
- String newClassName;
- String newMixedCaseClassName;
- do
- {
- // Let the factory produce a class name.
- newClassName = newPackagePrefix +
- classNameFactory.nextName();
-
- newMixedCaseClassName = mixedCaseClassName(newClassName);
- }
- while (classNamesToAvoid.contains(newMixedCaseClassName));
-
- // Explicitly make sure the name isn't used again if we have a
- // user-specified dictionary and we're not allowed to have mixed case
- // class names -- just to protect against problematic dictionaries.
- if (this.classNameFactory != null &&
- !useMixedCaseClassNames)
- {
- classNamesToAvoid.add(newMixedCaseClassName);
- }
-
- return newClassName;
- }
-
-
- /**
- * Returns the given class name, unchanged if mixed-case class names are
- * allowed, or the lower-case version otherwise.
- */
- private String mixedCaseClassName(String className)
- {
- return useMixedCaseClassNames ?
- className :
- className.toLowerCase();
- }
-
-
- /**
- * Assigns a new name to the given class.
- * @param clazz the given class.
- * @param name the new name.
- */
- static void setNewClassName(Clazz clazz, String name)
- {
- clazz.setVisitorInfo(name);
- }
-
-
- /**
- * Retrieves the new name of the given class.
- * @param clazz the given class.
- * @return the class's new name, or <code>null</code> if it doesn't
- * have one yet.
- */
- static String newClassName(Clazz clazz)
- {
- Object visitorInfo = clazz.getVisitorInfo();
-
- return visitorInfo instanceof String ?
- (String)visitorInfo :
- null;
- }
-}
diff --git a/src/proguard/obfuscate/ClassRenamer.java b/src/proguard/obfuscate/ClassRenamer.java
deleted file mode 100644
index 0a0974d..0000000
--- a/src/proguard/obfuscate/ClassRenamer.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.constant.ClassConstant;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.editor.ConstantPoolEditor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.*;
-
-/**
- * This <code>ClassVisitor</code> renames the class names and class member
- * names of the classes it visits, using names previously determined by the
- * obfuscator.
- *
- * @see ClassObfuscator
- * @see MemberObfuscator
- *
- * @author Eric Lafortune
- */
-public class ClassRenamer
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- ConstantVisitor
-{
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Rename this class.
- programClass.thisClassConstantAccept(this);
-
- // Rename the class members.
- programClass.fieldsAccept(this);
- programClass.methodsAccept(this);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- libraryClass.thisClassName = ClassObfuscator.newClassName(libraryClass);
-
- // Rename the class members.
- libraryClass.fieldsAccept(this);
- libraryClass.methodsAccept(this);
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramMember(ProgramClass programClass,
- ProgramMember programMember)
- {
- // Has the class member name changed?
- String name = programMember.getName(programClass);
- String newName = MemberObfuscator.newMemberName(programMember);
- if (newName != null &&
- !newName.equals(name))
- {
- programMember.u2nameIndex =
- new ConstantPoolEditor(programClass).addUtf8Constant(newName);
- }
- }
-
- public void visitLibraryMember(LibraryClass libraryClass,
- LibraryMember libraryMember)
- {
- String newName = MemberObfuscator.newMemberName(libraryMember);
- if (newName != null)
- {
- libraryMember.name = newName;
- }
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- {
- // Update the Class entry if required.
- String newName = ClassObfuscator.newClassName(clazz);
- if (newName != null)
- {
- // Refer to a new Utf8 entry.
- classConstant.u2nameIndex =
- new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newName);
- }
- }
-}
diff --git a/src/proguard/obfuscate/DictionaryNameFactory.java b/src/proguard/obfuscate/DictionaryNameFactory.java
deleted file mode 100644
index ffe6e41..0000000
--- a/src/proguard/obfuscate/DictionaryNameFactory.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * This <code>NameFactory</code> generates names that are read from a
- * specified input file.
- * Comments (everything starting with '#' on a single line) are ignored.
- *
- * @author Eric Lafortune
- */
-public class DictionaryNameFactory implements NameFactory
-{
- private static final char COMMENT_CHARACTER = '#';
-
-
- private final List names;
- private final NameFactory nameFactory;
-
- private int index = 0;
-
-
- /**
- * Creates a new <code>DictionaryNameFactory</code>.
- * @param file the file from which the names can be read.
- * @param nameFactory the name factory from which names will be retrieved
- * if the list of read names has been exhausted.
- */
- public DictionaryNameFactory(File file,
- NameFactory nameFactory) throws IOException
- {
- this.names = new ArrayList();
- this.nameFactory = nameFactory;
-
- Reader reader = new FileReader(file);
-
- try
- {
- StringBuffer buffer = new StringBuffer();
-
- while (true)
- {
- // Read the next character.
- int c = reader.read();
-
- // Is it a valid identifier character?
- if (c != -1 &&
- (buffer.length() == 0 ?
- Character.isJavaIdentifierStart((char)c) :
- Character.isJavaIdentifierPart((char)c)))
- {
- // Append it to the current identifier.
- buffer.append((char)c);
- }
- else
- {
- // Did we collect a new identifier?
- if (buffer.length() > 0)
- {
- // Add the completed name to the list of names, if it's
- // not in it yet.
- String name = buffer.toString();
- if (!names.contains(name))
- {
- names.add(name);
- }
-
- // Clear the buffer.
- buffer.setLength(0);
- }
-
- // Is this the beginning of a comment line?
- if (c == COMMENT_CHARACTER)
- {
- // Skip all characters till the end of the line.
- do
- {
- c = reader.read();
- }
- while (c != -1 &&
- c != '\n' &&
- c != '\r');
- }
-
- // Is this the end of the file?
- if (c == -1)
- {
- // Just return.
- return;
- }
- }
- }
- }
- finally
- {
- reader.close();
- }
- }
-
-
- /**
- * Creates a new <code>DictionaryNameFactory</code>.
- * @param dictionaryNameFactory the dictionary name factory whose dictionary
- * will be used.
- * @param nameFactory the name factory from which names will be
- * retrieved if the list of read names has been
- * exhausted.
- */
- public DictionaryNameFactory(DictionaryNameFactory dictionaryNameFactory,
- NameFactory nameFactory)
- {
- this.names = dictionaryNameFactory.names;
- this.nameFactory = nameFactory;
- }
-
-
- // Implementations for NameFactory.
-
- public void reset()
- {
- index = 0;
-
- nameFactory.reset();
- }
-
-
- public String nextName()
- {
- String name;
-
- // Do we still have names?
- if (index < names.size())
- {
- // Return the next name.
- name = (String)names.get(index++);
- }
- else
- {
- // Return the next different name from the other name factory.
- do
- {
- name = nameFactory.nextName();
- }
- while (names.contains(name));
- }
-
- return name;
- }
-
-
- public static void main(String[] args)
- {
- try
- {
- DictionaryNameFactory factory =
- new DictionaryNameFactory(new File(args[0]), new SimpleNameFactory());
-
- for (int counter = 0; counter < 50; counter++)
- {
- System.out.println("["+factory.nextName()+"]");
- }
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
- }
-}
diff --git a/src/proguard/obfuscate/MapCleaner.java b/src/proguard/obfuscate/MapCleaner.java
deleted file mode 100644
index 365ec15..0000000
--- a/src/proguard/obfuscate/MapCleaner.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.Clazz;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.ClassVisitor;
-
-import java.util.Map;
-
-/**
- * This ClassVisitor clears a given map whenever it visits a class.
- *
- * @author Eric Lafortune
- */
-public class MapCleaner
-extends SimplifiedVisitor
-implements ClassVisitor
-{
- private final Map map;
-
-
- /**
- * Creates a new MapCleaner.
- * @param map the map to be cleared.
- */
- public MapCleaner(Map map)
- {
- this.map = map;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitAnyClass(Clazz clazz)
- {
- map.clear();
- }
-}
diff --git a/src/proguard/obfuscate/MappingKeeper.java b/src/proguard/obfuscate/MappingKeeper.java
deleted file mode 100644
index e955e53..0000000
--- a/src/proguard/obfuscate/MappingKeeper.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.util.*;
-import proguard.util.ListUtil;
-
-
-/**
- * This MappingKeeper applies the mappings that it receives to its class pool,
- * so these mappings are ensured in a subsequent obfuscation step.
- *
- * @author Eric Lafortune
- */
-public class MappingKeeper implements MappingProcessor
-{
- private final ClassPool classPool;
- private final WarningPrinter warningPrinter;
-
- // A field acting as a parameter.
- private Clazz clazz;
-
-
- /**
- * Creates a new MappingKeeper.
- * @param classPool the class pool in which class names and class
- * member names have to be mapped.
- * @param warningPrinter the optional warning printer to which warnings
- * can be printed.
- */
- public MappingKeeper(ClassPool classPool,
- WarningPrinter warningPrinter)
- {
- this.classPool = classPool;
- this.warningPrinter = warningPrinter;
- }
-
-
- // Implementations for MappingProcessor.
-
- public boolean processClassMapping(String className,
- String newClassName)
- {
- // Find the class.
- String name = ClassUtil.internalClassName(className);
-
- clazz = classPool.getClass(name);
- if (clazz != null)
- {
- String newName = ClassUtil.internalClassName(newClassName);
-
- // Print out a warning if the mapping conflicts with a name that
- // was set before.
- if (warningPrinter != null)
- {
- String currentNewName = ClassObfuscator.newClassName(clazz);
- if (currentNewName != null &&
- !currentNewName.equals(newName))
- {
- warningPrinter.print(name,
- currentNewName,
- "Warning: " +
- className +
- " is not being kept as '" +
- ClassUtil.externalClassName(currentNewName) +
- "', but remapped to '" +
- newClassName + "'");
- }
- }
-
- ClassObfuscator.setNewClassName(clazz, newName);
-
- // The class members have to be kept as well.
- return true;
- }
-
- return false;
- }
-
-
- public void processFieldMapping(String className,
- String fieldType,
- String fieldName,
- String newFieldName)
- {
- if (clazz != null)
- {
- // Find the field.
- String name = fieldName;
- String descriptor = ClassUtil.internalType(fieldType);
-
- Field field = clazz.findField(name, descriptor);
- if (field != null)
- {
- // Print out a warning if the mapping conflicts with a name that
- // was set before.
- if (warningPrinter != null)
- {
- String currentNewName = MemberObfuscator.newMemberName(field);
- if (currentNewName != null &&
- !currentNewName.equals(newFieldName))
- {
- warningPrinter.print(ClassUtil.internalClassName(className),
- "Warning: " +
- className +
- ": field '" + fieldType + " " + fieldName +
- "' is not being kept as '" + currentNewName +
- "', but remapped to '" + newFieldName + "'");
- }
- }
-
- // Make sure the mapping name will be kept.
- MemberObfuscator.setFixedNewMemberName(field, newFieldName);
- }
- }
- }
-
-
- public void processMethodMapping(String className,
- int firstLineNumber,
- int lastLineNumber,
- String methodReturnType,
- String methodName,
- String methodArguments,
- String newMethodName)
- {
- if (clazz != null)
- {
- // Find the method.
- String descriptor = ClassUtil.internalMethodDescriptor(methodReturnType,
- ListUtil.commaSeparatedList(methodArguments));
-
- Method method = clazz.findMethod(methodName, descriptor);
- if (method != null)
- {
- // Print out a warning if the mapping conflicts with a name that
- // was set before.
- if (warningPrinter != null)
- {
- String currentNewName = MemberObfuscator.newMemberName(method);
- if (currentNewName != null &&
- !currentNewName.equals(newMethodName))
- {
- warningPrinter.print(ClassUtil.internalClassName(className),
- "Warning: " +
- className +
- ": method '" + methodReturnType + " " + methodName + JavaConstants.METHOD_ARGUMENTS_OPEN + methodArguments + JavaConstants.METHOD_ARGUMENTS_CLOSE +
- "' is not being kept as '" + currentNewName +
- "', but remapped to '" + newMethodName + "'");
- }
- }
-
- // Make sure the mapping name will be kept.
- MemberObfuscator.setFixedNewMemberName(method, newMethodName);
- }
- }
- }
-}
diff --git a/src/proguard/obfuscate/MappingPrinter.java b/src/proguard/obfuscate/MappingPrinter.java
deleted file mode 100644
index 537a345..0000000
--- a/src/proguard/obfuscate/MappingPrinter.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.*;
-
-import java.io.PrintStream;
-
-
-/**
- * This ClassVisitor prints out the renamed classes and class members with
- * their old names and new names.
- *
- * @see ClassRenamer
- *
- * @author Eric Lafortune
- */
-public class MappingPrinter
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- AttributeVisitor
-{
- private final PrintStream ps;
-
-
- /**
- * Creates a new MappingPrinter that prints to <code>System.out</code>.
- */
- public MappingPrinter()
- {
- this(System.out);
- }
-
-
- /**
- * Creates a new MappingPrinter that prints to the given stream.
- * @param printStream the stream to which to print
- */
- public MappingPrinter(PrintStream printStream)
- {
- this.ps = printStream;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- String name = programClass.getName();
- String newName = ClassObfuscator.newClassName(programClass);
-
- ps.println(ClassUtil.externalClassName(name) +
- " -> " +
- ClassUtil.externalClassName(newName) +
- ":");
-
- // Print out the class members.
- programClass.fieldsAccept(this);
- programClass.methodsAccept(this);
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- String newName = MemberObfuscator.newMemberName(programField);
- if (newName != null)
- {
- ps.println(" " +
- ClassUtil.externalFullFieldDescription(
- 0,
- programField.getName(programClass),
- programField.getDescriptor(programClass)) +
- " -> " +
- newName);
- }
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- // Special cases: <clinit> and <init> are always kept unchanged.
- // We can ignore them here.
- String name = programMethod.getName(programClass);
- if (ClassUtil.isInitializer(name))
- {
- return;
- }
-
- String newName = MemberObfuscator.newMemberName(programMethod);
- if (newName != null)
- {
- ps.print(" ");
- programMethod.attributesAccept(programClass, this);
- ps.println(ClassUtil.externalFullMethodDescription(
- programClass.getName(),
- 0,
- programMethod.getName(programClass),
- programMethod.getDescriptor(programClass)) +
- " -> " +
- newName);
- }
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- {
- codeAttribute.attributesAccept(clazz, method, this);
- }
-
-
- public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
- {
- // ps.print(lineNumberTableAttribute.getLowestLineNumber() + ":" +
- // lineNumberTableAttribute.getHighestLineNumber() + ":");
- // With the above statement,
- // OpenJDK 8 (openjdk version "1.8.0_45-internal") crashed with:
- // Exception in thread "main" java.lang.AbstractMethodError:
- // java.lang.Exception.getMessage()Ljava/lang/String;
- // at proguard.ProGuard.main(ProGuard.java:519)
- //
- // Using temporary variables fixed the crash.
- // See bug 26274804.
- int low,high;
- low = lineNumberTableAttribute.getLowestLineNumber();
- high = lineNumberTableAttribute.getHighestLineNumber();
- ps.print(low + ":" + high + ":");
- }
-}
diff --git a/src/proguard/obfuscate/MappingProcessor.java b/src/proguard/obfuscate/MappingProcessor.java
deleted file mode 100644
index 8047e8d..0000000
--- a/src/proguard/obfuscate/MappingProcessor.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-
-/**
- * This interface specifies methods to process name mappings between original
- * classes and their obfuscated versions. The mappings are typically read
- * from a mapping file.
- *
- * @see MappingReader
- *
- * @author Eric Lafortune
- */
-public interface MappingProcessor
-{
- /**
- * Processes the given class name mapping.
- *
- * @param className the original class name.
- * @param newClassName the new class name.
- * @return whether the processor is interested in receiving mappings of the
- * class members of this class.
- */
- public boolean processClassMapping(String className,
- String newClassName);
-
- /**
- * Processes the given field name mapping.
- *
- * @param className the original class name.
- * @param fieldType the original external field type.
- * @param fieldName the original field name.
- * @param newFieldName the new field name.
- */
- public void processFieldMapping(String className,
- String fieldType,
- String fieldName,
- String newFieldName);
-
- /**
- * Processes the given method name mapping.
- *
- * @param className the original class name.
- * @param firstLineNumber the first line number of the method, or 0 if it
- * is not known.
- * @param lastLineNumber the last line number of the method, or 0 if it
- * is not known.
- * @param methodReturnType the original external method return type.
- * @param methodName the original external method name.
- * @param methodArguments the original external method arguments.
- * @param newMethodName the new method name.
- */
- public void processMethodMapping(String className,
- int firstLineNumber,
- int lastLineNumber,
- String methodReturnType,
- String methodName,
- String methodArguments,
- String newMethodName);
-}
diff --git a/src/proguard/obfuscate/MappingReader.java b/src/proguard/obfuscate/MappingReader.java
deleted file mode 100644
index 88a13e0..0000000
--- a/src/proguard/obfuscate/MappingReader.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import java.io.*;
-
-
-/**
- * This class can parse mapping files and invoke a processor for each of the
- * mapping entries.
- *
- * @author Eric Lafortune
- */
-public class MappingReader
-{
- private final File mappingFile;
-
-
- public MappingReader(File mappingFile)
- {
- this.mappingFile = mappingFile;
- }
-
-
- /**
- * Reads the mapping file, presenting all of the encountered mapping entries
- * to the given processor.
- */
- public void pump(MappingProcessor mappingProcessor) throws IOException
- {
- LineNumberReader reader = new LineNumberReader(
- new BufferedReader(
- new FileReader(mappingFile)));
- try
- {
- String className = null;
-
- // Read the subsequent class mappings and class member mappings.
- while (true)
- {
- String line = reader.readLine();
-
- if (line == null)
- {
- break;
- }
-
- line = line.trim();
-
- // The distinction between a class mapping and a class
- // member mapping is the initial whitespace.
- if (line.endsWith(":"))
- {
- // Process the class mapping and remember the class's
- // old name.
- className = processClassMapping(line, mappingProcessor);
- }
- else if (className != null)
- {
- // Process the class member mapping, in the context of the
- // current old class name.
- processClassMemberMapping(className, line, mappingProcessor);
- }
- }
- }
- catch (IOException ex)
- {
- throw new IOException("Can't process mapping file (" + ex.getMessage() + ")");
- }
- finally
- {
- try
- {
- reader.close();
- }
- catch (IOException ex)
- {
- // This shouldn't happen.
- }
- }
- }
-
-
- /**
- * Parses the given line with a class mapping and processes the
- * results with the given mapping processor. Returns the old class name,
- * or null if any subsequent class member lines can be ignored.
- */
- private String processClassMapping(String line,
- MappingProcessor mappingProcessor)
- {
- // See if we can parse "___ -> ___:", containing the original
- // class name and the new class name.
-
- int arrowIndex = line.indexOf("->");
- if (arrowIndex < 0)
- {
- return null;
- }
-
- int colonIndex = line.indexOf(':', arrowIndex + 2);
- if (colonIndex < 0)
- {
- return null;
- }
-
- // Extract the elements.
- String className = line.substring(0, arrowIndex).trim();
- String newClassName = line.substring(arrowIndex + 2, colonIndex).trim();
-
- // Process this class name mapping.
- boolean interested = mappingProcessor.processClassMapping(className, newClassName);
-
- return interested ? className : null;
- }
-
-
- /**
- * Parses the given line with a class member mapping and processes the
- * results with the given mapping processor.
- */
- private void processClassMemberMapping(String className,
- String line,
- MappingProcessor mappingProcessor)
- {
- // See if we can parse "___:___:___ ___(___) -> ___",
- // containing the optional line numbers, the return type, the original
- // field/method name, optional arguments, and the new field/method name.
-
- int colonIndex1 = line.indexOf(':');
- int colonIndex2 = colonIndex1 < 0 ? -1 : line.indexOf(':', colonIndex1 + 1);
- int spaceIndex = line.indexOf(' ', colonIndex2 + 2);
- int argumentIndex1 = line.indexOf('(', spaceIndex + 1);
- int argumentIndex2 = argumentIndex1 < 0 ? -1 : line.indexOf(')', argumentIndex1 + 1);
- int arrowIndex = line.indexOf("->", Math.max(spaceIndex, argumentIndex2) + 1);
-
- if (spaceIndex < 0 ||
- arrowIndex < 0)
- {
- return;
- }
-
- // Extract the elements.
- String type = line.substring(colonIndex2 + 1, spaceIndex).trim();
- String name = line.substring(spaceIndex + 1, argumentIndex1 >= 0 ? argumentIndex1 : arrowIndex).trim();
- String newName = line.substring(arrowIndex + 2).trim();
-
- // Process this class member mapping.
- if (type.length() > 0 &&
- name.length() > 0 &&
- newName.length() > 0)
- {
- // Is it a field or a method?
- if (argumentIndex2 < 0)
- {
- mappingProcessor.processFieldMapping(className, type, name, newName);
- }
- else
- {
- int firstLineNumber = 0;
- int lastLineNumber = 0;
-
- if (colonIndex2 > 0)
- {
- firstLineNumber = Integer.parseInt(line.substring(0, colonIndex1).trim());
- lastLineNumber = Integer.parseInt(line.substring(colonIndex1 + 1, colonIndex2).trim());
- }
-
- String arguments = line.substring(argumentIndex1 + 1, argumentIndex2).trim();
-
- mappingProcessor.processMethodMapping(className,
- firstLineNumber,
- lastLineNumber,
- type,
- name,
- arguments,
- newName);
- }
- }
- }
-}
diff --git a/src/proguard/obfuscate/MemberNameCleaner.java b/src/proguard/obfuscate/MemberNameCleaner.java
deleted file mode 100644
index 5b7e16f..0000000
--- a/src/proguard/obfuscate/MemberNameCleaner.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.MemberVisitor;
-
-/**
- * This <code>MemberVisitor</code> clears the new names of the class members
- * that it visits.
- *
- * @see MemberObfuscator
- *
- * @author Eric Lafortune
- */
-public class MemberNameCleaner implements MemberVisitor
-{
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- MemberObfuscator.setNewMemberName(programField, null);
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- MemberObfuscator.setNewMemberName(programMethod, null);
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
- {
- MemberObfuscator.setNewMemberName(libraryField, null);
- }
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- MemberObfuscator.setNewMemberName(libraryMethod, null);
- }
-}
diff --git a/src/proguard/obfuscate/MemberNameCollector.java b/src/proguard/obfuscate/MemberNameCollector.java
deleted file mode 100644
index bab9e95..0000000
--- a/src/proguard/obfuscate/MemberNameCollector.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.MemberVisitor;
-
-import java.util.Map;
-
-/**
- * This MemberVisitor collects all new (obfuscation) names of the members
- * that it visits.
- *
- * @see MemberObfuscator
- *
- * @author Eric Lafortune
- */
-public class MemberNameCollector
-extends SimplifiedVisitor
-implements MemberVisitor
-{
- private final boolean allowAggressiveOverloading;
- private final Map descriptorMap;
-
-
- /**
- * Creates a new MemberNameCollector.
- * @param allowAggressiveOverloading a flag that specifies whether class
- * members can be overloaded aggressively.
- * @param descriptorMap the map of descriptors to
- * [new name - old name] maps.
- */
- public MemberNameCollector(boolean allowAggressiveOverloading,
- Map descriptorMap)
- {
- this.allowAggressiveOverloading = allowAggressiveOverloading;
- this.descriptorMap = descriptorMap;
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitAnyMember(Clazz clazz, Member member)
- {
- // Special cases: <clinit> and <init> are always kept unchanged.
- // We can ignore them here.
- String name = member.getName(clazz);
- if (ClassUtil.isInitializer(name))
- {
- return;
- }
-
- // Get the member's new name.
- String newName = MemberObfuscator.newMemberName(member);
-
- // Remember it, if it has already been set.
- if (newName != null)
- {
- // Get the member's descriptor.
- String descriptor = member.getDescriptor(clazz);
-
- // Check whether we're allowed to do aggressive overloading
- if (!allowAggressiveOverloading)
- {
- // Trim the return argument from the descriptor if not.
- // Works for fields and methods alike.
- descriptor = descriptor.substring(0, descriptor.indexOf(')')+1);
- }
-
- // Put the [descriptor - new name] in the map,
- // creating a new [new name - old name] map if necessary.
- Map nameMap = MemberObfuscator.retrieveNameMap(descriptorMap, descriptor);
-
- // Isn't there another original name for this new name, or should
- // this original name get priority?
- String otherName = (String)nameMap.get(newName);
- if (otherName == null ||
- MemberObfuscator.hasFixedNewMemberName(member) ||
- name.compareTo(otherName) < 0)
- {
- // Remember not to use the new name again in this name space.
- nameMap.put(newName, name);
- }
- }
- }
-}
diff --git a/src/proguard/obfuscate/MemberNameConflictFixer.java b/src/proguard/obfuscate/MemberNameConflictFixer.java
deleted file mode 100644
index 00ac6f7..0000000
--- a/src/proguard/obfuscate/MemberNameConflictFixer.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.MemberVisitor;
-
-import java.util.Map;
-
-/**
- * This MemberInfoVisitor solves obfuscation naming conflicts in all class
- * members that it visits. It avoids names from the given descriptor map,
- * delegating to the given obfuscator in order to get a new name if necessary.
- *
- * @author Eric Lafortune
- */
-public class MemberNameConflictFixer implements MemberVisitor
-{
- private final boolean allowAggressiveOverloading;
- private final Map descriptorMap;
- private final WarningPrinter warningPrinter;
- private final MemberObfuscator memberObfuscator;
-
-
- /**
- * Creates a new MemberNameConflictFixer.
- * @param allowAggressiveOverloading a flag that specifies whether class
- * members can be overloaded aggressively.
- * @param descriptorMap the map of descriptors to
- * [new name - old name] maps.
- * @param warningPrinter an optional warning printer to which
- * warnings about conflicting name
- * mappings can be printed.
- * @param memberObfuscator the obfuscator that can assign new
- * names to members with conflicting
- * names.
- */
- public MemberNameConflictFixer(boolean allowAggressiveOverloading,
- Map descriptorMap,
- WarningPrinter warningPrinter,
- MemberObfuscator memberObfuscator)
- {
- this.allowAggressiveOverloading = allowAggressiveOverloading;
- this.descriptorMap = descriptorMap;
- this.warningPrinter = warningPrinter;
- this.memberObfuscator = memberObfuscator;
- }
-
-
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- visitMember(programClass, programField, true);
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- // Special cases: <clinit> and <init> are always kept unchanged.
- // We can ignore them here.
- String name = programMethod.getName(programClass);
- if (ClassUtil.isInitializer(name))
- {
- return;
- }
-
- visitMember(programClass, programMethod, false);
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField) {}
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod) {}
-
-
- /**
- * Obfuscates the given class member.
- * @param clazz the class of the given member.
- * @param member the class member to be obfuscated.
- * @param isField specifies whether the class member is a field.
- */
- private void visitMember(Clazz clazz,
- Member member,
- boolean isField)
- {
- // Get the member's name and descriptor.
- String name = member.getName(clazz);
- String descriptor = member.getDescriptor(clazz);
-
- // Check whether we're allowed to overload aggressively.
- if (!allowAggressiveOverloading)
- {
- // Trim the return argument from the descriptor if not.
- // Works for fields and methods alike.
- descriptor = descriptor.substring(0, descriptor.indexOf(')')+1);
- }
-
- // Get the name map.
- Map nameMap = MemberObfuscator.retrieveNameMap(descriptorMap, descriptor);
-
- // Get the member's new name.
- String newName = MemberObfuscator.newMemberName(member);
-
- // Get the expected old name for this new name.
- String previousName = (String)nameMap.get(newName);
- if (previousName != null &&
- !name.equals(previousName))
- {
- // There's a conflict! A member (with a given old name) in a
- // first namespace has received the same new name as this
- // member (with a different old name) in a second name space,
- // and now these two have to live together in this name space.
- if (MemberObfuscator.hasFixedNewMemberName(member) &&
- warningPrinter != null)
- {
- descriptor = member.getDescriptor(clazz);
- warningPrinter.print(clazz.getName(),
- "Warning: " + ClassUtil.externalClassName(clazz.getName()) +
- (isField ?
- ": field '" + ClassUtil.externalFullFieldDescription(0, name, descriptor) :
- ": method '" + ClassUtil.externalFullMethodDescription(clazz.getName(), 0, name, descriptor)) +
- "' can't be mapped to '" + newName +
- "' because it would conflict with " +
- (isField ?
- "field '" :
- "method '" ) + previousName +
- "', which is already being mapped to '" + newName + "'");
- }
-
- // Clear the conflicting name.
- MemberObfuscator.setNewMemberName(member, null);
-
- // Assign a new name.
- member.accept(clazz, memberObfuscator);
- }
- }
-}
diff --git a/src/proguard/obfuscate/MemberNameFilter.java b/src/proguard/obfuscate/MemberNameFilter.java
deleted file mode 100644
index dfff99a..0000000
--- a/src/proguard/obfuscate/MemberNameFilter.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.MemberVisitor;
-
-/**
- * This <code>MemberVisitor</code> delegates its visits to another given
- * <code>MemberVisitor</code>, but only when the visited member has a new name.
- * Constructors are judged based on the class name.
- *
- * @see ClassObfuscator
- * @see MemberObfuscator
- *
- * @author Eric Lafortune
- */
-public class MemberNameFilter implements MemberVisitor
-{
- private final MemberVisitor memberVisitor;
-
-
- /**
- * Creates a new MemberNameFilter.
- * @param memberVisitor the <code>MemberVisitor</code> to which
- * visits will be delegated.
- */
- public MemberNameFilter(MemberVisitor memberVisitor)
- {
- this.memberVisitor = memberVisitor;
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- if (hasName(programField))
- {
- memberVisitor.visitProgramField(programClass, programField);
- }
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- if (hasName(programClass, programMethod))
- {
- memberVisitor.visitProgramMethod(programClass, programMethod);
- }
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
- {
- if (hasName(libraryField))
- {
- memberVisitor.visitLibraryField(libraryClass, libraryField);
- }
- }
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- if (hasName(libraryClass, libraryMethod))
- {
- memberVisitor.visitLibraryMethod(libraryClass, libraryMethod);
- }
- }
-
-
- // Small utility methods.
-
- /**
- * Returns whether the given class has a new name.
- */
- private boolean hasName(Clazz clazz)
- {
- return ClassObfuscator.newClassName(clazz) != null;
- }
-
-
- /**
- * Returns whether the given method has a new name.
- */
- private boolean hasName(Clazz clazz, Method method)
- {
- return
- hasName(method) ||
- (hasName(clazz) &&
- method.getName(clazz).equals(ClassConstants.METHOD_NAME_INIT));
- }
-
-
- /**
- * Returns whether the given class member has a new name.
- */
- private boolean hasName(Member member)
- {
- return MemberObfuscator.newMemberName(member) != null;
- }
-}
diff --git a/src/proguard/obfuscate/MemberObfuscator.java b/src/proguard/obfuscate/MemberObfuscator.java
deleted file mode 100644
index b5211ac..0000000
--- a/src/proguard/obfuscate/MemberObfuscator.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.MemberVisitor;
-
-import java.util.*;
-
-/**
- * This MemberVisitor obfuscates all class members that it visits.
- * It uses names from the given name factory. At the same time, it avoids names
- * from the given descriptor map.
- * <p>
- * The class members must have been linked before applying this visitor.
- *
- * @see MethodLinker
- *
- * @author Eric Lafortune
- */
-public class MemberObfuscator
-extends SimplifiedVisitor
-implements MemberVisitor
-{
- private final boolean allowAggressiveOverloading;
- private final NameFactory nameFactory;
- private final Map descriptorMap;
-
-
- /**
- * Creates a new MemberObfuscator.
- * @param allowAggressiveOverloading a flag that specifies whether class
- * members can be overloaded aggressively.
- * @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,
- NameFactory nameFactory,
- Map descriptorMap)
- {
- this.allowAggressiveOverloading = allowAggressiveOverloading;
- this.nameFactory = nameFactory;
- this.descriptorMap = descriptorMap;
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitAnyMember(Clazz clazz, Member member)
- {
- // Special cases: <clinit> and <init> are always kept unchanged.
- // We can ignore them here.
- String name = member.getName(clazz);
- if (ClassUtil.isInitializer(name))
- {
- return;
- }
-
- // Get the member's descriptor.
- String descriptor = member.getDescriptor(clazz);
-
- // Check whether we're allowed to do aggressive overloading
- if (!allowAggressiveOverloading)
- {
- // Trim the return argument from the descriptor if not.
- // Works for fields and methods alike.
- descriptor = descriptor.substring(0, descriptor.indexOf(')')+1);
- }
-
- // Get the name map, creating a new one if necessary.
- Map nameMap = retrieveNameMap(descriptorMap, descriptor);
-
- // Get the member's new name.
- String newName = newMemberName(member);
-
- // Assign a new one, if necessary.
- if (newName == null)
- {
- // Find an acceptable new name.
- nameFactory.reset();
-
- do
- {
- newName = nameFactory.nextName();
- }
- while (nameMap.containsKey(newName));
-
- // Remember not to use the new name again in this name space.
- nameMap.put(newName, name);
-
- // Assign the new name.
- setNewMemberName(member, newName);
- }
- }
-
-
- // Small utility methods.
-
- /**
- * Gets the name map, based on the given map and a given descriptor.
- * A new empty map is created if necessary.
- * @param descriptorMap the map of descriptors to [new name - old name] maps.
- * @param descriptor the class member descriptor.
- * @return the corresponding name map.
- */
- static Map retrieveNameMap(Map descriptorMap, String descriptor)
- {
- // See if we can find the nested map with this descriptor key.
- Map nameMap = (Map)descriptorMap.get(descriptor);
-
- // Create a new one if not.
- if (nameMap == null)
- {
- nameMap = new HashMap();
- descriptorMap.put(descriptor, nameMap);
- }
-
- return nameMap;
- }
-
-
- /**
- * Assigns a fixed new name to the given class member.
- * @param member the class member.
- * @param name the new name.
- */
- static void setFixedNewMemberName(Member member, String name)
- {
- VisitorAccepter lastVisitorAccepter = MethodLinker.lastVisitorAccepter(member);
-
- if (!(lastVisitorAccepter instanceof LibraryMember) &&
- !(lastVisitorAccepter instanceof MyFixedName))
- {
- lastVisitorAccepter.setVisitorInfo(new MyFixedName(name));
- }
- else
- {
- lastVisitorAccepter.setVisitorInfo(name);
- }
- }
-
-
- /**
- * Assigns a new name to the given class member.
- * @param member the class member.
- * @param name the new name.
- */
- static void setNewMemberName(Member member, String name)
- {
- MethodLinker.lastVisitorAccepter(member).setVisitorInfo(name);
- }
-
-
- /**
- * Returns whether the new name of the given class member is fixed.
- * @param member the class member.
- * @return whether its new name is fixed.
- */
- static boolean hasFixedNewMemberName(Member member)
- {
- VisitorAccepter lastVisitorAccepter = MethodLinker.lastVisitorAccepter(member);
-
- return lastVisitorAccepter instanceof LibraryMember ||
- lastVisitorAccepter instanceof MyFixedName;
- }
-
-
- /**
- * Retrieves the new name of the given class member.
- * @param member the class member.
- * @return the class member's new name, or <code>null</code> if it doesn't
- * have one yet.
- */
- static String newMemberName(Member member)
- {
- return (String)MethodLinker.lastVisitorAccepter(member).getVisitorInfo();
- }
-
-
- /**
- * This VisitorAccepter can be used to wrap a name string, to indicate that
- * the name is fixed.
- */
- private static class MyFixedName implements VisitorAccepter
- {
- private String newName;
-
-
- public MyFixedName(String newName)
- {
- this.newName = newName;
- }
-
-
- // Implementations for VisitorAccepter.
-
- public Object getVisitorInfo()
- {
- return newName;
- }
-
-
- public void setVisitorInfo(Object visitorInfo)
- {
- newName = (String)visitorInfo;
- }
- }
-}
diff --git a/src/proguard/obfuscate/MemberSpecialNameFilter.java b/src/proguard/obfuscate/MemberSpecialNameFilter.java
deleted file mode 100644
index f8ab913..0000000
--- a/src/proguard/obfuscate/MemberSpecialNameFilter.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.MemberVisitor;
-
-/**
- * This <code>MemberVisitor</code> delegates its visits to another given
- * <code>MemberVisitor</code>, but only when the visited member has a
- * special new name. A special name is a name that might have been produced by
- * a <code>SpecialNameFactory</code>.
- *
- * @see MemberObfuscator
- * @see SpecialNameFactory
- *
- * @author Eric Lafortune
- */
-public class MemberSpecialNameFilter implements MemberVisitor
-{
- private final MemberVisitor memberVisitor;
-
-
- /**
- * Creates a new MemberSpecialNameFilter.
- * @param memberVisitor the <code>MemberVisitor</code> to which
- * visits will be delegated.
- */
- public MemberSpecialNameFilter(MemberVisitor memberVisitor)
- {
- this.memberVisitor = memberVisitor;
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- if (hasSpecialName(programField))
- {
- memberVisitor.visitProgramField(programClass, programField);
- }
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- if (hasSpecialName(programMethod))
- {
- memberVisitor.visitProgramMethod(programClass, programMethod);
- }
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
- {
- if (hasSpecialName(libraryField))
- {
- memberVisitor.visitLibraryField(libraryClass, libraryField);
- }
- }
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- if (hasSpecialName(libraryMethod))
- {
- memberVisitor.visitLibraryMethod(libraryClass, libraryMethod);
- }
- }
-
-
- // Small utility methods.
-
- /**
- * Returns whether the given class member has a special new name.
- * @param member the class member.
- */
- private static boolean hasSpecialName(Member member)
- {
- return SpecialNameFactory.isSpecialName(MemberObfuscator.newMemberName(member));
- }
-}
diff --git a/src/proguard/obfuscate/MultiMappingProcessor.java b/src/proguard/obfuscate/MultiMappingProcessor.java
deleted file mode 100644
index e10c100..0000000
--- a/src/proguard/obfuscate/MultiMappingProcessor.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-/**
- * This MappingKeeper delegates all method calls to each MappingProcessor
- * in a given list.
- *
- * @author Eric Lafortune
- */
-public class MultiMappingProcessor implements MappingProcessor
-{
- private final MappingProcessor[] mappingProcessors;
-
-
- /**
- * Creates a new MultiMappingProcessor.
- * @param mappingProcessors the mapping processors to which method calls
- * will be delegated.
- */
- public MultiMappingProcessor(MappingProcessor[] mappingProcessors)
- {
- this.mappingProcessors = mappingProcessors;
- }
-
-
- // Implementations for MappingProcessor.
-
- public boolean processClassMapping(String className,
- String newClassName)
- {
- boolean result = false;
-
- for (int index = 0; index < mappingProcessors.length; index++)
- {
- result |= mappingProcessors[index].processClassMapping(className,
- newClassName);
- }
-
- return result;
- }
-
-
- public void processFieldMapping(String className,
- String fieldType,
- String fieldName,
- String newFieldName)
- {
- for (int index = 0; index < mappingProcessors.length; index++)
- {
- mappingProcessors[index].processFieldMapping(className,
- fieldType,
- fieldName,
- newFieldName);
- }
- }
-
-
- public void processMethodMapping(String className,
- int firstLineNumber,
- int lastLineNumber,
- String methodReturnType,
- String methodName,
- String methodArguments,
- String newMethodName)
- {
- for (int index = 0; index < mappingProcessors.length; index++)
- {
- mappingProcessors[index].processMethodMapping(className,
- firstLineNumber,
- lastLineNumber,
- methodReturnType,
- methodName,
- methodArguments,
- newMethodName);
- }
- }
-}
diff --git a/src/proguard/obfuscate/NameFactory.java b/src/proguard/obfuscate/NameFactory.java
deleted file mode 100644
index cb5f998..0000000
--- a/src/proguard/obfuscate/NameFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-/**
- * This interfaces provides methods to generate unique sequences of names.
- * The names must be valid Java identifiers.
- *
- * @author Eric Lafortune
- */
-public interface NameFactory
-{
- public void reset();
-
- public String nextName();
-}
diff --git a/src/proguard/obfuscate/NameFactoryResetter.java b/src/proguard/obfuscate/NameFactoryResetter.java
deleted file mode 100644
index a6188a6..0000000
--- a/src/proguard/obfuscate/NameFactoryResetter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.ClassVisitor;
-
-/**
- * This ClassVisitor resets a given name factory whenever it visits a class
- * file.
- *
- * @author Eric Lafortune
- */
-public class NameFactoryResetter implements ClassVisitor
-{
- private final NameFactory nameFactory;
-
-
- /**
- * Creates a new NameFactoryResetter.
- * @param nameFactory the name factory to be reset.
- */
- public NameFactoryResetter(NameFactory nameFactory)
- {
- this.nameFactory = nameFactory;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- nameFactory.reset();
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- nameFactory.reset();
- }
-}
diff --git a/src/proguard/obfuscate/NameMarker.java b/src/proguard/obfuscate/NameMarker.java
deleted file mode 100644
index 376943f..0000000
--- a/src/proguard/obfuscate/NameMarker.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.ClassConstant;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.*;
-
-
-/**
- * This <code>ClassVisitor</code> and <code>MemberVisitor</code>
- * marks names of the classes and class members it visits. The marked names
- * will remain unchanged in the obfuscation step.
- *
- * @see ClassObfuscator
- * @see MemberObfuscator
- *
- * @author Eric Lafortune
- */
-class NameMarker
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- AttributeVisitor,
- InnerClassesInfoVisitor,
- ConstantVisitor
-{
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- keepClassName(programClass);
-
- // Make sure any outer class names are kept as well.
- programClass.attributesAccept(this);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- keepClassName(libraryClass);
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- keepFieldName(programClass, programField);
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- keepMethodName(programClass, programMethod);
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
- {
- keepFieldName(libraryClass, libraryField);
- }
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- keepMethodName(libraryClass, libraryMethod);
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
- {
- // Make sure the outer class names are kept as well.
- innerClassesAttribute.innerClassEntriesAccept(clazz, this);
- }
-
-
- // Implementations for InnerClassesInfoVisitor.
-
- public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
- {
- // Make sure the outer class name is kept as well.
- int innerClassIndex = innerClassesInfo.u2innerClassIndex;
- int outerClassIndex = innerClassesInfo.u2outerClassIndex;
- if (innerClassIndex != 0 &&
- outerClassIndex != 0 &&
- clazz.getClassName(innerClassIndex).equals(clazz.getName()))
- {
- clazz.constantPoolEntryAccept(outerClassIndex, this);
- }
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- {
- // Make sure the outer class name is kept as well.
- classConstant.referencedClassAccept(this);
- }
-
-
- // Small utility method.
-
- /**
- * Ensures the name of the given class name will be kept.
- */
- public void keepClassName(Clazz clazz)
- {
- ClassObfuscator.setNewClassName(clazz,
- clazz.getName());
- }
-
-
- /**
- * Ensures the name of the given field name will be kept.
- */
- private void keepFieldName(Clazz clazz, Field field)
- {
- MemberObfuscator.setFixedNewMemberName(field,
- field.getName(clazz));
- }
-
-
- /**
- * Ensures the name of the given method name will be kept.
- */
- private void keepMethodName(Clazz clazz, Method method)
- {
- String name = method.getName(clazz);
-
- if (!ClassUtil.isInitializer(name))
- {
- MemberObfuscator.setFixedNewMemberName(method, name);
- }
- }
-}
diff --git a/src/proguard/obfuscate/NumericNameFactory.java b/src/proguard/obfuscate/NumericNameFactory.java
deleted file mode 100644
index 0a23f16..0000000
--- a/src/proguard/obfuscate/NumericNameFactory.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-/**
- * This <code>NameFactory</code> generates unique numeric names, starting at
- * "1".
- *
- * @author Eric Lafortune
- */
-public class NumericNameFactory implements NameFactory
-{
- private int index;
-
-
- // Implementations for NameFactory.
-
- public void reset()
- {
- index = 0;
- }
-
-
- public String nextName()
- {
- return Integer.toString(++index);
- }
-} \ No newline at end of file
diff --git a/src/proguard/obfuscate/Obfuscator.java b/src/proguard/obfuscate/Obfuscator.java
deleted file mode 100644
index b2758a7..0000000
--- a/src/proguard/obfuscate/Obfuscator.java
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.*;
-import proguard.classfile.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.visitor.AllConstantVisitor;
-import proguard.classfile.editor.*;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.*;
-import proguard.util.*;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * This class can perform obfuscation of class pools according to a given
- * specification.
- *
- * @author Eric Lafortune
- */
-public class Obfuscator
-{
- private final Configuration configuration;
-
-
- /**
- * Creates a new Obfuscator.
- */
- public Obfuscator(Configuration configuration)
- {
- this.configuration = configuration;
- }
-
-
- /**
- * Performs obfuscation of the given program class pool.
- */
- public void execute(ClassPool programClassPool,
- ClassPool libraryClassPool) throws IOException
- {
- // Check if we have at least some keep commands.
- if (configuration.keep == null &&
- configuration.applyMapping == null &&
- configuration.printMapping == null)
- {
- throw new IOException("You have to specify '-keep' options for the obfuscation step.");
- }
-
- // Clean up any old visitor info.
- programClassPool.classesAccept(new ClassCleaner());
- libraryClassPool.classesAccept(new ClassCleaner());
-
- // If the class member names have to correspond globally,
- // link all class members in all classes, otherwise
- // link all non-private methods in all class hierarchies.
- ClassVisitor memberInfoLinker =
- configuration.useUniqueClassMemberNames ?
- (ClassVisitor)new AllMemberVisitor(new MethodLinker()) :
- (ClassVisitor)new BottomClassFilter(new MethodLinker());
-
- programClassPool.classesAccept(memberInfoLinker);
- libraryClassPool.classesAccept(memberInfoLinker);
-
- // Create a visitor for marking the seeds.
- NameMarker nameMarker = new NameMarker();
- ClassPoolVisitor classPoolvisitor =
- ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.keep,
- nameMarker,
- nameMarker,
- false,
- false,
- true);
- // Mark the seeds.
- programClassPool.accept(classPoolvisitor);
- libraryClassPool.accept(classPoolvisitor);
-
- // All library classes and library class members keep their names.
- libraryClassPool.classesAccept(nameMarker);
- libraryClassPool.classesAccept(new AllMemberVisitor(nameMarker));
-
- // We also keep the names of all methods of classes that are returned
- // by dynamic method invocations. They may return dynamic
- // implementations of interfaces. The method names then have to match
- // with the invoke dynamic names.
- programClassPool.classesAccept(
- new ClassVersionFilter(ClassConstants.CLASS_VERSION_1_7,
- new AllConstantVisitor(
- new DynamicReturnedClassVisitor(
- new AllMemberVisitor(nameMarker)))));
-
- // Mark attributes that have to be kept.
- AttributeVisitor attributeUsageMarker =
- new NonEmptyAttributeFilter(
- new AttributeUsageMarker());
-
- AttributeVisitor optionalAttributeUsageMarker =
- configuration.keepAttributes == null ? null :
- new AttributeNameFilter(configuration.keepAttributes,
- attributeUsageMarker);
-
- programClassPool.classesAccept(
- new AllAttributeVisitor(true,
- new RequiredAttributeFilter(attributeUsageMarker,
- optionalAttributeUsageMarker)));
-
- // Keep parameter names and types if specified.
- if (configuration.keepParameterNames)
- {
- programClassPool.classesAccept(
- new AllMethodVisitor(
- new MemberNameFilter(
- new AllAttributeVisitor(true,
- new ParameterNameMarker(attributeUsageMarker)))));
- }
-
- // Remove the attributes that can be discarded. Note that the attributes
- // may only be discarded after the seeds have been marked, since the
- // configuration may rely on annotations.
- programClassPool.classesAccept(new AttributeShrinker());
-
- // Apply the mapping, if one has been specified. The mapping can
- // override the names of library classes and of library class members.
- if (configuration.applyMapping != null)
- {
- WarningPrinter warningPrinter = new WarningPrinter(System.err, configuration.warn);
-
- MappingReader reader = new MappingReader(configuration.applyMapping);
-
- MappingProcessor keeper =
- new MultiMappingProcessor(new MappingProcessor[]
- {
- new MappingKeeper(programClassPool, warningPrinter),
- new MappingKeeper(libraryClassPool, null),
- });
-
- reader.pump(keeper);
-
- // Print out a summary of the warnings if necessary.
- int warningCount = warningPrinter.getWarningCount();
- if (warningCount > 0)
- {
- System.err.println("Warning: there were " + warningCount +
- " kept classes and class members that were remapped anyway.");
- System.err.println(" You should adapt your configuration or edit the mapping file.");
-
- if (!configuration.ignoreWarnings)
- {
- System.err.println(" If you are sure this remapping won't hurt, you could try your luck");
- System.err.println(" using the '-ignorewarnings' option.");
- }
-
- System.err.println(" (http://proguard.sourceforge.net/manual/troubleshooting.html#mappingconflict1)");
-
- if (!configuration.ignoreWarnings)
- {
- throw new IOException("Please correct the above warnings first.");
- }
- }
- }
-
- // Come up with new names for all classes.
- DictionaryNameFactory classNameFactory = configuration.classObfuscationDictionary != null ?
- new DictionaryNameFactory(configuration.classObfuscationDictionary, null) :
- null;
-
- DictionaryNameFactory packageNameFactory = configuration.packageObfuscationDictionary != null ?
- new DictionaryNameFactory(configuration.packageObfuscationDictionary, null) :
- null;
-
- programClassPool.classesAccept(
- new ClassObfuscator(programClassPool,
- classNameFactory,
- packageNameFactory,
- configuration.useMixedCaseClassNames,
- configuration.keepPackageNames,
- configuration.flattenPackageHierarchy,
- configuration.repackageClasses,
- configuration.allowAccessModification));
-
- // Come up with new names for all class members.
- NameFactory nameFactory = new SimpleNameFactory();
-
- if (configuration.obfuscationDictionary != null)
- {
- nameFactory = new DictionaryNameFactory(configuration.obfuscationDictionary,
- nameFactory);
- }
-
- WarningPrinter warningPrinter = new WarningPrinter(System.err, configuration.warn);
-
- // Maintain a map of names to avoid [descriptor - new name - old name].
- Map descriptorMap = new HashMap();
-
- // Do the class member names have to be globally unique?
- if (configuration.useUniqueClassMemberNames)
- {
- // Collect all member names in all classes.
- programClassPool.classesAccept(
- new AllMemberVisitor(
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)));
-
- // Assign new names to all members in all classes.
- programClassPool.classesAccept(
- new AllMemberVisitor(
- new MemberObfuscator(configuration.overloadAggressively,
- nameFactory,
- descriptorMap)));
- }
- else
- {
- // Come up with new names for all non-private class members.
- programClassPool.classesAccept(
- new MultiClassVisitor(new ClassVisitor[]
- {
- // Collect all private member names in this class and down
- // the hierarchy.
- new ClassHierarchyTraveler(true, false, false, true,
- new AllMemberVisitor(
- new MemberAccessFilter(ClassConstants.ACC_PRIVATE, 0,
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)))),
-
- // Collect all non-private member names anywhere in the hierarchy.
- new ClassHierarchyTraveler(true, true, true, true,
- new AllMemberVisitor(
- new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE,
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)))),
-
- // Assign new names to all non-private members in this class.
- new AllMemberVisitor(
- new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE,
- new MemberObfuscator(configuration.overloadAggressively,
- nameFactory,
- descriptorMap))),
-
- // Clear the collected names.
- new MapCleaner(descriptorMap)
- }));
-
- // Come up with new names for all private class members.
- programClassPool.classesAccept(
- new MultiClassVisitor(new ClassVisitor[]
- {
- // Collect all member names in this class.
- new AllMemberVisitor(
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)),
-
- // Collect all non-private member names higher up the hierarchy.
- new ClassHierarchyTraveler(false, true, true, false,
- new AllMemberVisitor(
- new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE,
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)))),
-
- // Collect all member names from interfaces of abstract
- // classes down the hierarchy.
- // Due to an error in the JLS/JVMS, virtual invocations
- // may end up at a private method otherwise (Sun/Oracle
- // bugs #6691741 and #6684387, ProGuard bug #3471941,
- // and ProGuard test #1180).
- new ClassHierarchyTraveler(false, false, false, true,
- new ClassAccessFilter(ClassConstants.ACC_ABSTRACT, 0,
- new ClassHierarchyTraveler(false, false, true, false,
- new AllMemberVisitor(
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap))))),
-
- // Assign new names to all private members in this class.
- new AllMemberVisitor(
- new MemberAccessFilter(ClassConstants.ACC_PRIVATE, 0,
- new MemberObfuscator(configuration.overloadAggressively,
- nameFactory,
- descriptorMap))),
-
- // Clear the collected names.
- new MapCleaner(descriptorMap)
- }));
- }
-
- // Some class members may have ended up with conflicting names.
- // Come up with new, globally unique names for them.
- NameFactory specialNameFactory =
- new SpecialNameFactory(new SimpleNameFactory());
-
- // Collect a map of special names to avoid
- // [descriptor - new name - old name].
- Map specialDescriptorMap = new HashMap();
-
- programClassPool.classesAccept(
- new AllMemberVisitor(
- new MemberSpecialNameFilter(
- new MemberNameCollector(configuration.overloadAggressively,
- specialDescriptorMap))));
-
- libraryClassPool.classesAccept(
- new AllMemberVisitor(
- new MemberSpecialNameFilter(
- new MemberNameCollector(configuration.overloadAggressively,
- specialDescriptorMap))));
-
- // Replace conflicting non-private member names with special names.
- programClassPool.classesAccept(
- new MultiClassVisitor(new ClassVisitor[]
- {
- // Collect all private member names in this class and down
- // the hierarchy.
- new ClassHierarchyTraveler(true, false, false, true,
- new AllMemberVisitor(
- new MemberAccessFilter(ClassConstants.ACC_PRIVATE, 0,
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)))),
-
- // Collect all non-private member names in this class and
- // higher up the hierarchy.
- new ClassHierarchyTraveler(true, true, true, false,
- new AllMemberVisitor(
- new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE,
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)))),
-
- // Assign new names to all conflicting non-private members
- // in this class and higher up the hierarchy.
- new ClassHierarchyTraveler(true, true, true, false,
- new AllMemberVisitor(
- new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE,
- new MemberNameConflictFixer(configuration.overloadAggressively,
- descriptorMap,
- warningPrinter,
- new MemberObfuscator(configuration.overloadAggressively,
- specialNameFactory,
- specialDescriptorMap))))),
-
- // Clear the collected names.
- new MapCleaner(descriptorMap)
- }));
-
- // Replace conflicting private member names with special names.
- // This is only possible if those names were kept or mapped.
- programClassPool.classesAccept(
- new MultiClassVisitor(new ClassVisitor[]
- {
- // Collect all member names in this class.
- new AllMemberVisitor(
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)),
-
- // Collect all non-private member names higher up the hierarchy.
- new ClassHierarchyTraveler(false, true, true, false,
- new AllMemberVisitor(
- new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE,
- new MemberNameCollector(configuration.overloadAggressively,
- descriptorMap)))),
-
- // Assign new names to all conflicting private members in this
- // class.
- new AllMemberVisitor(
- new MemberAccessFilter(ClassConstants.ACC_PRIVATE, 0,
- new MemberNameConflictFixer(configuration.overloadAggressively,
- descriptorMap,
- warningPrinter,
- new MemberObfuscator(configuration.overloadAggressively,
- specialNameFactory,
- specialDescriptorMap)))),
-
- // Clear the collected names.
- new MapCleaner(descriptorMap)
- }));
-
- // Print out any warnings about member name conflicts.
- int warningCount = warningPrinter.getWarningCount();
- if (warningCount > 0)
- {
- System.err.println("Warning: there were " + warningCount +
- " conflicting class member name mappings.");
- System.err.println(" Your configuration may be inconsistent.");
-
- if (!configuration.ignoreWarnings)
- {
- System.err.println(" If you are sure the conflicts are harmless,");
- System.err.println(" you could try your luck using the '-ignorewarnings' option.");
- }
-
- System.err.println(" (http://proguard.sourceforge.net/manual/troubleshooting.html#mappingconflict2)");
-
- if (!configuration.ignoreWarnings)
- {
- throw new IOException("Please correct the above warnings first.");
- }
- }
-
- // Print out the mapping, if requested.
- if (configuration.printMapping != null)
- {
- PrintStream ps =
- configuration.printMapping == Configuration.STD_OUT ? System.out :
- new PrintStream(
- new BufferedOutputStream(
- new FileOutputStream(configuration.printMapping)));
-
- // Print out items that will be removed.
- programClassPool.classesAcceptAlphabetically(new MappingPrinter(ps));
-
- if (ps == System.out)
- {
- ps.flush();
- }
- else
- {
- ps.close();
- }
- }
-
- // Actually apply the new names.
- programClassPool.classesAccept(new ClassRenamer());
- libraryClassPool.classesAccept(new ClassRenamer());
-
- // Update all references to these new names.
- programClassPool.classesAccept(new ClassReferenceFixer(false));
- libraryClassPool.classesAccept(new ClassReferenceFixer(false));
- programClassPool.classesAccept(new MemberReferenceFixer());
-
- // Make package visible elements public or protected, if obfuscated
- // classes are being repackaged aggressively.
- if (configuration.repackageClasses != null &&
- configuration.allowAccessModification)
- {
- programClassPool.classesAccept(
- new AccessFixer());
-
- // Fix the access flags of the inner classes information.
- programClassPool.classesAccept(
- new AllAttributeVisitor(
- new AllInnerClassesInfoVisitor(
- new InnerClassesAccessFixer())));
- }
-
- // Fix the bridge method flags.
- programClassPool.classesAccept(
- new AllMethodVisitor(
- new BridgeMethodFixer()));
-
- // Rename the source file attributes, if requested.
- if (configuration.newSourceFileAttribute != null)
- {
- programClassPool.classesAccept(new SourceFileRenamer(configuration.newSourceFileAttribute));
- }
-
- // Remove unused constants.
- programClassPool.classesAccept(
- new ConstantPoolShrinker());
- }
-}
diff --git a/src/proguard/obfuscate/ParameterNameMarker.java b/src/proguard/obfuscate/ParameterNameMarker.java
deleted file mode 100644
index fbe8a81..0000000
--- a/src/proguard/obfuscate/ParameterNameMarker.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-
-/**
- * This AttributeVisitor trims and marks all local variable (type) table
- * attributes that it visits. It keeps parameter names and types and removes
- * the ordinary local variable names and types.
- *
- * @author Eric Lafortune
- */
-public class ParameterNameMarker
-extends SimplifiedVisitor
-implements AttributeVisitor
-{
- private final AttributeVisitor attributeUsageMarker;
-
-
- /**
- * Constructs a new ParameterNameMarker.
- * @param attributeUsageMarker the marker that will be used to mark
- * attributes containing local variable info.
- */
- public ParameterNameMarker(AttributeVisitor attributeUsageMarker)
- {
- this.attributeUsageMarker = attributeUsageMarker;
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
- {
- if (!AttributeUsageMarker.isUsed(localVariableTableAttribute) &&
- hasParameters(clazz, method))
- {
- // Shift the entries that start at offset 0 to the front.
- int newIndex = 0;
-
- for (int index = 0; index < localVariableTableAttribute.u2localVariableTableLength; index++)
- {
- LocalVariableInfo localVariableInfo =
- localVariableTableAttribute.localVariableTable[index];
-
- if (localVariableInfo.u2startPC == 0)
- {
- localVariableTableAttribute.localVariableTable[newIndex++] =
- localVariableInfo;
- }
- }
-
- // Trim the table.
- localVariableTableAttribute.u2localVariableTableLength = newIndex;
-
- // Mark the table if there are any entries.
- if (newIndex > 0)
- {
- attributeUsageMarker.visitLocalVariableTableAttribute(clazz, method, codeAttribute, localVariableTableAttribute);
- }
- }
- }
-
-
- public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
- {
- if (!AttributeUsageMarker.isUsed(localVariableTypeTableAttribute) &&
- hasParameters(clazz, method))
- {
- // Shift the entries that start at offset 0 to the front.
- int newIndex = 0;
-
- for (int index = 0; index < localVariableTypeTableAttribute.u2localVariableTypeTableLength; index++)
- {
- LocalVariableTypeInfo localVariableTypeInfo =
- localVariableTypeTableAttribute.localVariableTypeTable[index];
-
- if (localVariableTypeInfo.u2startPC == 0)
- {
- localVariableTypeTableAttribute.localVariableTypeTable[newIndex++] =
- localVariableTypeInfo;
- }
- }
-
- // Trim the table.
- localVariableTypeTableAttribute.u2localVariableTypeTableLength = newIndex;
-
- // Mark the table if there are any entries.
- if (newIndex > 0)
- {
- attributeUsageMarker.visitLocalVariableTypeTableAttribute(clazz, method, codeAttribute, localVariableTypeTableAttribute);
- }
- }
- }
-
-
- // Small utility methods.
-
- private boolean hasParameters(Clazz clazz, Method method)
- {
- return method.getDescriptor(clazz).charAt(1) != ClassConstants.METHOD_ARGUMENTS_CLOSE;
- }
-} \ No newline at end of file
diff --git a/src/proguard/obfuscate/SimpleNameFactory.java b/src/proguard/obfuscate/SimpleNameFactory.java
deleted file mode 100644
index c7e1a50..0000000
--- a/src/proguard/obfuscate/SimpleNameFactory.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import java.util.*;
-
-
-/**
- * This <code>NameFactory</code> generates unique short names, using mixed-case
- * characters or lower-case characters only.
- *
- * @author Eric Lafortune
- */
-public class SimpleNameFactory implements NameFactory
-{
- private static final int CHARACTER_COUNT = 26;
-
- private static final List cachedMixedCaseNames = new ArrayList();
- private static final List cachedLowerCaseNames = new ArrayList();
-
- private final boolean generateMixedCaseNames;
- private int index = 0;
-
-
- /**
- * Creates a new <code>SimpleNameFactory</code> that generates mixed-case names.
- */
- public SimpleNameFactory()
- {
- this(true);
- }
-
-
- /**
- * Creates a new <code>SimpleNameFactory</code>.
- * @param generateMixedCaseNames a flag to indicate whether the generated
- * names will be mixed-case, or lower-case only.
- */
- public SimpleNameFactory(boolean generateMixedCaseNames)
- {
- this.generateMixedCaseNames = generateMixedCaseNames;
- }
-
-
- // Implementations for NameFactory.
-
- public void reset()
- {
- index = 0;
- }
-
-
- public String nextName()
- {
- return name(index++);
- }
-
-
- /**
- * Returns the name at the given index.
- */
- private String name(int index)
- {
- // Which cache do we need?
- List cachedNames = generateMixedCaseNames ?
- cachedMixedCaseNames :
- cachedLowerCaseNames;
-
- // Do we have the name in the cache?
- if (index < cachedNames.size())
- {
- return (String)cachedNames.get(index);
- }
-
- // Create a new name and cache it.
- String name = newName(index);
- cachedNames.add(index, name);
-
- return name;
- }
-
-
- /**
- * Creates and returns the name at the given index.
- */
- private String newName(int index)
- {
- // If we're allowed to generate mixed-case names, we can use twice as
- // many characters.
- int totalCharacterCount = generateMixedCaseNames ?
- 2 * CHARACTER_COUNT :
- CHARACTER_COUNT;
-
- int baseIndex = index / totalCharacterCount;
- int offset = index % totalCharacterCount;
-
- char newChar = charAt(offset);
-
- String newName = baseIndex == 0 ?
- new String(new char[] { newChar }) :
- (name(baseIndex-1) + newChar);
-
- return newName;
- }
-
-
- /**
- * Returns the character with the given index, between 0 and the number of
- * acceptable characters.
- */
- private char charAt(int index)
- {
- return (char)((index < CHARACTER_COUNT ? 'a' - 0 :
- 'A' - CHARACTER_COUNT) + index);
- }
-
-
- public static void main(String[] args)
- {
- System.out.println("Some mixed-case names:");
- printNameSamples(new SimpleNameFactory(true), 60);
- System.out.println("Some lower-case names:");
- printNameSamples(new SimpleNameFactory(false), 60);
- System.out.println("Some more mixed-case names:");
- printNameSamples(new SimpleNameFactory(true), 80);
- System.out.println("Some more lower-case names:");
- printNameSamples(new SimpleNameFactory(false), 80);
- }
-
-
- private static void printNameSamples(SimpleNameFactory factory, int count)
- {
- for (int counter = 0; counter < count; counter++)
- {
- System.out.println(" ["+factory.nextName()+"]");
- }
- }
-}
diff --git a/src/proguard/obfuscate/SourceFileRenamer.java b/src/proguard/obfuscate/SourceFileRenamer.java
deleted file mode 100644
index 57ab009..0000000
--- a/src/proguard/obfuscate/SourceFileRenamer.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.editor.ConstantPoolEditor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.ClassVisitor;
-
-/**
- * This ClassVisitor changes the name stored in the source file attributes
- * and source dir attributes of the classes that it visits, if the
- * attributes are present.
- *
- * @author Eric Lafortune
- */
-public class SourceFileRenamer
-extends SimplifiedVisitor
-implements ClassVisitor,
- AttributeVisitor
-{
- private final String newSourceFileAttribute;
-
-
- /**
- * Creates a new SourceFileRenamer.
- * @param newSourceFileAttribute the new string to be put in the source file
- * attributes.
- */
- public SourceFileRenamer(String newSourceFileAttribute)
- {
- this.newSourceFileAttribute = newSourceFileAttribute;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Only visit the class attributes.
- programClass.attributesAccept(this);
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute)
- {
- // Fix the source file attribute.
- sourceFileAttribute.u2sourceFileIndex =
- new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSourceFileAttribute);
- }
-
-
- public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute)
- {
- // Fix the source file attribute.
- sourceDirAttribute.u2sourceDirIndex =
- new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSourceFileAttribute);
- }
-}
diff --git a/src/proguard/obfuscate/SpecialNameFactory.java b/src/proguard/obfuscate/SpecialNameFactory.java
deleted file mode 100644
index 84bb55f..0000000
--- a/src/proguard/obfuscate/SpecialNameFactory.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.obfuscate;
-
-/**
- * This <code>NameFactory</code> generates names that are special, by appending
- * a suffix.
- *
- * @author Eric Lafortune
- */
-public class SpecialNameFactory implements NameFactory
-{
- private static final char SPECIAL_SUFFIX = '_';
-
-
- private final NameFactory nameFactory;
-
-
- /**
- * Creates a new <code>SpecialNameFactory</code>.
- * @param nameFactory the name factory from which original names will be
- * retrieved.
- */
- public SpecialNameFactory(NameFactory nameFactory)
- {
- this.nameFactory = nameFactory;
- }
-
-
- // Implementations for NameFactory.
-
- public void reset()
- {
- nameFactory.reset();
- }
-
-
- public String nextName()
- {
- return nameFactory.nextName() + SPECIAL_SUFFIX;
- }
-
-
- // Small utility methods.
-
- /**
- * Returns whether the given name is special.
- */
- static boolean isSpecialName(String name)
- {
- return name != null &&
- name.charAt(name.length()-1) == SPECIAL_SUFFIX;
- }
-
-
- public static void main(String[] args)
- {
- SpecialNameFactory factory = new SpecialNameFactory(new SimpleNameFactory());
-
- for (int counter = 0; counter < 50; counter++)
- {
- System.out.println("["+factory.nextName()+"]");
- }
- }
-}
diff --git a/src/proguard/obfuscate/package.html b/src/proguard/obfuscate/package.html
deleted file mode 100644
index a82d266..0000000
--- a/src/proguard/obfuscate/package.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<body>
-This package contains classes to perform obfuscation of class files.
-</body>