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:
030: /**
031: * Representation of a 'ref'-type entry in the ConstantPool.
032: *
033: * @author Mark Welsh
034: */
035: abstract public class RefCpInfo extends CpInfo {
036: // Constants -------------------------------------------------------------
037:
038: // Fields ----------------------------------------------------------------
039: private int u2classIndex;
040: private int u2nameAndTypeIndex;
041:
042: // Class Methods ---------------------------------------------------------
043:
044: // Instance Methods ------------------------------------------------------
045: protected RefCpInfo(int tag) {
046: super (tag);
047: }
048:
049: /** Return the class index. */
050: protected int getClassIndex() {
051: return u2classIndex;
052: }
053:
054: /** Return the name-and-type index. */
055: protected int getNameAndTypeIndex() {
056: return u2nameAndTypeIndex;
057: }
058:
059: /** Set the name-and-type index. */
060: protected void setNameAndTypeIndex(int index) {
061: u2nameAndTypeIndex = index;
062: }
063:
064: /** Check for N+T references to constant pool and mark them. */
065: protected void markNTRefs(ConstantPool pool) {
066: pool.incRefCount(u2nameAndTypeIndex);
067: }
068:
069: /** Read the 'info' data following the u1tag byte. */
070: protected void readInfo(DataInput din) throws java.io.IOException {
071: u2classIndex = din.readUnsignedShort();
072: u2nameAndTypeIndex = din.readUnsignedShort();
073: }
074:
075: /** Write the 'info' data following the u1tag byte. */
076: protected void writeInfo(DataOutput dout)
077: throws java.io.IOException {
078: dout.writeShort(u2classIndex);
079: dout.writeShort(u2nameAndTypeIndex);
080: }
081:
082: /** Dump the content of the class file to the specified file (used for debugging). */
083: public void dump(PrintWriter pw, ClassFile cf, int index) {
084: pw.println(" Ref "
085: + Integer.toString(index)
086: + ": "
087: + ((Utf8CpInfo) cf.getCpEntry(((ClassCpInfo) cf
088: .getCpEntry(u2classIndex)).getNameIndex()))
089: .getString()
090: + " "
091: + ((Utf8CpInfo) cf
092: .getCpEntry(((NameAndTypeCpInfo) cf
093: .getCpEntry(u2nameAndTypeIndex))
094: .getNameIndex())).getString()
095: + " "
096: + ((Utf8CpInfo) cf.getCpEntry(((NameAndTypeCpInfo) cf
097: .getCpEntry(u2nameAndTypeIndex))
098: .getDescriptorIndex())).getString());
099: }
100: }
|