[kaffe] Re: Decoding compiled class files

Mark Wielaard mark at klomp.org
Thu May 15 08:13:02 PDT 2003


Hi,

On Tue, 2003-05-13 at 16:24, Tony Wyatt wrote:
>
> I want something that decodes and prints out the entire contents of the
> .class file structure, so that I can see the variables, constants pool, 
> initialisation, operations performed by bytecode, etc, etc. 
> I'm trying to identify and then fix the difference of a single byte 
> between two very simple files.

gcj comes with jcf-dump. I believe jcf-dump -c does precisely what you
want. For example for your eexample (put into a main() method in a class
Test it gives the attached output.

Cheers,

Mark
-------------- next part --------------
Reading .class from ./Test.class.
Magic number: 0xcafebabe, minor_version: 0, major_version: 47.

Constant pool (count: 57):
#1: Class name: 2="Test"
#2: Utf8: "Test"
#3: Class name: 4="java/lang/Object"
#4: Utf8: "java/lang/Object"
#5: Utf8: "main"
#6: Utf8: "([Ljava/lang/String;)V"
#7: Utf8: "Code"
#8: Utf8: "LineNumberTable"
#9: Double QNaN(0), bits = 0x7ff8000000000000
#11: Long 9218869174563700736=0x7ff000abacab0000
#13: NameAndType name: 14=longBitsToDouble, signature: 15=(long)double
#14: Utf8: "longBitsToDouble"
#15: Utf8: "(J)D"
#16: Methodref class: 17=java.lang.Double name_and_type: 13=<longBitsToDouble (long)double>
#17: Class name: 18="java/lang/Double"
#18: Utf8: "java/lang/Double"
#19: Long -9223372036854775808=0x8000000000000000
#21: NameAndType name: 22=out, signature: 23=java.io.PrintStream
#22: Utf8: "out"
#23: Utf8: "Ljava/io/PrintStream;"
#24: Fieldref class: 25=java.lang.System name_and_type: 21=<out java.io.PrintStream>
#25: Class name: 26="java/lang/System"
#26: Utf8: "java/lang/System"
#27: Class name: 28="java/lang/StringBuffer"
#28: Utf8: "java/lang/StringBuffer"
#29: String 30="x ="
#30: Utf8: "x ="
#31: NameAndType name: 32=<init>, signature: 33=(java.lang.String)void
#32: Utf8: "<init>"
#33: Utf8: "(Ljava/lang/String;)V"
#34: Methodref class: 27=java.lang.StringBuffer name_and_type: 31=<<init> (java.lang.String)void>
#35: NameAndType name: 36=append, signature: 37=(double)java.lang.StringBuffer
#36: Utf8: "append"
#37: Utf8: "(D)Ljava/lang/StringBuffer;"
#38: Methodref class: 27=java.lang.StringBuffer name_and_type: 35=<append (double)java.lang.StringBuffer>
#39: NameAndType name: 40=toString, signature: 41=()java.lang.String
#40: Utf8: "toString"
#41: Utf8: "()Ljava/lang/String;"
#42: Methodref class: 27=java.lang.StringBuffer name_and_type: 39=<toString ()java.lang.String>
#43: NameAndType name: 44=println, signature: 33=(java.lang.String)void
#44: Utf8: "println"
#45: Methodref class: 46=java.io.PrintStream name_and_type: 43=<println (java.lang.String)void>
#46: Class name: 47="java/io/PrintStream"
#47: Utf8: "java/io/PrintStream"
#48: String 49="y ="
#49: Utf8: "y ="
#50: String 51="z ="
#51: Utf8: "z ="
#52: Utf8: "()V"
#53: NameAndType name: 32=<init>, signature: 52=()void
#54: Methodref class: 3=java.lang.Object name_and_type: 53=<<init> ()void>
#55: Utf8: "SourceFile"
#56: Utf8: "Test.java"

Access flags: 0x21 public super
This class: 1=Test, super: 3=java.lang.Object
Interfaces (count: 0):

Fields (count: 0):

Methods (count: 2):

Method name:"main" public static Signature: 6=(java.lang.String[])void
Attribute "Code", length:135, max_stack:4, max_locals:7, code_length:87
Attribute "LineNumberTable", length:30, count: 7

Method name:"<init>" public Signature: 52=()void
Attribute "Code", length:33, max_stack:1, max_locals:1, code_length:5
Attribute "LineNumberTable", length:10, count: 2

Attributes (count: 1):
Attribute "SourceFile", length:2, #56="Test.java"


More information about the kaffe mailing list