• 查看JAVA的class二进制文件的方法


    hexdump -C filename可以查看二进制文件。

    比如java的Test.java

    public class Test{
        public static void main(String[] args){
            System.out.println("Hello World!");
        }
    }

    1、hexdump

    javac Test.java之后生成的Test.class,可以使用:

    1.1 hexdump -C Test.class 

    0000000  ca fe ba be 00 00 00 32  00 1d 0a 00 06 00 0f 09  |.......2........|
    00000010  00 10 00 11 08 00 12 0a  00 13 00 14 07 00 15 07  |................|
    00000020  00 16 01 00 06 3c 69 6e  69 74 3e 01 00 03 28 29  |.....<init>...()|
    00000030  56 01 00 04 43 6f 64 65  01 00 0f 4c 69 6e 65 4e  |V...Code...LineN|
    00000040  75 6d 62 65 72 54 61 62  6c 65 01 00 04 6d 61 69  |umberTable...mai|
    00000050  6e 01 00 16 28 5b 4c 6a  61 76 61 2f 6c 61 6e 67  |n...([Ljava/lang|
    00000060  2f 53 74 72 69 6e 67 3b  29 56 01 00 0a 53 6f 75  |/String;)V...Sou|
    00000070  72 63 65 46 69 6c 65 01  00 09 54 65 73 74 2e 6a  |rceFile...Test.j|
    00000080  61 76 61 0c 00 07 00 08  07 00 17 0c 00 18 00 19  |ava.............|
    00000090  01 00 0c 48 65 6c 6c 6f  20 57 6f 72 6c 64 21 07  |...Hello World!.|
    000000a0  00 1a 0c 00 1b 00 1c 01  00 04 54 65 73 74 01 00  |..........Test..|
    000000b0  10 6a 61 76 61 2f 6c 61  6e 67 2f 4f 62 6a 65 63  |.java/lang/Objec|
    000000c0  74 01 00 10 6a 61 76 61  2f 6c 61 6e 67 2f 53 79  |t...java/lang/Sy|
    000000d0  73 74 65 6d 01 00 03 6f  75 74 01 00 15 4c 6a 61  |stem...out...Lja|
    000000e0  76 61 2f 69 6f 2f 50 72  69 6e 74 53 74 72 65 61  |va/io/PrintStrea|
    000000f0  6d 3b 01 00 13 6a 61 76  61 2f 69 6f 2f 50 72 69  |m;...java/io/Pri|
    00000100  6e 74 53 74 72 65 61 6d  01 00 07 70 72 69 6e 74  |ntStream...print|
    00000110  6c 6e 01 00 15 28 4c 6a  61 76 61 2f 6c 61 6e 67  |ln...(Ljava/lang|
    00000120  2f 53 74 72 69 6e 67 3b  29 56 00 21 00 05 00 06  |/String;)V.!....|
    00000130  00 00 00 00 00 02 00 01  00 07 00 08 00 01 00 09  |................|
    00000140  00 00 00 1d 00 01 00 01  00 00 00 05 2a b7 00 01  |............*...|
    00000150  b1 00 00 00 01 00 0a 00  00 00 06 00 01 00 00 00  |................|
    00000160  01 00 09 00 0b 00 0c 00  01 00 09 00 00 00 25 00  |..............%.|
    00000170  02 00 01 00 00 00 09 b2  00 02 12 03 b6 00 04 b1  |................|
    00000180  00 00 00 01 00 0a 00 00  00 0a 00 02 00 00 00 03  |................|
    00000190  00 08 00 04 00 01 00 0d  00 00 00 02 00 0e        |..............|
    0000019e

    2、javap

    2.1 javap -c Test

    Compiled from "Test.java"
    public class Test extends java.lang.Object{
    public Test();
      Code:
       0:    aload_0
       1:    invokespecial    #1; //Method java/lang/Object."<init>":()V
       4:    return
    
    public static void main(java.lang.String[]);
      Code:
       0:    getstatic    #2; //Field java/lang/System.out:Ljava/io/PrintStream;
       3:    ldc    #3; //String Hello World!
       5:    invokevirtual    #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8:    return
    
    }

    2.2 javap -verbose Test

    Compiled from "Test.java"
    public class Test extends java.lang.Object
      SourceFile: "Test.java"
      minor version: 0
      major version: 50
      Constant pool:
    const #1 = Method    #6.#15;    //  java/lang/Object."<init>":()V
    const #2 = Field    #16.#17;    //  java/lang/System.out:Ljava/io/PrintStream;
    const #3 = String    #18;    //  Hello World!
    const #4 = Method    #19.#20;    //  java/io/PrintStream.println:(Ljava/lang/String;)V
    const #5 = class    #21;    //  Test
    const #6 = class    #22;    //  java/lang/Object
    const #7 = Asciz    <init>;
    const #8 = Asciz    ()V;
    const #9 = Asciz    Code;
    const #10 = Asciz    LineNumberTable;
    const #11 = Asciz    main;
    const #12 = Asciz    ([Ljava/lang/String;)V;
    const #13 = Asciz    SourceFile;
    const #14 = Asciz    Test.java;
    const #15 = NameAndType    #7:#8;//  "<init>":()V
    const #16 = class    #23;    //  java/lang/System
    const #17 = NameAndType    #24:#25;//  out:Ljava/io/PrintStream;
    const #18 = Asciz    Hello World!;
    const #19 = class    #26;    //  java/io/PrintStream
    const #20 = NameAndType    #27:#28;//  println:(Ljava/lang/String;)V
    const #21 = Asciz    Test;
    const #22 = Asciz    java/lang/Object;
    const #23 = Asciz    java/lang/System;
    const #24 = Asciz    out;
    const #25 = Asciz    Ljava/io/PrintStream;;
    const #26 = Asciz    java/io/PrintStream;
    const #27 = Asciz    println;
    const #28 = Asciz    (Ljava/lang/String;)V;
    
    {
    public Test();
      Code:
       Stack=1, Locals=1, Args_size=1
       0:    aload_0
       1:    invokespecial    #1; //Method java/lang/Object."<init>":()V
       4:    return
      LineNumberTable: 
       line 1: 0
    
    
    public static void main(java.lang.String[]);
      Code:
       Stack=2, Locals=1, Args_size=1
       0:    getstatic    #2; //Field java/lang/System.out:Ljava/io/PrintStream;
       3:    ldc    #3; //String Hello World!
       5:    invokevirtual    #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8:    return
      LineNumberTable: 
       line 3: 0
       line 4: 8
    
    
    }
  • 相关阅读:
    内部类
    Tomcat 配置安装
    Eclipse转idea改设置
    MyEclipse增强代码补全
    06、自动挂载+超级守护进程+时间同步+tcpwrapper+软硬链接+日志管理
    05、ip划分+网络配置+虚拟化基础+基本路由
    04、rpm+yum+tar解压
    03、磁盘管理+swap分区创建+磁盘配额+自动挂载
    02、用户管理
    01、Linux基础命令
  • 原文地址:https://www.cnblogs.com/liqiu/p/hexdump.html
Copyright © 2020-2023  润新知