Java Code Examples for com.sun.org.apache.bcel.internal.util.ByteSequence#available()

The following examples show how to use com.sun.org.apache.bcel.internal.util.ByteSequence#available() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 2
Source File: Utility.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 3
Source File: Utility.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 4
Source File: Utility.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 5
Source File: Utility.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 6
Source File: Utility.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 7
Source File: Utility.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 8
Source File: Utility.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 9
Source File: Utility.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 10
Source File: Utility.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        int index, int length, boolean verbose)
{
  StringBuffer buf    = new StringBuffer(code.length * 20); // Should be sufficient
  ByteSequence stream = new ByteSequence(code);

  try {
    for(int i=0; i < index; i++) // Skip `index' lines of code
      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 + codeToString(stream, constant_pool, verbose) + '\n');
      }
    }
  } catch(IOException e) {
    System.out.println(buf.toString());
    e.printStackTrace();
    throw new ClassFormatException("Byte code error: " + e);
  }

  return buf.toString();
}
 
Example 11
Source File: InstructionList.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 12
Source File: InstructionList.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 13
Source File: InstructionList.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 14
Source File: InstructionList.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 15
Source File: InstructionList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 16
Source File: InstructionList.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 17
Source File: InstructionList.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 18
Source File: InstructionList.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 19
Source File: InstructionList.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}
 
Example 20
Source File: InstructionList.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * @return an array of instructions without target information for branch instructions.
 */
public Instruction[] getInstructions() {
  ByteSequence  bytes        = new ByteSequence(getByteCode());
  ArrayList     instructions = new ArrayList();

  try {
    while(bytes.available() > 0) {
      instructions.add(Instruction.readInstruction(bytes));
    }
  } catch(IOException e) { throw new ClassGenException(e.toString()); }

  Instruction[] result = new Instruction[instructions.size()];
  instructions.toArray(result);
  return result;
}