I could successfully manipulate classes from the rt.jar.
For example I manipulated the bytecode of the BigDecimal
class. Which class are you training to manipulate? And what kind of manipulation are you doing? Just adding logs to every method of the class like in the article that you mentioned?
In additional of following the instructions of article, I had to do some other things in order to be able manipulate the classes of rt.jar.
In the LoggerAgent
class I added an array of classes that I explicitly want to manipulate.
String[] includeArr = new String[] { "java/math/BigDecimal" };
ArrayList<String> include = new ArrayList(Arrays.asList(includeArr));
In the transform
method of the LoggerAgent
class I modified the loop to include the classes I explicitly want to manipulate.
for (int i = 0; i < ignore.length; i++) {
if (className.startsWith(ignore[i]) && !include.contains(className)) {
return bytes;
}
}
Fixed the method methodReturnsValue
of JavassistHelper to correctly distinguish between methods and constructors.
private static boolean methodReturnsValue(CtBehavior method)throws NotFoundException {
if (method instanceof CtMethod){
CtClass returnType = ((CtMethod) method).getReturnType();
String returnTypeName = returnType.getName();
if(returnTypeName.equals("void")){
return false;
}else{
return true;
}
} else{
return false;
}
}
Last, in the HelloWorld class I created a BigDecimal
just to check the manipulation behavior.
The output looks like as follow:
19/06/2015 16:00:26 java.math.BigDecimal signum
INFO: << signum() returns: 1
19/06/2015 16:00:26 java.math.BigDecimal layoutChars
INFO: << layoutChars(1=true) returns: 11.1099999999999994315658113919198513031005859375
19/06/2015 16:00:26 java.math.BigDecimal toString
INFO: << toString() returns: 11.1099999999999994315658113919198513031005859375
19/06/2015 16:00:26 com.runjva.demo.HelloWorld main
INFO: << main(args=[])
BigDecimal=11.1099999999999994315658113919198513031005859375
Stop at Fri Jun 19 16:00:26 PDT 2015
I hope it helps. If not, please add more details of what you are trying to do.