class 文件java字节码Oolong反编译分析

时间:2022-09-19 17:20:58

我们知道java程序在经过虚拟机后生成class字节码二进制文件,那么怎样分析class文件呢,我们可以把class文件结构转换为能够理解的汇编语言Oolong,可以更好的认识class文件中的信息。

一:下载Onlong JVM项目

地址https://github.com/jpbirdy/programming-for-the-jvm

主要说明

* COM.sootNsmoke.jvm - a library for building Java (tm)  class files
* COM.sootNsmoke.oolong - A compiler and decompiler for Oolong, a
  language for building JVM class files.
* COM.sootNsmoke.instructions - Support classes for the jvm package.
  Abstractions of JVM instructions to make building code easier.
* COM.sootNsmoke.scheme - a nearly complete implementation of the R4
  Scheme specification, which compiles Scheme code into JVM bytecodes.
* COM.sootNsmoke.prolog - a simple Prolog compiler demonstrating how
  to compile Prolog into JVM code

二:把Onlong文件下的\programming-for-the-jvm-master\src\main\java\COM打为jar包

class 文件java字节码Oolong反编译分析

三:把jar包放到jdk的lib目录下并添加到环境变量的classpath路径下

class 文件java字节码Oolong反编译分析

四:测试生成Onlong

class 文件java字节码Oolong反编译分析

五:生成了.j结尾的文件

class 文件java字节码Oolong反编译分析

六:对.j结尾Onlong的文件进行分析

.source TestClass.java
.class public super com/lean/clazz/TestClass
.super java/lang/Object


.method public <init> ()V
.limit stack 1
.limit locals 1
.var 0 is this Lcom/lean/clazz/TestClass; from l0 to l5
.line 3
l0: aload_0
l1: invokespecial java/lang/Object/<init> ()V
l4: return

.end method

.method public static main ([Ljava/lang/String;)V
.limit stack 2
.limit locals 1
.var 0 is args [Ljava/lang/String; from l0 to l9
.line 5
l0: getstatic java/lang/System/out Ljava/io/PrintStream;
l3: ldc "I am Chinese!"
l5: invokevirtual java/io/PrintStream/println (Ljava/lang/String;)V
.line 6
l8: return

.end method