> Is it possible to modify the variable values and variable name with BCEL? 
> 
> For example, 
> 
> class test { 
> public void init(int a, String x) { 
> int i; 
> String o; 
> 
> i = a + 1; 
> o = x + " ... "; 
> } 
> } 

Don't know if I correctly understand your intentions,  but let me give
it a shot:

> 1. init(int a, String x) to init(int intVar, String strVar) 

Done :) names of variables are a Java language notion, in a Java class
file these are mapped do local variable indexes, so this is a non-issue.

> 2. int i ----> int tmpVar; 

'i' is just local variable slot for some time. If the variable is out of
scope, the local variable slot could be reused. non-issue. 'i' doesn't
really exist, just added to the LocalVariableTable attribute by the
compiler for debugging purposes.
 
> 3. String o ----> String oVar; 

idem. 

> 4. i = a + 1 ----> i = 10; 

Can't say anything about this since there is no pattern. I mean, do you
mean rewriting the 'i' variable to 10? The value of 'i' is the result of
a evaluating a bytecode sequence. Consider the following; 

.. 
iload_1
iconst_1
iadd
istore ?
..

At some point you get to the assignment of the 'i' variable. The value
of 'a' is in local variable slot 1 (becuase you are describing an
instance methods, thus slot 0 is used by the reference to the object
invoked on (this)). The iload_1 places a copy on the stack, next the
iconst_1 places constant 1 on the stack and the iadd instruction sums
the two top stack values. Finally, the istore instruction stores the
result of the addition in the local variable that represents the 'a'
variable.

So based on your intentions you can try to find a pattern in the
bytecode and rewrite it like, 

iload_1  
iconst_1  => iconst 10  
iadd         
istore ?     istore ?     

the key issue however is locating a pattern that works for all
methods.... 





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to