简体   繁体   English

使用Javassist获取字节码的参数

[英]Getting the arguments for the bytecode using Javassist

http://lpaste.net/338173的反汇编代码(使用javap -c)如下所示: http : //lpaste.net/338175 ,在第三列上,有200个参数作为“ sipush”的参数我是从使用javassist的类文件中获得的?

sipush is a bytecode which takes a single two byte argument which is a number to push onto the operand stack. sipush是一个字节码,它采用一个两个字节的参数,该参数是要压入操作数堆栈的数字。 In Javassist, you can iterate over all bytecode of a method via the CodeAttribute that is available from the CtMethod 's MethodInfo . 在Javassist是,你可以遍历通过一个方法的所有字节码CodeAttribute是可从CtMethodMethodInfo In your case, it would be the first byte code, but you can check that you reached Opcode.SIPUSH . 在您的情况下,这将是第一个字节代码,但是您可以检查是否已到达Opcode.SIPUSH Once you iterated to this instruction you can read the 2 byte argument via the s16bitAt method from the iterator. 迭代该指令后,您可以通过s16bitAt方法从迭代器读取2字节参数。 The method takes a zero-based index. 该方法采用从零开始的索引。 In your case, this makes the argument zero for sipush , returning 200 as a value. 在您的情况下,这会使sipush的参数为零,并返回200作为值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM