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