欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java 类文件(.class)结构查看器,java.class,源码项目(JavaCla

来源: javaer 分享于  点击 27909 次 点评:227

Java 类文件(.class)结构查看器,java.class,源码项目(JavaCla


源码项目(JavaClassViewer.src.zip)请使用NetBeans6.5 或者更新版本打开。

工具屏幕截图

imgs/asCode/08221854_Urqk.png

[Java]代码

// ArticleCodeDemo.src.zip - org.freeinternals.demo.jCFL_CodeDemo.printClassFile() // Minor & Major versionMinorVersion minorVersion = classfile.getMinorVersion();System.out.println("Class File Minor Version: " + minorVersion.getValue()); MajorVersion majorVersion = classfile.getMajorVersion();System.out.println("Class File Major Version: " + majorVersion.getValue()); // Constant PoolCPCount cpCount = classfile.getCPCount();System.out.println("Constant Pool size: " + cpCount.getValue()); AbstractCPInfo[] cpArray = classfile.getConstantPool();for (int i = 1; i < cpCount.getValue(); i++) {    System.out.println(            String.format("Constant Pool [%d]: %s", i, classfile.getCPDescription(i)));    short tag = cpArray[i].getTag();    if ((tag == AbstractCPInfo.CONSTANT_Double) ||             (tag == AbstractCPInfo.CONSTANT_Long)) {        i++;    }} // Access flag, this & super classAccessFlags accessFlags = classfile.getAccessFlags();System.out.println("Class Modifier: " + accessFlags.getModifiers()); ThisClass thisClass = classfile.getThisClass();System.out.println("This Class Name Index: " + thisClass.getValue());System.out.println("This Class Name: " +     classfile.getCPDescription(thisClass.getValue())); SuperClass superClass = classfile.getSuperClass();System.out.println("Super Class Name Index: " + superClass.getValue());if (superClass.getValue() == 0) {    System.out.println("Super Class Name: java.lang.Object");} else {    System.out.println("Super Class Name: " +         classfile.getCPDescription(superClass.getValue()));} // InterfacesInterfaceCount interfactCount = classfile.getInterfacesCount();System.out.println("Interface Count: " + interfactCount.getValue()); if (interfactCount.getValue() > 0) {    Interface[] interfaceArray = classfile.getInterfaces();    for (int i = 0; i < interfaceArray.length; i++) {        System.out.println(                String.format("Interface [%d] Name Index: %d", i,                 interfaceArray[i].getValue()));        System.out.println(                String.format("Interface [%d] Name: %s", i,         classfile.getCPDescription(interfaceArray[i].getValue())));    }} // FieldsFieldCount fieldCount = classfile.getFieldCount();System.out.println("Field count: " + fieldCount.getValue()); if (fieldCount.getValue() > 0) {    FieldInfo[] fieldArray = classfile.getFields();    for (int i = 0; i < fieldArray.length; i++) {        System.out.println(String.format("Field [%d]: %s", i,                 fieldArray[i].getDeclaration()));    }} // MethodsMethodCount methodCount = classfile.getMethodCount();System.out.println("Method count: " + methodCount.getValue()); if (methodCount.getValue() > 0) {    MethodInfo[] methodArray = classfile.getMethods();    for (int i = 0; i < methodArray.length; i++) {        System.out.println(String.format("Method [%d]: %s", i,                 methodArray[i].getDeclaration()));    }} // AttributesAttributeCount attributeCount = classfile.getAttributeCount();System.out.println("Attribute count: " + attributeCount.getValue()); AttributeInfo[] attributeArray = classfile.getAttributes();for (int i = 0; i < attributeArray.length; i++) {    System.out.println(String.format("Attribute [%d]: %s", i,                 attributeArray[i].getName()));}
相关栏目:

用户点评