⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configurationparser.java

📁 j2me 混淆包,用于混淆j2me的原代码用的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* $Id: ConfigurationParser.java,v 1.19 2004/12/18 20:22:13 eric Exp $ * * ProGuard -- shrinking, optimization, and obfuscation of Java class files. * * Copyright (c) 2002-2004 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;import proguard.classfile.*;import proguard.classfile.util.*;import proguard.util.*;import java.io.*;import java.net.URL;import java.util.*;/** * This class parses ProGuard configurations. Configurations can be read from an * array of arguments or from a configuration file or URL. * * @author Eric Lafortune */public class ConfigurationParser{    private WordReader reader;    private String     nextWord;    private String     lastComments;    /**     * Creates a new ConfigurationParser for the given String arguments.     */    public ConfigurationParser(String[] args) throws IOException    {        reader = new ArgumentWordReader(args);        readNextWord();    }    /**     * Creates a new ConfigurationParser for the given file name.     */    public ConfigurationParser(String fileName) throws IOException    {        reader = new FileWordReader(fileName);        readNextWord();    }    /**     * Creates a new ConfigurationParser for the given URL.     */    public ConfigurationParser(URL url) throws IOException    {        reader = new FileWordReader(url);        readNextWord();    }    /**     * Parses and returns the configuration.     * @param configuration the configuration that is updated as a side-effect.     * @throws ParseException if the any of the configuration settings contains     *                        a syntax error.     * @throws IOException if an IO error occurs while reading a configuration.     */    public void parse(Configuration configuration) throws ParseException, IOException    {        while (nextWord != null)        {            lastComments = reader.lastComments();            // First include directives.            if      (ConfigurationConstants.AT_DIRECTIVE                                     .startsWith(nextWord) ||                     ConfigurationConstants.INCLUDE_DIRECTIVE                                .startsWith(nextWord)) parseIncludeArgument();            // Then configuration options with or without arguments.            else if (ConfigurationConstants.INJARS_OPTION                                    .startsWith(nextWord)) configuration.programJars                      = parseClassPathArgument(configuration.programJars, false);            else if (ConfigurationConstants.OUTJARS_OPTION                                   .startsWith(nextWord)) configuration.programJars                      = parseClassPathArgument(configuration.programJars, true);            else if (ConfigurationConstants.LIBRARYJARS_OPTION                               .startsWith(nextWord)) configuration.libraryJars                      = parseClassPathArgument(configuration.libraryJars, false);            else if (ConfigurationConstants.RESOURCEJARS_OPTION                              .startsWith(nextWord)) throw new ParseException("The '-resourcejars' option is no longer supported. Please use the '-injars' option for all input");            else if (ConfigurationConstants.DONT_SKIP_NON_PUBLIC_LIBRARY_CLASSES_OPTION      .startsWith(nextWord)) configuration.skipNonPublicLibraryClasses      = parseNoArgument(false);            else if (ConfigurationConstants.DONT_SKIP_NON_PUBLIC_LIBRARY_CLASS_MEMBERS_OPTION.startsWith(nextWord)) configuration.skipNonPublicLibraryClassMembers = parseNoArgument(false);            else if (ConfigurationConstants.KEEP_OPTION                                      .startsWith(nextWord)) configuration.keep                             = parseClassSpecificationArguments(configuration.keep, true,  false);            else if (ConfigurationConstants.KEEP_CLASS_MEMBERS_OPTION                        .startsWith(nextWord)) configuration.keep                             = parseClassSpecificationArguments(configuration.keep, false, false);            else if (ConfigurationConstants.KEEP_CLASSES_WITH_MEMBERS_OPTION                 .startsWith(nextWord)) configuration.keep                             = parseClassSpecificationArguments(configuration.keep, false, true);            else if (ConfigurationConstants.KEEP_NAMES_OPTION                                .startsWith(nextWord)) configuration.keepNames                        = parseClassSpecificationArguments(configuration.keepNames, true,  false);            else if (ConfigurationConstants.KEEP_CLASS_MEMBER_NAMES_OPTION                   .startsWith(nextWord)) configuration.keepNames                        = parseClassSpecificationArguments(configuration.keepNames, false, false);            else if (ConfigurationConstants.KEEP_CLASSES_WITH_MEMBER_NAMES_OPTION            .startsWith(nextWord)) configuration.keepNames                        = parseClassSpecificationArguments(configuration.keepNames, false, true);            else if (ConfigurationConstants.PRINT_SEEDS_OPTION                               .startsWith(nextWord)) configuration.printSeeds                       = parseOptionalArgument();            else if (ConfigurationConstants.DONT_SHRINK_OPTION                               .startsWith(nextWord)) configuration.shrink                           = parseNoArgument(false);            else if (ConfigurationConstants.PRINT_USAGE_OPTION                               .startsWith(nextWord)) configuration.printUsage                       = parseOptionalArgument();            else if (ConfigurationConstants.DONT_OPTIMIZE_OPTION                             .startsWith(nextWord)) configuration.optimize                         = parseNoArgument(false);            else if (ConfigurationConstants.ASSUME_NO_SIDE_EFFECTS_OPTION                    .startsWith(nextWord)) configuration.assumeNoSideEffects              = parseClassSpecificationArguments(configuration.assumeNoSideEffects, false, false);            else if (ConfigurationConstants.ALLOW_ACCESS_MODIFICATION_OPTION                 .startsWith(nextWord)) configuration.allowAccessModification          = parseNoArgument(true);            else if (ConfigurationConstants.DONT_OBFUSCATE_OPTION                            .startsWith(nextWord)) configuration.obfuscate                        = parseNoArgument(false);            else if (ConfigurationConstants.PRINT_MAPPING_OPTION                             .startsWith(nextWord)) configuration.printMapping                     = parseOptionalArgument();            else if (ConfigurationConstants.APPLY_MAPPING_OPTION                             .startsWith(nextWord)) configuration.applyMapping                     = parseOptionalArgument();            else if (ConfigurationConstants.OBFUSCATION_DICTIONARY_OPTION                    .startsWith(nextWord)) configuration.obfuscationDictionary            = parseObfuscationDictionaryArgument();            else if (ConfigurationConstants.OVERLOAD_AGGRESSIVELY_OPTION                     .startsWith(nextWord)) configuration.overloadAggressively             = parseNoArgument(true);            else if (ConfigurationConstants.DEFAULT_PACKAGE_OPTION                           .startsWith(nextWord)) configuration.defaultPackage                   = ClassUtil.internalClassName(parseOptionalArgument());            else if (ConfigurationConstants.DONT_USE_MIXED_CASE_CLASS_NAMES_OPTION           .startsWith(nextWord)) configuration.useMixedCaseClassNames           = parseNoArgument(false);            else if (ConfigurationConstants.KEEP_ATTRIBUTES_OPTION                           .startsWith(nextWord)) configuration.keepAttributes                   = parseKeepAttributesArguments(configuration.keepAttributes);            else if (ConfigurationConstants.RENAME_SOURCE_FILE_ATTRIBUTE_OPTION              .startsWith(nextWord)) configuration.newSourceFileAttribute           = parseOptionalArgument();            else if (ConfigurationConstants.VERBOSE_OPTION                                   .startsWith(nextWord)) configuration.verbose                          = parseNoArgument(true);            else if (ConfigurationConstants.DONT_NOTE_OPTION                                 .startsWith(nextWord)) configuration.note                             = parseNoArgument(false);            else if (ConfigurationConstants.DONT_WARN_OPTION                                 .startsWith(nextWord)) configuration.warn                             = parseNoArgument(false);            else if (ConfigurationConstants.IGNORE_WARNINGS_OPTION                           .startsWith(nextWord)) configuration.ignoreWarnings                   = parseNoArgument(true);            else if (ConfigurationConstants.DUMP_OPTION                                      .startsWith(nextWord)) configuration.dump                             = parseOptionalArgument();            else            {                throw new ParseException("Unknown configuration " + reader.locationDescription());            }        }    }    private void parseIncludeArgument()    throws ParseException, IOException    {        // Read the configuation file name.        readNextWord("configuration file name");        reader.includeWordReader(new FileWordReader(replaceSystemProperties(nextWord)));        readNextWord();    }    private ClassPath parseClassPathArgument(ClassPath classPath,                                             boolean   isOutput)    throws ParseException, IOException    {        // Create a new List if necessary.        if (classPath == null)        {            classPath = new ClassPath();        }        while (true)        {            // Read the next jar name.            readNextWord("jar or directory name");            // Create a new class path entry.            ClassPathEntry entry = new ClassPathEntry(replaceSystemProperties(nextWord),                                                      isOutput);            // Read the opening parenthesis or the separator, if any.            readNextWord();            // Read the optional filters.            if (!configurationEnd() &&                ConfigurationConstants.OPEN_ARGUMENTS_KEYWORD.equals(nextWord))            {                // Read all filters in an array.                String[] filters = new String[5];                int counter = 0;                do                {                    // Read the filter.                    filters[counter++] = ListUtil.commaSeparatedString(parseCommaSeparatedList(false, true));                }                while (counter < filters.length &&                       ConfigurationConstants.SEPARATOR_KEYWORD.equals(nextWord));                // Make sure there is a closing parenthesis.                if (!ConfigurationConstants.CLOSE_ARGUMENTS_KEYWORD.equals(nextWord))                {                    throw new ParseException("Expecting separating '" + ConfigurationConstants.ARGUMENT_SEPARATOR_KEYWORD +                                             "' or '" + ConfigurationConstants.SEPARATOR_KEYWORD +                                             "', or closing '" + ConfigurationConstants.CLOSE_ARGUMENTS_KEYWORD +                                             "' before " + reader.locationDescription());                }                // Set all filters from the array on the entry.                entry.setFilter(filters[--counter]);                if (counter > 0)                {                    entry.setJarFilter(filters[--counter]);                    if (counter > 0)                    {                        entry.setWarFilter(filters[--counter]);                        if (counter > 0)                        {                            entry.setEarFilter(filters[--counter]);                            if (counter > 0)                            {                                entry.setZipFilter(filters[--counter]);                            }                        }                    }                }                // Read the separator, if any.                readNextWord();            }            // Add the entry to the list.            classPath.add(entry);            if (configurationEnd())            {                return classPath;            }            if (!nextWord.equals(ConfigurationConstants.JAR_SEPARATOR_KEYWORD))            {                throw new ParseException("Expecting class path separator '" + ConfigurationConstants.JAR_SEPARATOR_KEYWORD +                                         "' before " + reader.locationDescription());            }        }    }    private List parseKeepAttributesArguments(List keepAttributes)    throws ParseException, IOException    {        // Create a new List if necessary.        if (keepAttributes == null)        {            keepAttributes = new ArrayList();        }        // Read the first attribute name.        readNextWord();        // Should we keep all attributes?        if (configurationEnd())        {            keepAttributes.clear();            return keepAttributes;        }        if (nextWord.equals(ConfigurationConstants.ANY_ATTRIBUTE_KEYWORD))        {            keepAttributes.clear();            readNextWord();            return keepAttributes;        }        while (true)        {            // Add the attribute name to the list.            keepAttributes.add(nextWord);            // Read the separator, if any.            readNextWord();            if (configurationEnd())            {                break;            }            if (!nextWord.equals(ConfigurationConstants.ATTRIBUTE_SEPARATOR_KEYWORD))            {                throw new ParseException("Expecting attribute name separator '" + ConfigurationConstants.ATTRIBUTE_SEPARATOR_KEYWORD +                                         "' before " + reader.locationDescription());            }            // Read the next attribute name.            readNextWord("attribute name");        }        return keepAttributes;    }    private String parseObfuscationDictionaryArgument()    throws ParseException, IOException    {        // Read the obfsucation dictionary name.        readNextWord("obfuscation dictionary name");        String obfuscationDictionary = replaceSystemProperties(nextWord);        readNextWord();        return obfuscationDictionary;    }    private String parseOptionalArgument()    throws IOException    {        readNextWord();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -