001: /* ===========================================================================
002: * $RCSfile: Md.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;
021:
022: import java.io.*;
023: import java.lang.reflect.*;
024: import java.util.*;
025: import COM.rl.util.*;
026: import COM.rl.obf.classfile.*;
027:
028: /**
029: * Tree item representing a method.
030: *
031: * @author Mark Welsh
032: */
033: public class Md extends MdFd {
034: // Constants -------------------------------------------------------------
035:
036: // Fields ----------------------------------------------------------------
037:
038: // Class Methods ---------------------------------------------------------
039:
040: // Instance Methods ------------------------------------------------------
041: /** Ctor. */
042: public Md(TreeItem parent, boolean isSynthetic, String name,
043: String descriptor, int access) throws Exception {
044: super (parent, isSynthetic, name, descriptor, access);
045: }
046:
047: /** Return the display name of the descriptor types. */
048: protected String getDescriptorName() {
049: String[] types = parseTypes();
050: StringBuffer sb = new StringBuffer();
051: sb.append("(");
052: if (types.length > 0) {
053: for (int i = 0; i < types.length - 1; i++) {
054: sb.append(types[i]);
055: if (i < types.length - 2) {
056: sb.append(", ");
057: }
058: }
059: }
060: sb.append(");");
061: return sb.toString();
062: }
063:
064: /** Does this method match the wildcard pattern? (compatibility mode) */
065: public boolean isOldStyleMatch(String namePattern,
066: String descPattern) {
067: return isOldStyleMatch(namePattern)
068: && isMatch(descPattern, getDescriptor());
069: }
070:
071: /** Find and add TreeItem references. */
072: public void findRefs(ClassFile cf, MethodInfo methodInfo)
073: throws Exception {
074: // References from method Code and Exceptions attributes
075: for (Enumeration enm = methodInfo.listCpRefs(); enm
076: .hasMoreElements();) {
077: CpInfo cpInfo = (CpInfo) enm.nextElement();
078: if (cpInfo instanceof ClassCpInfo) {
079: String name = ((ClassCpInfo) cpInfo).getName(cf);
080: if (name.charAt(0) == '[') {
081: // Pull the class ref from an array ref
082: name = name.substring(name.indexOf('L') + 1, name
083: .length() - 1);
084: }
085: addRef(new ClRef(name));
086: } else if (cpInfo instanceof RefCpInfo) {
087: RefCpInfo refCpInfo = (RefCpInfo) cpInfo;
088: if ((cpInfo instanceof MethodrefCpInfo)
089: || (cpInfo instanceof InterfaceMethodrefCpInfo)) {
090: // addRef to method
091: addRef(new MdRef(refCpInfo.getClassName(cf),
092: refCpInfo.getName(cf), refCpInfo
093: .getDescriptor(cf)));
094: } else if (cpInfo instanceof FieldrefCpInfo) {
095: // addRef to field
096: addRef(new FdRef(refCpInfo.getClassName(cf),
097: refCpInfo.getName(cf), refCpInfo
098: .getDescriptor(cf)));
099: }
100: }
101: }
102: }
103: }
|