Hello everyone,

I am a beginner in the modification of java bytecode and i want to insert a 
'assert(false)' instruction in the body of one method.

My main question is : if you had to add an 'assert(false)' instruction to a 
class file how would you proceed with Javassist ?

Here is what i tried so far but unfortunately it didn't work :
At first i tried with CtMethod.insertAfter("assert(false)";) method to simply  
add it to the body of one method but you can't insert an 'assert' with these 
methods (the 'assert' instruction is not recognized by javassist). 

So in order to discover the "bytecode pattern" of the 'assert(false)' 
instruction I used a CodeIterator instance and I went trough the bytecode of 
this simple method :
public static int func(int param) {
  |         assert(false);
  |         return 10 + param;
  |     }
I finally isolate the following bytes (using the byteAt() method) for the 
'assert(false)' instruction :
byteAt index 0 : 178 GETSTATIC
  | byteAt index 1 : 0
  | byteAt index 2 : 9  T_SHORT
  | byteAt index 3 : 154 IFNE
  | byteAt index 4 : 0
  | byteAt index 5 : 11 FCONST_O 
  | byteAt index 6 : 187 NEW
  | byteAt index 7 : 0
  | byteAt index 8 : 10 LCONST_1 or T_INT
  | byteAt index 9 : 89  DUP
  | byteAt index 10 : 183  INVOKESPECIAL
  | byteAt index 11 : 0
  | byteAt index 12 : 11 T_LONG
  | byteAt index 13 : 191 ATHROW
Then i tried to add this pattern byte by byte to my class file using 
CodeIterator.insert() and unfortunately it correctly add the bytes to the class 
file but it didn't result in an 'assert(false)' instruction...

What am I doing wrong here ? Thank you very much for any help !  

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3880674#3880674

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3880674


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to