01: /* ===========================================================================
02: * $RCSfile: MethodInfo.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 a method from a class-file.
27: *
28: * @author Mark Welsh
29: */
30: public class MethodInfo extends ClassItemInfo {
31: // Constants -------------------------------------------------------------
32:
33: // Fields ----------------------------------------------------------------
34:
35: // Class Methods ---------------------------------------------------------
36: /**
37: * Create a new MethodInfo from the file format data in the DataInput stream.
38: *
39: * @throws IOException if class file is corrupt or incomplete
40: */
41: public static MethodInfo create(DataInput din, ClassFile cf)
42: throws Exception {
43: if (din == null)
44: throw new IOException("No input stream was provided.");
45: MethodInfo mi = new MethodInfo(cf);
46: mi.read(din);
47: return mi;
48: }
49:
50: // Instance Methods ------------------------------------------------------
51: protected MethodInfo(ClassFile cf) {
52: super (cf);
53: }
54:
55: /** List the constant pool entries references from this method or field. */
56: public Enumeration listCpRefs() throws Exception {
57: Vector refs = new Vector();
58: for (int i = 0; i < attributes.length; i++) {
59: if (attributes[i].getAttrName().equals(ATTR_Exceptions)) {
60: // List references from method's Exceptions attribute
61: ExceptionsAttrInfo exceptions = (ExceptionsAttrInfo) attributes[i];
62: for (int j = 0; j < exceptions.count(); j++) {
63: refs.addElement(cf.getCpEntry(exceptions
64: .getIndex(j)));
65: }
66: } else if (attributes[i].getAttrName().equals(ATTR_Code)) {
67: // List references from method's Code attribute
68: CodeAttrInfo code = (CodeAttrInfo) attributes[i];
69: code.addCpRefs(refs);
70: }
71: }
72: return refs.elements();
73: }
74: }
|