Byteman extension Helper Class for Java Reverse Foundation

Source: Internet
Author: User
Tags jboss

The previous article mentions that we can invoke the extension helper class that we write in the rules file

See an example

Create a new target project and extend the helper class project with the following structure

The code where the target project uses the second example of the previous blog

Extension helper projects need to use a third-party jar, C:\byteman-download-4.0.2\lib find Byteman.jar copy over

The Tracehelper.java code is as follows

Package Com.vvvtimes;import Org.jboss.byteman.rule.rule;import Org.jboss.byteman.rule.helper.helper;public class Tracehelper extends Helper {protected tracehelper (rule rule) {super (rule);} public boolean myprint (String message) {return Super.traceln ("!!! IMPORTANT EVENT!!! "+ message);}}

Export this project as Bytemanhelperdemo.jar

The TRACING.BTM content of the rule file in the target project is as follows, where the helper item specifies a custom helper class name

RULE Trace return Value1class com.vvvtimes.MainMETHOD Add (int,int) HELPER Com.vvvtimes.TraceHelperAT exitif Truedo Myprint ("Return value:" +$!) Endrule

Compile

Javac Com/vvvtimes/main.java

Run

Java Com.vvvtimes.Main

Add helper class rules file check, notice more a-CP Bytemanhelperdemo.jar

BMCHECK-CP. -CP bytemanhelperdemo.jar-v SCRIPTS/TRACING.BTM

Byteman Run

Java-cp ".; bytemanhelperdemo.jar;%classpath% "-javaagent:%byteman_home%\lib\byteman.jar=script:scripts/tracing.btm Com.vvvtimes.Main

The operation results are as follows


If we package the above target item into a jar, the command can be changed to the following form

The target project is packaged into a jar named Bytemandemo2.jar

Run

JAVA-CP "bytemandemo2.jar;%classpath%" Com.vvvtimes.Main

Rule file Check for helper classes

BMCHECK-CP BYTEMANDEMO2.JAR-CP bytemanhelperdemo.jar-v SCRIPTS/TRACING.BTM

Byteman Run

JAVA-CP "Bytemandemo2.jar; bytemanhelperdemo.jar;%classpath% "-javaagent:%byteman_home%\lib\byteman.jar=script:scripts/tracing.btm Com.vvvtimes.Main

Run results




Byteman extension Helper Class for Java Reverse Foundation

Related Article

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.