您的位置:首页 > 编程语言 > Java开发

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

2010-12-12 20:27 489 查看
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 H***E 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 H***E TO REWRITE OR RE-ORGANIZE THESE SOURCE.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐