Initial knowledge Byteman of Java Reverse Foundation

Source: Internet
Author: User
Tags jboss

Byteman was invented primarily by JBoss to support multi-threaded and multi-JVM testing automation.

The Byteman rule language provides a standard set of built-in actions that support tasks in a specific category above

To simplify test automation, Byteman has been integrated with two popular test integration frameworks JUnit and testng

In the reverse, we can also use Byteman to help us analyze the invocation of the method


Byteman:http://byteman.jboss.org/downloads.html

Environment variable Configuration

Byteman_home = C:\byteman-download-4.0.2

Path Add%byteman_home%\bin


Installation verification

Bmcheck


See an example

Helloworld.java

Helloworld.javapublic class HelloWorld {public static void main (string[] argv) {System.out.println ("Hello, world!");}}


Rule File Appmain.btm

#appmain. Btmrule Trace Main entryclass helloworldmethod mainat entryif truedo traceln ("Entering main") Endrulerule trace M Ain Exitclass helloworldmethod Mainat exitif truedo Traceln ("exiting main") Endrule


Compile

Javac Helloworld.java

Run

Java HelloWorld

Rule check

BMCHECK-CP. -V Appmain.btm

Byteman Run

JAVA-JAVAAGENT:%BYTEMAN_HOME%\LIB\BYTEMAN.JAR=SCRIPT:APPMAIN.BTM HelloWorld

Run results


Rule file Definition

# Regular Skeleton rule < rule name >class < class name >method < method name >bind < bind event >if < condition >do < action >endrule

In the script we used the Traceln statement, then this call is actually Byteman Org.jboss.byteman.rule.helper.Helper class method, these methods are already built-in, can be called directly in the script. We can also extend the helper class for invocation.

From the above we can see how to use the Byteman: 1. Write the rules file, 2. Write the extension method of the helper class (optional), 3. Specify script file invocation


Look at one more example.

Output parameters and return values

Main.java

Package Com.vvvtimes;public class Main {public int add (int x, int y) {return x + y;} public int Add (int x, int y, int z) {return x + y + z;} public static void Main (string[] argv) {main m = new main (); System.out.println (M.add (1, 2)); System.out.println (M.add (1, 2, 3));}}

Rule File Appmain.btm

RULE Trace Arg1class Com.vvvtimes.MainMETHOD Add (int,int) at Entryif Truedo Traceln ("arg1=" + $ + "arg2=" + $ $) Endrulerul E Trace return Value1class com.vvvtimes.MainMETHOD Add (int,int) at Exitif Truedo Traceln ("Return value:" +$!)  Endrulerule Trace Arg2class Com.vvvtimes.MainMETHOD Add (int,int,int) at Entryif Truedo Traceln ("arg1=" + $ + + "arg2=" + $ $ + "arg3=" + $ $) endrulerule trace return value2class com.vvvtimes.MainMETHOD Add (int,int,int) at Exitif Truedo Traceln ("Re Turn value: "+$!) Endrule


Compile

Javac Com/vvvtimes/main.java

Run

Java Com.vvvtimes.Main

Rule check

BMCHECK-CP. -V Scripts/appmain.btm

Byteman Run

JAVA-JAVAAGENT:%BYTEMAN_HOME%\LIB\BYTEMAN.JAR=SCRIPT:SCRIPTS/APPMAIN.BTM Com.vvvtimes.Main

Run results

This is the current object. $ = is the first parameter of the current method, and if there are multiple parameters, the number grows sequentially. $! refers to the return value, at and after synonyms

It is important to note that rule's syntax rules do not support the wildcard pattern in the grammar of the rule, in reverse if this rule to write will be very troublesome, the official recommended to use batch script to generate ...

So if you have a lot of the same name, use the ASPECTJ in front of you to find it.

For more information, refer to Docs/byteman-programmers-guide.pdf

There's no use in tracking local variables online. Requires-g compilation, not used in reverse




Initial knowledge Byteman of Java Reverse Foundation

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.