jtulach@144: /* jtulach@144: * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. jtulach@144: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jtulach@144: * jtulach@144: * This code is free software; you can redistribute it and/or modify it jtulach@144: * under the terms of the GNU General Public License version 2 only, as jtulach@144: * published by the Free Software Foundation. Oracle designates this jtulach@144: * particular file as subject to the "Classpath" exception as provided jtulach@144: * by Oracle in the LICENSE file that accompanied this code. jtulach@144: * jtulach@144: * This code is distributed in the hope that it will be useful, but WITHOUT jtulach@144: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jtulach@144: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jtulach@144: * version 2 for more details (a copy is included in the LICENSE file that jtulach@144: * accompanied this code). jtulach@144: * jtulach@144: * You should have received a copy of the GNU General Public License version jtulach@144: * 2 along with this work; if not, write to the Free Software Foundation, jtulach@144: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jtulach@144: * jtulach@144: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jtulach@144: * or visit www.oracle.com if you need additional information or have any jtulach@144: * questions. jtulach@144: */ jtulach@144: jtulach@144: jtulach@144: package sun.tools.javap; jtulach@144: jtulach@144: import java.util.*; jtulach@144: import java.io.*; jtulach@144: jtulach@144: import static sun.tools.javap.RuntimeConstants.*; jtulach@144: jtulach@144: /** jtulach@144: * Program to print information about class files jtulach@144: * jtulach@144: * @author Sucheta Dambalkar jtulach@144: */ jtulach@144: public class JavapPrinter { jtulach@144: JavapEnvironment env; jtulach@144: ClassData cls; jtulach@144: byte[] code; jtulach@144: String lP= ""; jtulach@144: PrintWriter out; jtulach@144: jtulach@144: public JavapPrinter(InputStream cname, PrintWriter out, JavapEnvironment env){ jtulach@144: this.out = out; jtulach@144: this.cls = new ClassData(cname); jtulach@144: this.env = env; jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Entry point to print class file information. jtulach@144: */ jtulach@144: public void print(){ jtulach@144: printclassHeader(); jtulach@144: printfields(); jtulach@144: printMethods(); jtulach@144: printend(); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print a description of the class (not members). jtulach@144: */ jtulach@144: public void printclassHeader(){ jtulach@144: String srcName=""; jtulach@144: if ((srcName = cls.getSourceName()) != "null") // requires debug info jtulach@144: out.println("Compiled from " + javaclassname(srcName)); jtulach@144: jtulach@144: if(cls.isInterface()) { jtulach@144: // The only useful access modifier of an interface is jtulach@144: // public; interfaces are always marked as abstract and jtulach@144: // cannot be final. jtulach@144: out.print((cls.isPublic()?"public ":"") + jtulach@144: "interface "+ javaclassname(cls.getClassName())); jtulach@144: } jtulach@144: else if(cls.isClass()) { jtulach@144: String []accflags = cls.getAccess(); jtulach@144: printAccess(accflags); jtulach@144: out.print("class "+ javaclassname(cls.getClassName())); jtulach@144: jtulach@144: if(cls.getSuperClassName() != null){ jtulach@144: out.print(" extends " + javaclassname(cls.getSuperClassName())); jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: String []interfacelist = cls.getSuperInterfaces(); jtulach@144: if(interfacelist.length > 0){ jtulach@144: if(cls.isClass()) { jtulach@144: out.print(" implements "); jtulach@144: } jtulach@144: else if(cls.isInterface()){ jtulach@144: out.print(" extends "); jtulach@144: } jtulach@144: jtulach@144: for(int j = 0; j < interfacelist.length; j++){ jtulach@144: out.print(javaclassname(interfacelist[j])); jtulach@144: jtulach@144: if((j+1) < interfacelist.length) { jtulach@144: out.print(","); jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: // Print class attribute information. jtulach@144: if((env.showallAttr) || (env.showVerbose)){ jtulach@144: printClassAttributes(); jtulach@144: } jtulach@144: // Print verbose output. jtulach@144: if(env.showVerbose){ jtulach@144: printverbosecls(); jtulach@144: } jtulach@144: out.println("{"); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print verbose output. jtulach@144: */ jtulach@144: public void printverbosecls(){ jtulach@144: out.println(" minor version: "+cls.getMinor_version()); jtulach@144: out.println(" major version: "+cls.getMajor_version()); jtulach@144: out.println(" Constant pool:"); jtulach@144: printcp(); jtulach@144: env.showallAttr = true; jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print class attribute information. jtulach@144: */ jtulach@144: public void printClassAttributes(){ jtulach@144: out.println(); jtulach@144: AttrData[] clsattrs = cls.getAttributes(); jtulach@144: for(int i = 0; i < clsattrs.length; i++){ jtulach@144: String clsattrname = clsattrs[i].getAttrName(); jtulach@144: if(clsattrname.equals("SourceFile")){ jtulach@144: out.println(" SourceFile: "+ cls.getSourceName()); jtulach@144: }else if(clsattrname.equals("InnerClasses")){ jtulach@144: printInnerClasses(); jtulach@144: }else { jtulach@144: printAttrData(clsattrs[i]); jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print the fields jtulach@144: */ jtulach@144: public void printfields(){ jtulach@144: FieldData[] fields = cls.getFields(); jtulach@144: for(int f = 0; f < fields.length; f++){ jtulach@144: String[] accflags = fields[f].getAccess(); jtulach@144: if(checkAccess(accflags)){ jtulach@144: if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose jtulach@144: || env.showInternalSigs || env.showallAttr)){ jtulach@144: out.print(" "); jtulach@144: } jtulach@144: printAccess(accflags); jtulach@144: out.println(fields[f].getType()+" " +fields[f].getName()+";"); jtulach@144: if (env.showInternalSigs) { jtulach@144: out.println(" Signature: " + (fields[f].getInternalSig())); jtulach@144: } jtulach@144: jtulach@144: // print field attribute information. jtulach@144: if (env.showallAttr){ jtulach@144: printFieldAttributes(fields[f]); jtulach@144: jtulach@144: } jtulach@144: if((env.showDisassembled) || (env.showLineAndLocal)){ jtulach@144: out.println(); jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: jtulach@144: /* print field attribute information. */ jtulach@144: public void printFieldAttributes(FieldData field){ jtulach@144: Vector fieldattrs = field.getAttributes(); jtulach@144: for(int j = 0; j < fieldattrs.size(); j++){ jtulach@144: String fieldattrname = ((AttrData)fieldattrs.elementAt(j)).getAttrName(); jtulach@144: if(fieldattrname.equals("ConstantValue")){ jtulach@144: printConstantValue(field); jtulach@144: }else if (fieldattrname.equals("Deprecated")){ jtulach@144: out.println("Deprecated: "+ field.isDeprecated()); jtulach@144: }else if (fieldattrname.equals("Synthetic")){ jtulach@144: out.println(" Synthetic: "+ field.isSynthetic()); jtulach@144: }else { jtulach@144: printAttrData((AttrData)fieldattrs.elementAt(j)); jtulach@144: } jtulach@144: } jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print the methods jtulach@144: */ jtulach@144: public void printMethods(){ jtulach@144: MethodData[] methods = cls.getMethods(); jtulach@144: for(int m = 0; m < methods.length; m++){ jtulach@144: String[] accflags = methods[m].getAccess(); jtulach@144: if(checkAccess(accflags)){ jtulach@144: if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose jtulach@144: || env.showInternalSigs || env.showallAttr)){ jtulach@144: out.print(" "); jtulach@144: } jtulach@144: printMethodSignature(methods[m], accflags); jtulach@144: printExceptions(methods[m]); jtulach@144: out.println(";"); jtulach@144: jtulach@144: // Print internal signature of method. jtulach@144: if (env.showInternalSigs){ jtulach@144: out.println(" Signature: " + (methods[m].getInternalSig())); jtulach@144: } jtulach@144: jtulach@144: //Print disassembled code. jtulach@144: if(env.showDisassembled && ! env.showallAttr) { jtulach@144: printcodeSequence(methods[m]); jtulach@144: printExceptionTable(methods[m]); jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: // Print line and local variable attribute information. jtulach@144: if (env.showLineAndLocal) { jtulach@144: printLineNumTable(methods[m]); jtulach@144: printLocVarTable(methods[m]); jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: // Print method attribute information. jtulach@144: if (env.showallAttr){ jtulach@144: printMethodAttributes(methods[m]); jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print method signature. jtulach@144: */ jtulach@144: public void printMethodSignature(MethodData method, String[] accflags){ jtulach@144: printAccess(accflags); jtulach@144: jtulach@144: if((method.getName()).equals("")){ jtulach@144: out.print(javaclassname(cls.getClassName())); jtulach@144: out.print(method.getParameters()); jtulach@144: }else if((method.getName()).equals("")){ jtulach@144: out.print("{}"); jtulach@144: }else{ jtulach@144: out.print(method.getReturnType()+" "); jtulach@144: out.print(method.getName()); jtulach@144: out.print(method.getParameters()); jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * print method attribute information. jtulach@144: */ jtulach@144: public void printMethodAttributes(MethodData method){ jtulach@144: Vector methodattrs = method.getAttributes(); jtulach@144: Vector codeattrs = method.getCodeAttributes(); jtulach@144: for(int k = 0; k < methodattrs.size(); k++){ jtulach@144: String methodattrname = ((AttrData)methodattrs.elementAt(k)).getAttrName(); jtulach@144: if(methodattrname.equals("Code")){ jtulach@144: printcodeSequence(method); jtulach@144: printExceptionTable(method); jtulach@144: for(int c = 0; c < codeattrs.size(); c++){ jtulach@144: String codeattrname = ((AttrData)codeattrs.elementAt(c)).getAttrName(); jtulach@144: if(codeattrname.equals("LineNumberTable")){ jtulach@144: printLineNumTable(method); jtulach@144: }else if(codeattrname.equals("LocalVariableTable")){ jtulach@144: printLocVarTable(method); jtulach@144: }else if(codeattrname.equals("StackMapTable")) { jtulach@144: // Java SE JSR 202 stack map tables jtulach@144: printStackMapTable(method); jtulach@144: }else if(codeattrname.equals("StackMap")) { jtulach@144: // Java ME CLDC stack maps jtulach@144: printStackMap(method); jtulach@144: } else { jtulach@144: printAttrData((AttrData)codeattrs.elementAt(c)); jtulach@144: } jtulach@144: } jtulach@144: }else if(methodattrname.equals("Exceptions")){ jtulach@144: out.println(" Exceptions: "); jtulach@144: printExceptions(method); jtulach@144: }else if (methodattrname.equals("Deprecated")){ jtulach@144: out.println(" Deprecated: "+ method.isDeprecated()); jtulach@144: }else if (methodattrname.equals("Synthetic")){ jtulach@144: out.println(" Synthetic: "+ method.isSynthetic()); jtulach@144: }else { jtulach@144: printAttrData((AttrData)methodattrs.elementAt(k)); jtulach@144: } jtulach@144: } jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print exceptions. jtulach@144: */ jtulach@144: public void printExceptions(MethodData method){ jtulach@144: int []exc_index_table = method.get_exc_index_table(); jtulach@144: if (exc_index_table != null) { jtulach@144: if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose jtulach@144: || env.showInternalSigs || env.showallAttr)){ jtulach@144: out.print(" "); jtulach@144: } jtulach@144: out.print(" throws "); jtulach@144: int k; jtulach@144: int l = exc_index_table.length; jtulach@144: jtulach@144: for (k=0; kopc_jsr_w) { jtulach@144: // pseudo opcodes should be printed as bytecodes jtulach@144: out.print("bytecode "+opcode); jtulach@144: return 1; jtulach@144: } jtulach@144: out.print(Tables.opcName(opcode)); jtulach@144: switch (opcode) { jtulach@144: case opc_aload: case opc_astore: jtulach@144: case opc_fload: case opc_fstore: jtulach@144: case opc_iload: case opc_istore: jtulach@144: case opc_lload: case opc_lstore: jtulach@144: case opc_dload: case opc_dstore: jtulach@144: case opc_ret: jtulach@144: out.print("\t"+getUbyte(pc+1)); jtulach@144: return 2; jtulach@144: case opc_iinc: jtulach@144: out.print("\t"+getUbyte(pc+1)+", "+getbyte(pc+2)); jtulach@144: return 3; jtulach@144: case opc_tableswitch:{ jtulach@144: int tb=align(pc+1); jtulach@144: int default_skip = getInt(tb); /* default skip pamount */ jtulach@144: int low = getInt(tb+4); jtulach@144: int high = getInt(tb+8); jtulach@144: int count = high - low; jtulach@144: out.print("{ //"+low+" to "+high); jtulach@144: for (int i = 0; i <= count; i++) jtulach@144: out.print( "\n\t\t" + (i+low) + ": "+lP+(pc+getInt(tb+12+4*i))+";"); jtulach@144: out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }"); jtulach@144: return tb-pc+16+count*4; jtulach@144: } jtulach@144: jtulach@144: case opc_lookupswitch:{ jtulach@144: int tb=align(pc+1); jtulach@144: int default_skip = getInt(tb); jtulach@144: int npairs = getInt(tb+4); jtulach@144: out.print("{ //"+npairs); jtulach@144: for (int i = 1; i <= npairs; i++) jtulach@144: out.print("\n\t\t"+getInt(tb+i*8) jtulach@144: +": "+lP+(pc+getInt(tb+4+i*8))+";" jtulach@144: ); jtulach@144: out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }"); jtulach@144: return tb-pc+(npairs+1)*8; jtulach@144: } jtulach@144: case opc_newarray: jtulach@144: int type=getUbyte(pc+1); jtulach@144: switch (type) { jtulach@144: case T_BOOLEAN:out.print(" boolean");break; jtulach@144: case T_BYTE: out.print(" byte"); break; jtulach@144: case T_CHAR: out.print(" char"); break; jtulach@144: case T_SHORT: out.print(" short"); break; jtulach@144: case T_INT: out.print(" int"); break; jtulach@144: case T_LONG: out.print(" long"); break; jtulach@144: case T_FLOAT: out.print(" float"); break; jtulach@144: case T_DOUBLE: out.print(" double"); break; jtulach@144: case T_CLASS: out.print(" class"); break; jtulach@144: default: out.print(" BOGUS TYPE:"+type); jtulach@144: } jtulach@144: return 2; jtulach@144: jtulach@144: case opc_anewarray: { jtulach@144: int index = getUShort(pc+1); jtulach@144: out.print("\t#"+index+"; //"); jtulach@144: PrintConstant(index); jtulach@144: return 3; jtulach@144: } jtulach@144: jtulach@144: case opc_sipush: jtulach@144: out.print("\t"+getShort(pc+1)); jtulach@144: return 3; jtulach@144: jtulach@144: case opc_bipush: jtulach@144: out.print("\t"+getbyte(pc+1)); jtulach@144: return 2; jtulach@144: jtulach@144: case opc_ldc: { jtulach@144: int index = getUbyte(pc+1); jtulach@144: out.print("\t#"+index+"; //"); jtulach@144: PrintConstant(index); jtulach@144: return 2; jtulach@144: } jtulach@144: jtulach@144: case opc_ldc_w: case opc_ldc2_w: jtulach@144: case opc_instanceof: case opc_checkcast: jtulach@144: case opc_new: jtulach@144: case opc_putstatic: case opc_getstatic: jtulach@144: case opc_putfield: case opc_getfield: jtulach@144: case opc_invokevirtual: jtulach@144: case opc_invokespecial: jtulach@144: case opc_invokestatic: { jtulach@144: int index = getUShort(pc+1); jtulach@144: out.print("\t#"+index+"; //"); jtulach@144: PrintConstant(index); jtulach@144: return 3; jtulach@144: } jtulach@144: jtulach@144: case opc_invokeinterface: { jtulach@144: int index = getUShort(pc+1), nargs=getUbyte(pc+3); jtulach@144: out.print("\t#"+index+", "+nargs+"; //"); jtulach@144: PrintConstant(index); jtulach@144: return 5; jtulach@144: } jtulach@144: jtulach@144: case opc_multianewarray: { jtulach@144: int index = getUShort(pc+1), dimensions=getUbyte(pc+3); jtulach@144: out.print("\t#"+index+", "+dimensions+"; //"); jtulach@144: PrintConstant(index); jtulach@144: return 4; jtulach@144: } jtulach@144: case opc_jsr: case opc_goto: jtulach@144: case opc_ifeq: case opc_ifge: case opc_ifgt: jtulach@144: case opc_ifle: case opc_iflt: case opc_ifne: jtulach@144: case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpge: jtulach@144: case opc_if_icmpgt: case opc_if_icmple: case opc_if_icmplt: jtulach@144: case opc_if_acmpeq: case opc_if_acmpne: jtulach@144: case opc_ifnull: case opc_ifnonnull: jtulach@144: out.print("\t"+lP+(pc + getShort(pc+1)) ); jtulach@144: return 3; jtulach@144: jtulach@144: case opc_jsr_w: jtulach@144: case opc_goto_w: jtulach@144: out.print("\t"+lP+(pc + getInt(pc+1))); jtulach@144: return 5; jtulach@144: jtulach@144: default: jtulach@144: return 1; jtulach@144: } jtulach@144: } jtulach@144: /** jtulach@144: * Print code attribute details. jtulach@144: */ jtulach@144: public void printVerboseHeader(MethodData method) { jtulach@144: int argCount = method.getArgumentlength(); jtulach@144: if (!method.isStatic()) jtulach@144: ++argCount; // for 'this' jtulach@144: jtulach@144: out.println(" Stack=" + method.getMaxStack() jtulach@144: + ", Locals=" + method.getMaxLocals() jtulach@144: + ", Args_size=" + argCount); jtulach@144: jtulach@144: } jtulach@144: jtulach@144: jtulach@144: /** jtulach@144: * Print the exception table for this method code jtulach@144: */ jtulach@144: void printExceptionTable(MethodData method){//throws IOException jtulach@144: Vector exception_table = method.getexception_table(); jtulach@144: if (exception_table.size() > 0) { jtulach@144: out.println(" Exception table:"); jtulach@144: out.println(" from to target type"); jtulach@144: for (int idx = 0; idx < exception_table.size(); ++idx) { jtulach@144: TrapData handler = (TrapData)exception_table.elementAt(idx); jtulach@144: printFixedWidthInt(handler.start_pc, 6); jtulach@144: printFixedWidthInt(handler.end_pc, 6); jtulach@144: printFixedWidthInt(handler.handler_pc, 6); jtulach@144: out.print(" "); jtulach@144: int catch_cpx = handler.catch_cpx; jtulach@144: if (catch_cpx == 0) { jtulach@144: out.println("any"); jtulach@144: }else { jtulach@144: out.print("Class "); jtulach@144: out.println(cls.getClassName(catch_cpx)); jtulach@144: out.println(""); jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print LineNumberTable attribute information. jtulach@144: */ jtulach@144: public void printLineNumTable(MethodData method) { jtulach@144: int numlines = method.getnumlines(); jtulach@144: Vector lin_num_tb = method.getlin_num_tb(); jtulach@144: if( lin_num_tb.size() > 0){ jtulach@144: out.println(" LineNumberTable: "); jtulach@144: for (int i=0; i 0){ jtulach@144: out.println(" LocalVariableTable: "); jtulach@144: out.print(" "); jtulach@144: out.println("Start Length Slot Name Signature"); jtulach@144: } jtulach@144: Vector loc_var_tb = method.getloc_var_tb(); jtulach@144: jtulach@144: for (int i=0; i 0) { jtulach@144: out.println(" StackMap: number_of_entries = " + number_of_entries); jtulach@144: jtulach@144: for (StackMapData frame : stack_map_tb) { jtulach@144: frame.print(this); jtulach@144: } jtulach@144: } jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print StackMapTable attribute information. jtulach@144: */ jtulach@144: public void printStackMapTable(MethodData method) { jtulach@144: StackMapTableData[] stack_map_tb = method.getStackMapTable(); jtulach@144: int number_of_entries = stack_map_tb.length; jtulach@144: if (number_of_entries > 0) { jtulach@144: out.println(" StackMapTable: number_of_entries = " + number_of_entries); jtulach@144: jtulach@144: for (StackMapTableData frame : stack_map_tb) { jtulach@144: frame.print(this); jtulach@144: } jtulach@144: } jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: void printMap(String name, int[] map) { jtulach@144: out.print(name); jtulach@144: for (int i=0; i> 8; jtulach@144: switch (type) { jtulach@144: case ITEM_Object: jtulach@144: out.print(" "); jtulach@144: PrintConstant(argument); jtulach@144: break; jtulach@144: case ITEM_NewObject: jtulach@144: out.print(" " + Tables.mapTypeName(type)); jtulach@144: out.print(" " + argument); jtulach@144: break; jtulach@144: default: jtulach@144: out.print(" " + Tables.mapTypeName(type)); jtulach@144: } jtulach@144: out.print( (i==(map.length-1)? ' ' : ',')); jtulach@144: } jtulach@144: out.println("]"); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print ConstantValue attribute information. jtulach@144: */ jtulach@144: public void printConstantValue(FieldData field){ jtulach@144: out.print(" Constant value: "); jtulach@144: int cpx = (field.getConstantValueIndex()); jtulach@144: byte tag=0; jtulach@144: try { jtulach@144: tag=cls.getTag(cpx); jtulach@144: jtulach@144: } catch (IndexOutOfBoundsException e) { jtulach@144: out.print("Error:"); jtulach@144: return; jtulach@144: } jtulach@144: switch (tag) { jtulach@144: case CONSTANT_METHOD: jtulach@144: case CONSTANT_INTERFACEMETHOD: jtulach@144: case CONSTANT_FIELD: { jtulach@144: CPX2 x = (CPX2)(cls.getCpoolEntry(cpx)); jtulach@144: if (x.cpx1 == cls.getthis_cpx()) { jtulach@144: // don't print class part for local references jtulach@144: cpx=x.cpx2; jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx)); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print InnerClass attribute information. jtulach@144: */ jtulach@144: public void printInnerClasses(){//throws ioexception jtulach@144: jtulach@144: InnerClassData[] innerClasses = cls.getInnerClasses(); jtulach@144: if(innerClasses != null){ jtulach@144: if(innerClasses.length > 0){ jtulach@144: out.print(" "); jtulach@144: out.println("InnerClass: "); jtulach@144: for(int i = 0 ; i < innerClasses.length; i++){ jtulach@144: out.print(" "); jtulach@144: //access jtulach@144: String[] accflags = innerClasses[i].getAccess(); jtulach@144: if(checkAccess(accflags)){ jtulach@144: printAccess(accflags); jtulach@144: if (innerClasses[i].inner_name_index!=0) { jtulach@144: out.print("#"+innerClasses[i].inner_name_index+"= "); jtulach@144: } jtulach@144: out.print("#"+innerClasses[i].inner_class_info_index); jtulach@144: if (innerClasses[i].outer_class_info_index!=0) { jtulach@144: out.print(" of #"+innerClasses[i].outer_class_info_index); jtulach@144: } jtulach@144: out.print("; //"); jtulach@144: if (innerClasses[i].inner_name_index!=0) { jtulach@144: out.print(cls.getName(innerClasses[i].inner_name_index)+"="); jtulach@144: } jtulach@144: PrintConstant(innerClasses[i].inner_class_info_index); jtulach@144: if (innerClasses[i].outer_class_info_index!=0) { jtulach@144: out.print(" of "); jtulach@144: PrintConstant(innerClasses[i].outer_class_info_index); jtulach@144: } jtulach@144: out.println(); jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print constant pool information. jtulach@144: */ jtulach@144: public void printcp(){ jtulach@144: int cpx = 1 ; jtulach@144: jtulach@144: while (cpx < cls.getCpoolCount()) { jtulach@144: out.print("const #"+cpx+" = "); jtulach@144: cpx+=PrintlnConstantEntry(cpx); jtulach@144: } jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print constant pool entry information. jtulach@144: */ jtulach@144: public int PrintlnConstantEntry(int cpx) { jtulach@144: int size=1; jtulach@144: byte tag=0; jtulach@144: try { jtulach@144: tag=cls.getTag(cpx); jtulach@144: } catch (IndexOutOfBoundsException e) { jtulach@144: out.println(" "); jtulach@144: return 1; jtulach@144: } jtulach@144: out.print(cls.StringTag(cpx)+"\t"); jtulach@144: Object x=cls.getCpoolEntryobj(cpx); jtulach@144: if (x==null) { jtulach@144: switch (tag) { jtulach@144: case CONSTANT_LONG: jtulach@144: case CONSTANT_DOUBLE: jtulach@144: size=2; jtulach@144: } jtulach@144: out.println("null;"); jtulach@144: return size; jtulach@144: } jtulach@144: String str=cls.StringValue(cpx); jtulach@144: jtulach@144: switch (tag) { jtulach@144: case CONSTANT_CLASS: jtulach@144: case CONSTANT_STRING: jtulach@144: out.println("#"+(((CPX)x).cpx)+";\t// "+str); jtulach@144: break; jtulach@144: case CONSTANT_FIELD: jtulach@144: case CONSTANT_METHOD: jtulach@144: case CONSTANT_INTERFACEMETHOD: jtulach@144: out.println("#"+((CPX2)x).cpx1+".#"+((CPX2)x).cpx2+";\t// "+str); jtulach@144: break; jtulach@144: case CONSTANT_NAMEANDTYPE: jtulach@144: out.println("#"+((CPX2)x).cpx1+":#"+((CPX2)x).cpx2+";// "+str); jtulach@144: break; jtulach@144: case CONSTANT_LONG: jtulach@144: case CONSTANT_DOUBLE: jtulach@144: size=2; jtulach@144: default: jtulach@144: out.println(str+";"); jtulach@144: } jtulach@144: return size; jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Checks access of class, field or method. jtulach@144: */ jtulach@144: public boolean checkAccess(String accflags[]){ jtulach@144: jtulach@144: boolean ispublic = false; jtulach@144: boolean isprotected = false; jtulach@144: boolean isprivate = false; jtulach@144: boolean ispackage = false; jtulach@144: jtulach@144: for(int i= 0; i < accflags.length; i++){ jtulach@144: if(accflags[i].equals("public")) ispublic = true; jtulach@144: else if (accflags[i].equals("protected")) isprotected = true; jtulach@144: else if (accflags[i].equals("private")) isprivate = true; jtulach@144: } jtulach@144: jtulach@144: if(!(ispublic || isprotected || isprivate)) ispackage = true; jtulach@144: jtulach@144: if((env.showAccess == env.PUBLIC) && (isprotected || isprivate || ispackage)) return false; jtulach@144: else if((env.showAccess == env.PROTECTED) && (isprivate || ispackage)) return false; jtulach@144: else if((env.showAccess == env.PACKAGE) && (isprivate)) return false; jtulach@144: else return true; jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Prints access of class, field or method. jtulach@144: */ jtulach@144: public void printAccess(String []accflags){ jtulach@144: for(int j = 0; j < accflags.length; j++){ jtulach@144: out.print(accflags[j]+" "); jtulach@144: } jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print an integer so that it takes 'length' characters in jtulach@144: * the output. Temporary until formatting code is stable. jtulach@144: */ jtulach@144: public void printFixedWidthInt(long x, int length) { jtulach@144: CharArrayWriter baStream = new CharArrayWriter(); jtulach@144: PrintWriter pStream = new PrintWriter(baStream); jtulach@144: pStream.print(x); jtulach@144: String str = baStream.toString(); jtulach@144: for (int cnt = length - str.length(); cnt > 0; --cnt) jtulach@144: out.print(' '); jtulach@144: out.print(str); jtulach@144: } jtulach@144: jtulach@144: protected int getbyte (int pc) { jtulach@144: return code[pc]; jtulach@144: } jtulach@144: jtulach@144: protected int getUbyte (int pc) { jtulach@144: return code[pc]&0xFF; jtulach@144: } jtulach@144: jtulach@144: int getShort (int pc) { jtulach@144: return (code[pc]<<8) | (code[pc+1]&0xFF); jtulach@144: } jtulach@144: jtulach@144: int getUShort (int pc) { jtulach@144: return ((code[pc]<<8) | (code[pc+1]&0xFF))&0xFFFF; jtulach@144: } jtulach@144: jtulach@144: protected int getInt (int pc) { jtulach@144: return (getShort(pc)<<16) | (getShort(pc+2)&0xFFFF); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print constant value at that index. jtulach@144: */ jtulach@144: void PrintConstant(int cpx) { jtulach@144: if (cpx==0) { jtulach@144: out.print("#0"); jtulach@144: return; jtulach@144: } jtulach@144: byte tag=0; jtulach@144: try { jtulach@144: tag=cls.getTag(cpx); jtulach@144: jtulach@144: } catch (IndexOutOfBoundsException e) { jtulach@144: out.print("#"+cpx); jtulach@144: return; jtulach@144: } jtulach@144: switch (tag) { jtulach@144: case CONSTANT_METHOD: jtulach@144: case CONSTANT_INTERFACEMETHOD: jtulach@144: case CONSTANT_FIELD: { jtulach@144: // CPX2 x=(CPX2)(cpool[cpx]); jtulach@144: CPX2 x = (CPX2)(cls.getCpoolEntry(cpx)); jtulach@144: if (x.cpx1 == cls.getthis_cpx()) { jtulach@144: // don't print class part for local references jtulach@144: cpx=x.cpx2; jtulach@144: } jtulach@144: } jtulach@144: } jtulach@144: out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx)); jtulach@144: } jtulach@144: jtulach@144: protected static int align (int n) { jtulach@144: return (n+3) & ~3 ; jtulach@144: } jtulach@144: jtulach@144: public void printend(){ jtulach@144: out.println("}"); jtulach@144: out.println(); jtulach@144: } jtulach@144: jtulach@144: public String javaclassname(String name){ jtulach@144: return name.replace('/','.'); jtulach@144: } jtulach@144: jtulach@144: /** jtulach@144: * Print attribute data in hex. jtulach@144: */ jtulach@144: public void printAttrData(AttrData attr){ jtulach@144: byte []data = attr.getData(); jtulach@144: int i = 0; jtulach@144: int j = 0; jtulach@144: out.print(" "+attr.getAttrName()+": "); jtulach@144: out.println("length = " + cls.toHex(attr.datalen)); jtulach@144: jtulach@144: out.print(" "); jtulach@144: jtulach@144: jtulach@144: while (i < data.length){ jtulach@144: String databytestring = cls.toHex(data[i]); jtulach@144: if(databytestring.equals("0x")) out.print("00"); jtulach@144: else if(databytestring.substring(2).length() == 1){ jtulach@144: out.print("0"+databytestring.substring(2)); jtulach@144: } else{ jtulach@144: out.print(databytestring.substring(2)); jtulach@144: } jtulach@144: jtulach@144: j++; jtulach@144: if(j == 16) { jtulach@144: out.println(); jtulach@144: out.print(" "); jtulach@144: j = 0; jtulach@144: } jtulach@144: else out.print(" "); jtulach@144: i++; jtulach@144: } jtulach@144: out.println(); jtulach@144: } jtulach@144: }