I'm writing some code where I want to use BCEL to substitute all calls to methods of SomeClass with calls to methods of SomeOtherClass.
Right now, from my understanding, I can do this by:
- iterating over the instruction list
- finding all
invokevirtual
,invokestatic
orinvokespecial
instructions that reference SomeClass - replace those with the appropriate invokeX that references SomeOtherClass
This requires me to rewrite a lot of calls tho, and I have to handle at least three different cases (invokevirtual
, invokestatic
and invokespecial
calls).
Instead, is it possible to do it by manipulating the constant pool and replacing all constants that point to SomeClass with SomeOtherClass? if so, how?