| Code with Finding: |
class Utility {
/**
* Disassemble a byte array of JVM byte codes starting from code line
* `index' and return the disassembled string representation. Decode only
* `num' opcodes (including their operands), use -1 if you want to
* decompile everything.
*
* @param code byte code array
* @param constant_pool Array of constants
* @param index offset in `code' array
* <EM>(number of opcodes, not bytes!)</EM>
* @param length number of opcodes to decompile, -1 for all
* @param verbose be verbose, e.g. print constant pool index
* @return String representation of byte codes
*/
public static String codeToString( byte[] code, ConstantPool constant_pool, int index,
int length, boolean verbose ) {
StringBuilder buf = new StringBuilder(code.length * 20); // Should be sufficient // CHECKSTYLE IGNORE MagicNumber
ByteSequence stream = new ByteSequence(code);
try {
for (int i = 0; i < index; i++) {
codeToString(stream, constant_pool, verbose);
}
for (int i = 0; stream.available() > 0; i++) {
if ((length < 0) || (i < length)) {
String indices = fillup(stream.getIndex() + ":", 6, true, ' ');
buf.append(indices).append(codeToString(stream, constant_pool, verbose))
.append('\n');
}
}
} catch (IOException e) {
System.out.println(buf.toString());
e.printStackTrace();
throw new ClassFormatException("Byte code error: " + e, e);
}
return buf.toString();
}
}
|