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.classfile;
026:
027: import java.io.*;
028: import java.util.*;
029: import java.lang.reflect.Modifier;
030:
031: /**
032: * Representation of an Inner Classes table entry.
033: *
034: * @author Mark Welsh
035: */
036: public class InnerClassesInfo {
037: // Constants -------------------------------------------------------------
038:
039: // Fields ----------------------------------------------------------------
040: private int u2innerClassInfoIndex;
041: private int u2outerClassInfoIndex;
042: private int u2innerNameIndex;
043: private int u2innerClassAccessFlags;
044:
045: // Class Methods ---------------------------------------------------------
046: public static InnerClassesInfo create(DataInput din)
047: throws java.io.IOException {
048: InnerClassesInfo ici = new InnerClassesInfo();
049: ici.read(din);
050: return ici;
051: }
052:
053: public int getModifiers() {
054: int mods = 0;
055: if ((u2innerClassAccessFlags & 0x0001) == 0x0001)
056: mods |= Modifier.PUBLIC;
057: if ((u2innerClassAccessFlags & 0x0002) == 0x0002)
058: mods |= Modifier.PRIVATE;
059: if ((u2innerClassAccessFlags & 0x0004) == 0x0004)
060: mods |= Modifier.PROTECTED;
061: if ((u2innerClassAccessFlags & 0x0008) == 0x0008)
062: mods |= Modifier.STATIC;
063: if ((u2innerClassAccessFlags & 0x0010) == 0x0010)
064: mods |= Modifier.FINAL;
065: if ((u2innerClassAccessFlags & 0x0200) == 0x0200)
066: mods |= Modifier.INTERFACE;
067: if ((u2innerClassAccessFlags & 0x0400) == 0x0400)
068: mods |= Modifier.ABSTRACT;
069: return mods;
070: }
071:
072: // Instance Methods ------------------------------------------------------
073: private InnerClassesInfo() {
074: }
075:
076: /** Return the inner class index. */
077: protected int getInnerClassIndex() {
078: return u2innerClassInfoIndex;
079: }
080:
081: /** Return the name index. */
082: protected int getInnerNameIndex() {
083: return u2innerNameIndex;
084: }
085:
086: /** Set the name index. */
087: protected void setInnerNameIndex(int index) {
088: u2innerNameIndex = index;
089: }
090:
091: /** Check for Utf8 references to constant pool and mark them. */
092: protected void markUtf8Refs(ConstantPool pool) {
093: // BUGFIX: a Swing1.1beta3 class has name index of zero - this is valid
094: if (u2innerNameIndex != 0) {
095: pool.incRefCount(u2innerNameIndex);
096: }
097: }
098:
099: private void read(DataInput din) throws java.io.IOException {
100: u2innerClassInfoIndex = din.readUnsignedShort();
101: u2outerClassInfoIndex = din.readUnsignedShort();
102: u2innerNameIndex = din.readUnsignedShort();
103: u2innerClassAccessFlags = din.readUnsignedShort();
104: }
105:
106: /** Export the representation to a DataOutput stream. */
107: public void write(DataOutput dout) throws java.io.IOException {
108: dout.writeShort(u2innerClassInfoIndex);
109: dout.writeShort(u2outerClassInfoIndex);
110: dout.writeShort(u2innerNameIndex);
111: dout.writeShort(u2innerClassAccessFlags);
112: }
113: }
|