2

I read about Java ClassFile and I have tried to understand every byte in it. Basically everything is clear besides one thing... Just after the method definition (Code attribute) there is SourceFile attribute. But before that there is additional byte.

Hello.java


public class Hello {    
}

Hello.class

CA FE BA BE 00 00 00 34 00 0D 0A 00 03 00 0A 07 00 0B 07
00 0C 01 00 06 3C 69 6E 69 74 3E 01 00 03 28 29 56 01 00 
04 43 6F 64 65 01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 54 
61 62 6C 65 01 00 0A 53 6F 75 72 63 65 46 69 6C 65 01 00 
0A 48 65 6C 6C 6F 2E 6A 61 76 61 0C 00 04 00 05 01 00 05 
48 65 6C 6C 6F 01 00 10 6A 61 76 61 2F 6C 61 6E 67 2F 4F 
62 6A 65 63 74 00 21 00 02 00 03 00 00 00 00 00 01 00 01 
00 04 00 05 00 01 00 06 00 00 00 1D 00 01 00 01 00 00 00 
05 2A B7 00 01 B1 00 00 00 01 00 07 00 00 00 06 00 01 00 
00 00 01 00 01 00 08 00 00 00 02 00 09 

We are interested in following bytes: (These are last ones)

Code attribute        06 00 00 00 1D 00 01 00 01 00 00 00 05 2A B7 00 01 B1 00
                      00 00 01 00 07 00 00 00 06 00 01 00 00 00 01

What are these?       00 01 
SourceFile attribute  00 08 00 00 00 02 00 09

I analyzed data of Code attribute according to Code Attribute doc

  • 1
    The previous comment is right, look at en.wikipedia.org/wiki/Java_class_file, it is the attribute count. – mwarren Jun 7 at 10:26
2

It should be attributes_count.

The value of the attributes_count item indicates the number of attributes of the Code attribute.

Sources:

https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 https://en.wikipedia.org/wiki/Java_class_file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.