ASM + JASMIN combination for java class file editing in bytecode level

By using this combination, you will find that first we'll use ASM decompile the specified class and then rewite the specified class in JASMIN grammar, then compile this assemble source code file into java class file, first we'll show you the basic JASMIN grammar by a sample:

 

Typical Jasmin class source code:(HelloWorld case)

-------------------------------------------------------

.class public HelloWorld

.super java/lang/Object

 

.method public static main([Ljava/lang/String;)V

  .limit stack 2

  .limit locals 1

 

  getstatic      java/lang/System/out Ljava/io/PrintStream;

  ldc            "Hello World."

  invokevirtual  java/io/PrintStream/println(Ljava/lang/String;)V

  return

 

.end method

-------------------------------------------------------

If you want to get more knowledge for Jasmin, please see http://jasmin.sourceforge.net/instructions.html.

 

 

Use Asm to get assemble source code(command line set)

----------------------------------------------------------------------------

 SET CP="E:/Resource/ASM/asm3.3lib/asm-3.3.jar;E:/Resource/ASM/asm3.3lib/asm-util-3.3.jar"

 

ATTENTION: DUE TO THERE IS A DIFFERENCE (IN GRAMMAR) BETWEEN ASM AND JASMIN, WE HAVE TO REWRITE OR RE-ORGANIZE THE SOURCE AND COMPILE THEM AGAIN.

SET CP=%CP%;"E:/Resource/Test"

java -classpath %CP% org.objectweb.asm.util.TraceClassVisitor HelloWorld > HelloWorld.asm

----------------------------------------------------------------------------

 

 

Finally Run java class file in a source command:

----------------------------------------------------------------------------

SET CP="E:/Resource/Test"

java -cp %CP% examples.NewWorld

 

Use Jasmin to compile the specified assemble source code:

----------------------------------------------------------------------------

set CP=E:/Resource/Jasmin/jasmin-2.4/lib/ant.jar;

set CP=%CP%;E:/Resource/Jasmin/jasmin-2.4/lib/ant-launcher.jar;

set CP=%CP%;E:/Resource/Jasmin/jasmin-2.4/lib/java_cup.jar

java -cp %CP% -jar E:/Resource/Jasmin/jasmin-2.4/jasmin.jar examples/NewWorld.j

-----------------------------------------------------------------------

ATTENTION:  DUE TO THERE IS A DIFFERENCE BETWEEN THE ASSEMBLE CODE DECOMPILED BY ASM AND THE SOURCE FOR JASMIN COMPILING, WE WILL HAVE TO REWRITE OR RE-ORGANIZE THESE SOURCE.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值