bytecode manipulation - java disassemble reassemble -
say want take java class file, disassemble it, tweak java bytecode output, , reassemble again.
i need rename symbol in constant pool table. don't have access source code, , using decompiler seems overkill this. i'm not trying optimize - java fine job @ that.
is there... simple way this? i've found several tools either disassembly or reassembly, none both; or no pairs of tools seem use same format representing bytecode in text.
did check asm api?
here code sample (adapted official documentation) explaining how modify class bytecode:
classswriter cw = new classwriter(); classadapter ca = new classadapter(cw); // ca forwards events cw // ca should modify class data classreader cr = new classreader("myclass"); cr.accept(ca, 0); byte[] b2 = cw.tobytearray(); // b2 represents same class myclass, modified ca
then b2 can stored in .class file future use. can use method classloader.defineclass(string,byte[],int,int)
load if define own classloader.
Comments
Post a Comment