1

I'm studying binary file structure of JVM classfile. My current toolbox consists of $ xxd <classfile> and $ javap -v <classfile>. Sample outputs of these two tools are as follows:

$ xxd com/example/mycode/MyTest.class

00000000: cafe babe 0000 003d 001d 0a00 0200 0307  .......=........
00000010: 0004 0c00 0500 0601 0010 6a61 7661 2f6c  ..........java/l
00000020: 616e 672f 4f62 6a65 6374 0100 063c 696e  ang/Object...<in
00000030: 6974 3e01 0003 2829 5609 0008 0009 0700  it>...()V.......
...
000001a0: 0000 000a 0002 0000 0005 0008 0006 0001  ................
000001b0: 001b 0000 0002 001c                      ........

and

$ javap.exe -v com/example/mycode/MyTest.class

Classfile /<PathTo>/MyTest.class
  Last modified 2022/11/01; size 440 bytes
...
  interfaces: 0, fields: 0, methods: 2, attributes: 1
Constant pool:
   #1 = Methodref          #2.#3          // java/lang/Object."<init>":()V
   #2 = Class              #4             // java/lang/Object
   #3 = NameAndType        #5:#6          // "<init>":()V
   #4 = Utf8               java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
...
  #27 = Utf8               SourceFile
  #28 = Utf8               MyTest.java
{
  public com.example.mycode.MyTest();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 3: 0

  public static void main(java.lang.String[]);
...
}
SourceFile: "MyTest.java"

But, from these two outputs, it is difficult to comprehend which part of one output correspond which part of the other. It is hard to analyze the hex dumped binary by comparing with the disassembled output.

In this particular case I could manually assign tags by referring specification, but it was hard work even if the sample file is a trivial hello world. In general large files such method is hard to be done.

Edit: made the question prorer

So what I want to do is the following:

  1. Syntax highlight the xxd dump output along classfile structure so that easily view which part is, for example, the constant pool part, or the method info and attributes, in order to easily compare with javap output.

  2. More aggressively, it is useful to view javap and xxd outputs side by side, and selecting a text on one side results in highlighting corresponding text on the other side.

So, my question:

  • Is there any way or any other tools to understand xxd hex dump output in terms of javap decompiled output? Especially I'd like to comprehend that each hex corresponds to each decompiled entry one-to-one.
  • My current idea is to highlight colors on hex dump, possibly like the following image. Is there any software to do like this?

Maybe I need to do some coding, something like writing parser of .class-file. Then, which is the efficient way to do it in less effort to obtain highlighted hex dump with format tag annotations according to the .class-file specs, like shown in the image below?

Thank you for reading.

Sketch of Syntax Highlighting of Hex Dump (xxd)

4
  • 1
    You didn’t ask a question.
    – Holger
    Commented Nov 2, 2022 at 8:28
  • @Holger, thank you for advise. The article is editted.
    – Takashi
    Commented Nov 2, 2022 at 12:07
  • 1
    1. Don’t ask two fundamentally questions at once. 2. Don’t ask for software, that’s off-topic on this site (the answer is “no” anyway). 3. Don’t focus on hex dumps or javap output. Your actual input is a class file and its format is easier to parse than the text output of the other tools. Creating a hex dump as result, together with highlighting, is simpler than injecting highlighting into an existing hex dump.
    – Holger
    Commented Nov 2, 2022 at 13:36
  • 1. 2. I'm afraid I could fixed this time... 3. Directly treat .class-file is an insight for me. Editted to be consistent with the article title.
    – Takashi
    Commented Nov 3, 2022 at 7:23

0