Java Code Examples for proguard.classfile.ClassConstants#INTERNAL_PACKAGE_SEPARATOR

The following examples show how to use proguard.classfile.ClassConstants#INTERNAL_PACKAGE_SEPARATOR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FullyQualifiedClassNameChecker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the specified class (if any),
 * printing notes if necessary.
 */
private void checkClassName(String className)
{
    if (className != null                            &&
        !containsWildCards(className)                &&
        programClassPool.getClass(className) == null &&
        libraryClassPool.getClass(className) == null &&
        notePrinter.accepts(className))
    {
        notePrinter.print(className,
                          "Note: the configuration refers to the unknown class '" +
                          ClassUtil.externalClassName(className) + "'");

        String fullyQualifiedClassName =
            "**" + ClassConstants.INTERNAL_PACKAGE_SEPARATOR +
            className.substring(className.lastIndexOf(ClassConstants.INTERNAL_PACKAGE_SEPARATOR)+1);

        ClassNameFilter classNameFilter =
            new ClassNameFilter(fullyQualifiedClassName, this);

        programClassPool.classesAccept(classNameFilter);
        libraryClassPool.classesAccept(classNameFilter);
    }
}
 
Example 2
Source File: ClassObfuscator.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 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.INTERNAL_PACKAGE_SEPARATOR;
    }
    while (packagePrefixMap.containsValue(newPackagePrefix));

    return newPackagePrefix;
}
 
Example 3
Source File: ClassObfuscator.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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.INTERNAL_PACKAGE_SEPARATOR;
    }

    // First append the package separator if necessary.
    if (repackageClasses != null &&
        repackageClasses.length() > 0)
    {
        repackageClasses += ClassConstants.INTERNAL_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());
}
 
Example 4
Source File: JarWriter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public boolean createDirectory(DataEntry dataEntry) throws IOException
{
    //Make sure we can start with a new entry.
    if (!prepareEntry(dataEntry))
    {
        return false;
    }

    // Close the previous ZIP entry, if any.
    closeEntry();

    // Get the directory entry name.
    String name = dataEntry.getName() + ClassConstants.INTERNAL_PACKAGE_SEPARATOR;

    // We have to check if the name is already used, because
    // ZipOutputStream doesn't handle this case properly (it throws
    // an exception which can be caught, but the ZipDataEntry is
    // remembered anyway).
    if (jarEntryNames.add(name))
    {
        // Create a new directory entry.
        currentJarOutputStream.putNextEntry(new ZipEntry(name));
        currentJarOutputStream.closeEntry();
    }

    // Clear the finisher.
    currentFinisher  = null;
    currentDataEntry = null;

    return true;
}
 
Example 5
Source File: ZipDataEntry.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public String getName()
{
    // Get the right separators.
    String name = zipEntry.getName()
        .replace(File.separatorChar, ClassConstants.INTERNAL_PACKAGE_SEPARATOR);

    // Chop the trailing directory slash, if any.
    int length = name.length();
    return length > 0 &&
           name.charAt(length-1) == ClassConstants.INTERNAL_PACKAGE_SEPARATOR ?
               name.substring(0, length -1) :
               name;
}
 
Example 6
Source File: DataEntryRenamer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void read(DataEntry dataEntry) throws IOException
{
    String name = dataEntry.getName();

    // Add a directory separator if necessary.
    if (dataEntry.isDirectory() &&
        name.length() > 0)
    {
        name += ClassConstants.INTERNAL_PACKAGE_SEPARATOR;
    }

    String newName = (String)nameMap.get(name);
    if (newName != null)
    {
        // Remove the directory separator if necessary.
        if (dataEntry.isDirectory() &&
            newName.length() > 0)
        {
            newName = newName.substring(0, newName.length() -  1);
        }

        renamedDataEntryReader.read(new RenamedDataEntry(dataEntry, newName));
    }
    else if (missingDataEntryReader != null)
    {
        missingDataEntryReader.read(dataEntry);
    }
}
 
Example 7
Source File: ClassNameParser.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public StringMatcher parse(String regularExpression)
{
    int           index;
    StringMatcher nextMatcher = new EmptyStringMatcher();

    // Look for wildcards.
    for (index = 0; index < regularExpression.length(); index++)
    {
        // Is there an 'L///;' wildcard?
        if (regularExpression.regionMatches(index, "L///;", 0, 5))
        {
            SettableMatcher settableMatcher = new SettableMatcher();

            // Create a matcher, recursively, for the remainder of the
            // string, optionally preceded by any type.
            nextMatcher =
                new OrMatcher(parse(regularExpression.substring(index + 5)),
                              createAnyTypeMatcher(settableMatcher));

            settableMatcher.setMatcher(nextMatcher);

            break;
        }

        // Is there an 'L***;' wildcard?
        if (regularExpression.regionMatches(index, "L***;", 0, 5))
        {
            // Create a matcher for the wildcard and, recursively, for the
            // remainder of the string.
            nextMatcher =
                createAnyTypeMatcher(parse(regularExpression.substring(index + 5)));
            break;
        }

        // Is there a '**' wildcard?
        if (regularExpression.regionMatches(index, "**", 0, 2))
        {
            // Create a matcher for the wildcard and, recursively, for the
            // remainder of the string.
            nextMatcher =
                new VariableStringMatcher(null,
                                          new char[] { ClassConstants.INTERNAL_TYPE_CLASS_END },
                                          0,
                                          Integer.MAX_VALUE,
                                          parse(regularExpression.substring(index + 2)));
            break;
        }

        // Is there a '*' wildcard?
        else if (regularExpression.charAt(index) == '*')
        {
            // Create a matcher for the wildcard and, recursively, for the
            // remainder of the string.
            nextMatcher =
                new VariableStringMatcher(null,
                                          new char[] { ClassConstants.INTERNAL_TYPE_CLASS_END, ClassConstants.INTERNAL_PACKAGE_SEPARATOR },
                                          0,
                                          Integer.MAX_VALUE,
                                          parse(regularExpression.substring(index + 1)));
            break;
        }

        // Is there a '?' wildcard?
        else if (regularExpression.charAt(index) == '?')
        {
            // Create a matcher for the wildcard and, recursively, for the
            // remainder of the string.
            nextMatcher =
                new VariableStringMatcher(null,
                                          new char[] { ClassConstants.INTERNAL_TYPE_CLASS_END, ClassConstants.INTERNAL_PACKAGE_SEPARATOR },
                                          1,
                                          1,
                                          parse(regularExpression.substring(index + 1)));
            break;
        }

        // Is there a '%' wildcard?
        else if (regularExpression.charAt(index) == '%')
        {
            // Create a matcher for the wildcard and, recursively, for the
            // remainder of the string.
            nextMatcher =
                new VariableStringMatcher(INTERNAL_PRIMITIVE_TYPES,
                                          null,
                                          1,
                                          1,
                                          parse(regularExpression.substring(index + 1)));
            break;
        }
    }

    // Return a matcher for the fixed first part of the regular expression,
    // if any, and the remainder.
    return index != 0 ?
        (StringMatcher)new FixedStringMatcher(regularExpression.substring(0, index), nextMatcher) :
        (StringMatcher)nextMatcher;
}