001: /**
002: * YGuard -- an obfuscation library for Java(TM) classfiles.
003: *
004: * Original Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
005: * Modifications Copyright (c) 2002 yWorks GmbH (yguard@yworks.com)
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * The author may be contacted at yguard@yworks.com
022: *
023: * Java and all Java-based marks are trademarks or registered
024: * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
025: */package com.yworks.yguard.obf;
026:
027: import java.io.*;
028: import java.util.*;
029: import java.lang.reflect.Modifier;
030:
031: /**
032: * Representation of RGS script files entry.
033: *
034: * @author Mark Welsh
035: */
036: public class YGuardRule {
037: public static final int PUBLIC = Modifier.PUBLIC;
038: public static final int PROTECTED = Modifier.PROTECTED;
039: public static final int FRIENDLY = 4096;
040: public static final int PRIVATE = Modifier.PRIVATE;
041:
042: public static final int LEVEL_NONE = 0;
043: public static final int LEVEL_PUBLIC = PUBLIC;
044: public static final int LEVEL_PROTECTED = PROTECTED | LEVEL_PUBLIC;
045: public static final int LEVEL_FRIENDLY = FRIENDLY | LEVEL_PROTECTED;
046: public static final int LEVEL_PRIVATE = PRIVATE | LEVEL_FRIENDLY;
047:
048: // Constants -------------------------------------------------------------
049: public static final int TYPE_ATTR = 0;
050: public static final int TYPE_CLASS = 1;
051: public static final int TYPE_FIELD = 2;
052: public static final int TYPE_METHOD = 3;
053: public static final int TYPE_PACKAGE_MAP = 4;
054: public static final int TYPE_CLASS_MAP = 5;
055: public static final int TYPE_FIELD_MAP = 6;
056: public static final int TYPE_METHOD_MAP = 7;
057: public static final int TYPE_SOURCE_ATTRIBUTE_MAP = 8;
058: public static final int TYPE_LINE_NUMBER_MAPPER = 9;
059: public static final int TYPE_ATTR2 = 10;
060: public static final int TYPE_PACKAGE = 11;
061:
062: // Fields ----------------------------------------------------------------
063: public int type;
064: public String name;
065: public String descriptor;
066: public String obfName;
067: public LineNumberTableMapper lineNumberTableMapper;
068: public int retainFields = LEVEL_NONE;
069: public int retainMethods = LEVEL_NONE;
070: public int retainClasses = LEVEL_PRIVATE;
071:
072: // Instance Methods-------------------------------------------------------
073: public YGuardRule(int type, String name) {
074: this .type = type;
075: this .name = name;
076: this .descriptor = null;
077: this .obfName = null;
078: this .lineNumberTableMapper = null;
079: }
080:
081: public YGuardRule(int type, String name, String descriptor) {
082: this .obfName = null;
083: this .type = type;
084: this .name = name;
085: this .descriptor = descriptor;
086: this .lineNumberTableMapper = null;
087: }
088:
089: public YGuardRule(String className,
090: LineNumberTableMapper lineNumberTableMapper) {
091: this .descriptor = null;
092: this .obfName = null;
093: this .name = className;
094: this .type = TYPE_LINE_NUMBER_MAPPER;
095: this .lineNumberTableMapper = lineNumberTableMapper;
096: }
097:
098: public void logProperties(PrintWriter pw) {
099: if (type == TYPE_LINE_NUMBER_MAPPER) {
100: lineNumberTableMapper.logProperties(pw);
101: }
102: }
103:
104: public String toString() {
105: return typeToString(type) + " " + name + " " + descriptor
106: + " fields: " + methodToString(retainFields)
107: + " methods: " + methodToString(retainMethods)
108: + " classes: " + methodToString(retainClasses);
109: }
110:
111: public static String typeToString(int type) {
112: switch (type) {
113: default:
114: return "Unknown type " + type;
115: case TYPE_ATTR:
116: return "ATTRIBUTE";
117: case TYPE_ATTR2:
118: return "ATTRIBUTE PER CLASS";
119: case TYPE_CLASS:
120: return "CLASS";
121: case TYPE_CLASS_MAP:
122: return "CLASS_MAP";
123: case TYPE_FIELD:
124: return "FIELD";
125: case TYPE_FIELD_MAP:
126: return "FIELD_MAP";
127: case TYPE_METHOD:
128: return "METHOD";
129: case TYPE_METHOD_MAP:
130: return "METHOD_MAP";
131: case TYPE_PACKAGE_MAP:
132: return "PACKAGE_MAP";
133: case TYPE_SOURCE_ATTRIBUTE_MAP:
134: return "SOURCE_ATTRIBUTE_MAP";
135: case TYPE_LINE_NUMBER_MAPPER:
136: return "LINE_NUMBER_MAPPER";
137: case TYPE_PACKAGE:
138: return "PACKAGE";
139: }
140: }
141:
142: public static String methodToString(int modifier) {
143: switch (modifier) {
144: default:
145: return "Unknown modifier " + modifier;
146: case LEVEL_NONE:
147: return "LEVEL_NONE";
148: case LEVEL_FRIENDLY:
149: return "LEVEL_FRIENDLY";
150: case LEVEL_PRIVATE:
151: return "LEVEL_PRIVATE";
152: case LEVEL_PROTECTED:
153: return "LEVEL_PROTECTED";
154: case LEVEL_PUBLIC:
155: return "LEVEL_PUBLIC";
156: }
157: }
158: }
|