ASM + Jasmin combination for Java class file editing in bytecode level

Source: Internet
Author: User

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 % 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 %-jar E:/resources/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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.