00001 import de.fub.bytecode.*; 00002 import de.fub.bytecode.classfile.*; 00003 00004 public class Declass { 00005 private static boolean code = false; 00006 private static String method = null; 00007 00008 private static class Printer extends EmptyVisitor { 00009 public void visitMethod(Method m) { 00010 if(method != null && !method.equals(m.getName() + m.getSignature())) 00011 return; 00012 00013 if(m.isNative()) System.out.print("native "); 00014 System.out.println(m.getName() + m.getSignature()); 00015 if(code) { 00016 Code c = m.getCode(); 00017 if(c != null) 00018 System.out.println(Utility.codeToString(c.getCode(), c.getConstantPool(), 0, -1, false)); 00019 System.out.println(); 00020 } 00021 } 00022 } 00023 00024 public static void DeclassFile(String name) { 00025 try { 00026 JavaClass jc; 00027 00028 if((jc = Repository.lookupClass(name)) == null) 00029 jc = new ClassParser(name).parse(); 00030 00031 new DefaultVisitor(jc, new Printer()).visit(); 00032 } catch(java.io.IOException e) { 00033 e.printStackTrace(); 00034 System.exit(1); 00035 } 00036 } 00037 public static void main(String[] args) { 00038 int argc = args.length; 00039 00040 if(argc == 0) { 00041 System.err.println("usage:"); 00042 System.err.println("\tjava Declass [-code|-nocode] [-method <name>] <classname> {<classname> ...}"); 00043 System.err.println(); 00044 return; 00045 } 00046 00047 for(int i = 0; i < argc; i++) 00048 if(args[i].startsWith("-")) { 00049 if(args[i].equals("-code")) 00050 code = true; 00051 else if(args[i].equals("-no-code")) 00052 code = false; 00053 else if(args[i].equals("-method")) 00054 method = args[++i]; 00055 else { 00056 System.err.println("invalid option -- " + args[i]); 00057 System.exit(1); 00058 } 00059 } else 00060 DeclassFile(args[i]); 00061 } 00062 }