Java文件编译与反编译(一):javac命令和javap命令
Java文件编译与反编译(一):javac命令和javap命令
1.创建一个Test.java文件,并输入内容
public class Test{private int m;public int inc(){return m + 1;}}
2.使用javac命令编译Test.java文件,得到Test.class文件
$javac Test.java
3.使用Sublime3打开Test.class
cafe babe 0000 0034 0013 0a00 0400 0f090003 0010 0700 1107 0012 0100 016d 01000149 0100 063c 696e 6974 3e01 0003 28295601 0004 436f 6465 0100 0f4c 696e 654e756d 6265 7254 6162 6c65 0100 0369 6e630100 0328 2949 0100 0a53 6f75 7263 6546696c 6501 0009 5465 7374 2e6a 6176 610c0007 0008 0c00 0500 0601 0004 5465 73740100 106a 6176 612f 6c61 6e67 2f4f 626a6563 7400 2100 0300 0400 0000 0100 02000500 0600 0000 0200 0100 0700 0800 01000900 0000 1d00 0100 0100 0000 052a b70001b1 0000 0001 000a 0000 0006 0001 00000001 0001 000b 000c 0001 0009 0000 001f0002 0001 0000 0007 2ab4 0002 0460 ac000000 0100 0a00 0000 0600 0100 0000 04000100 0d00 0000 0200 0e
4.使用javap命令,反编译Test.class文件
使用命令:$ javap -v Test
输出为:
Classfile /Users/soldier/Desktop/Test.class Last modified 2018-9-19; size 265 bytes MD5 checksum 551399dd9890a81e8f8c079c6c1f364d Compiled from "Test.java"public class Test minor version: 0 major version: 52 flags: ACC_PUBLIC, ACC_SUPERConstant pool: #1 = Methodref #4.#15 // java/lang/Object."<init>":()V #2 = Fieldref #3.#16 // Test.m:I #3 = Class #17 // Test #4 = Class #18 // java/lang/Object #5 = Utf8 m #6 = Utf8 I #7 = Utf8 <init> #8 = Utf8 ()V #9 = Utf8 Code #10 = Utf8 LineNumberTable #11 = Utf8 inc #12 = Utf8 ()I #13 = Utf8 SourceFile #14 = Utf8 Test.java #15 = NameAndType #7:#8 // "<init>":()V #16 = NameAndType #5:#6 // m:I #17 = Utf8 Test #18 = Utf8 java/lang/Object{ public Test(); descriptor: ()V flags: 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 1: 0 public int inc(); descriptor: ()I flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: getfield #2 // Field m:I 4: iconst_1 5: iadd 6: ireturn LineNumberTable: line 4: 0}SourceFile: "Test.java"
使用命令:$ javap -c Test
输出为:
Compiled from "Test.java"public class Test { public Test(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public int inc(); Code: 0: aload_0 1: getfield #2 // Field m:I 4: iconst_1 5: iadd 6: ireturn}
用法摘要
-help 帮助-l 输出行和变量的表-public只输出public方法和域-protected只输出public和protected类和成员-package只输出包,public和protected类和成员,这是默认的-p -private 输出所有类和成员-s 输出内部类型签名-c输出分解后的代码,例如,类中每一个方法内,包含java字节码的指令,-v输出栈大小,方法参数的个数-constants 输出静态final常量
赞 (0)