Hi All,
I am new to BCEL. Just started using it. I had a problem with
local variable insertion to a method dynamically.
I tried to find in internet resoruces , but could not, could you
please help me in this regard.
I am trying to open the modified class with decompiler, a dialog
appears, when decompiling saying
The instruction at "0x..." reference memory at
"...". The memory could not be read.
however a jad is created, in which all the methods starting from
the modified method no more appear in the class file, i.e methods are
gettign corrupted.
Please have a look at the following code[1] and please correct
me..
should I do some updations to local variable table after
insertion of a local variable or is it automatically updated ????
please help me in this regard.
Thank you
Reddy
class A{
public Method instr( JavaClass javaClass,
Method method,
ConstantPoolGen poolGen,
InstructionFactory
factory ) {
MethodGen mgen = new MethodGen(method,
javaClass.getClassName(), poolGen);
InstructionList ilist = mgen.getInstructionList();
InstructionList ilist_start = new InstructionList();
insertStaticCallAtEntry(mgen, poolGen, factory,
ilist_start, methodName);
InstructionHandle ihss = ilist.insert( ihandle_start,
ilist_start);
ilist.redirectBranches( ihandle_start, ihss);
mgen.setMaxStack();
return mgen.getMethod();
}
private void insertStaticCallAtEntry( MethodGen mgen
, ConstantPoolGen poolGen
, InstructionFactory factory
, InstructionList ilist_start
, String method_call) {
ilist_start.append(factory.createInvoke(NAME_OF_CLASS_CONTAINER,
method_call, Type.VOID,
new Type[]{},
Constants.INVOKESTATIC));
LocalVariableGen localVar= mgen.addLocalVariable("obj",new
ObjectType("java.lang.Object"), null, null);
int obj = localVar.getIndex();
Tracer.trace("index is "+ obj);
localVar.setStart(ilist_start.append(new ASTORE(obj)));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]