1 4 package gnu.bytecode; 5 import java.io.InputStream ; 6 import java.io.IOException ; 7 import java.io.FileInputStream ; 8 9 12 13 public class dump extends ClassFileInput 14 { 15 ClassTypeWriter writer; 16 17 public dump (InputStream str) 18 throws IOException , ClassFormatError 19 { 20 super(str); 21 this.ctype = new ClassType(); 22 writer = new ClassTypeWriter (ctype, System.out, 0); 23 if (!readHeader()) 24 throw new ClassFormatError ("invalid magic number"); 25 readConstants(); 26 readClassInfo(); 27 readFields(); 28 readMethods(); 29 readAttributes(ctype); 30 31 writer.printClassInfo(); 32 writer.printFields(); 33 writer.printMethods(); 34 printAttributes (); 35 writer.flush(); 36 } 37 38 public ConstantPool readConstants () throws IOException 39 { 40 ctype.constants = super.readConstants(); 41 if (writer.printConstants) 42 writer.printConstantPool(); 43 return ctype.constants; 44 } 45 46 public Attribute readAttribute (String name, int length, AttrContainer container) 47 throws IOException 48 { 49 return super.readAttribute (name, length, container); 50 } 51 52 public void printAttributes () 53 { 54 AttrContainer attrs = ctype; 55 writer.println(); 56 writer.print("Attributes (count: "); 57 writer.print(Attribute.count(attrs)); 58 writer.println("):"); 59 writer.printAttributes (attrs); 60 } 61 62 67 public static void main (String [] args) 68 { 69 if (args.length == 0) 70 usage(); 71 String filename = args[0]; 72 try 73 { 74 java.io.InputStream inp = new FileInputStream (filename); 75 new dump(inp); 76 } 77 catch (java.io.FileNotFoundException e) 78 { 79 System.err.println("File "+filename+" not found"); 80 System.exit(-1); 81 } 82 catch (java.io.IOException e) 83 { 84 System.err.println(e); 85 System.exit(-1); 86 } 87 } 88 89 public static void usage() 90 { 91 System.err.println("Usage: foo.class"); 92 System.exit(-1); 93 } 94 } 95 96 | Popular Tags |