001: /* ===========================================================================
002: * $RCSfile: LocalVariableInfo.java,v $
003: * ===========================================================================
004: *
005: * RetroGuard -- an obfuscation package for Java classfiles.
006: *
007: * Copyright (c) 1998-2006 Mark Welsh (markw@retrologic.com)
008: *
009: * This program can be redistributed and/or modified under the terms of the
010: * Version 2 of the GNU General Public License as published by the Free
011: * Software Foundation.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: */
019:
020: package COM.rl.obf.classfile;
021:
022: import java.io.*;
023: import java.util.*;
024:
025: /**
026: * Representation of an Local Variable table entry.
027: *
028: * @author Mark Welsh
029: */
030: public class LocalVariableInfo {
031: // Constants -------------------------------------------------------------
032:
033: // Fields ----------------------------------------------------------------
034: private int u2startpc;
035: private int u2length;
036: private int u2nameIndex;
037: private int u2descriptorIndex;
038: private int u2index;
039:
040: // Class Methods ---------------------------------------------------------
041: public static LocalVariableInfo create(DataInput din)
042: throws Exception {
043: LocalVariableInfo lvi = new LocalVariableInfo();
044: lvi.read(din);
045: return lvi;
046: }
047:
048: // Instance Methods ------------------------------------------------------
049: private LocalVariableInfo() {
050: }
051:
052: /** Return name index into Constant Pool. */
053: protected int getNameIndex() {
054: return u2nameIndex;
055: }
056:
057: /** Set the name index. */
058: protected void setNameIndex(int index) {
059: u2nameIndex = index;
060: }
061:
062: /** Return descriptor index into Constant Pool. */
063: protected int getDescriptorIndex() {
064: return u2descriptorIndex;
065: }
066:
067: /** Set the descriptor index. */
068: protected void setDescriptorIndex(int index) {
069: u2descriptorIndex = index;
070: }
071:
072: /** Check for Utf8 references to constant pool and mark them. */
073: protected void markUtf8Refs(ConstantPool pool) throws Exception {
074: pool.incRefCount(u2nameIndex);
075: pool.incRefCount(u2descriptorIndex);
076: }
077:
078: private void read(DataInput din) throws Exception {
079: u2startpc = din.readUnsignedShort();
080: u2length = din.readUnsignedShort();
081: u2nameIndex = din.readUnsignedShort();
082: u2descriptorIndex = din.readUnsignedShort();
083: u2index = din.readUnsignedShort();
084: }
085:
086: /** Export the representation to a DataOutput stream. */
087: public void write(DataOutput dout) throws Exception {
088: dout.writeShort(u2startpc);
089: dout.writeShort(u2length);
090: dout.writeShort(u2nameIndex);
091: dout.writeShort(u2descriptorIndex);
092: dout.writeShort(u2index);
093: }
094:
095: /** Do necessary name remapping. */
096: protected void remap(ClassFile cf, NameMapper nm) throws Exception {
097: String oldDesc = cf.getUtf8(u2descriptorIndex);
098: String newDesc = nm.mapDescriptor(oldDesc);
099: u2descriptorIndex = cf.remapUtf8To(newDesc, u2descriptorIndex);
100: }
101: }
|