01: /* ===========================================================================
02: * $RCSfile: LocalVariableTableAttrInfo.java,v $
03: * ===========================================================================
04: *
05: * RetroGuard -- an obfuscation package for Java classfiles.
06: *
07: * Copyright (c) 1998-2006 Mark Welsh (markw@retrologic.com)
08: *
09: * This program can be redistributed and/or modified under the terms of the
10: * Version 2 of the GNU General Public License as published by the Free
11: * Software Foundation.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: */
19:
20: package COM.rl.obf.classfile;
21:
22: import java.io.*;
23: import java.util.*;
24:
25: /**
26: * Representation of an attribute.
27: *
28: * @author Mark Welsh
29: */
30: public class LocalVariableTableAttrInfo extends AttrInfo {
31: // Constants -------------------------------------------------------------
32:
33: // Fields ----------------------------------------------------------------
34: private int u2localVariableTableLength;
35: private LocalVariableInfo[] localVariableTable;
36:
37: // Class Methods ---------------------------------------------------------
38:
39: // Instance Methods ------------------------------------------------------
40: protected LocalVariableTableAttrInfo(ClassFile cf,
41: int attrNameIndex, int attrLength) {
42: super (cf, attrNameIndex, attrLength);
43: }
44:
45: /** Return the String name of the attribute; over-ride this in sub-classes. */
46: protected String getAttrName() throws Exception {
47: return ATTR_LocalVariableTable;
48: }
49:
50: /** Return the array of local variable table entries. */
51: protected LocalVariableInfo[] getLocalVariableTable()
52: throws Exception {
53: return localVariableTable;
54: }
55:
56: /** Check for Utf8 references in the 'info' data to the constant pool and mark them. */
57: protected void markUtf8RefsInInfo(ConstantPool pool)
58: throws Exception {
59: for (int i = 0; i < localVariableTable.length; i++) {
60: localVariableTable[i].markUtf8Refs(pool);
61: }
62: }
63:
64: /** Read the data following the header. */
65: protected void readInfo(DataInput din) throws Exception {
66: u2localVariableTableLength = din.readUnsignedShort();
67: localVariableTable = new LocalVariableInfo[u2localVariableTableLength];
68: for (int i = 0; i < u2localVariableTableLength; i++) {
69: localVariableTable[i] = LocalVariableInfo.create(din);
70: }
71: }
72:
73: /** Export data following the header to a DataOutput stream. */
74: public void writeInfo(DataOutput dout) throws Exception {
75: dout.writeShort(u2localVariableTableLength);
76: for (int i = 0; i < u2localVariableTableLength; i++) {
77: localVariableTable[i].write(dout);
78: }
79: }
80:
81: /** Do necessary name remapping. */
82: protected void remap(ClassFile cf, NameMapper nm) throws Exception {
83: for (int i = 0; i < u2localVariableTableLength; i++) {
84: localVariableTable[i].remap(cf, nm);
85: }
86: }
87: }
|