com.sun.org.apache.bcel.internal.util.ByteSequence Java Examples

The following examples show how to use com.sun.org.apache.bcel.internal.util.ByteSequence. 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: TABLESWITCH.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  super.initFromFile(bytes, wide);

  int low    = bytes.readInt();
  int high   = bytes.readInt();

  match_length = high - low + 1;
  fixed_length = (short)(13 + match_length * 4);
  length       = (short)(fixed_length + padding);

  match   = new int[match_length];
  indices = new int[match_length];
  targets = new InstructionHandle[match_length];

  for(int i=low; i <= high; i++)
    match[i - low] = i;

  for(int i=0; i < match_length; i++) {
    indices[i] = bytes.readInt();
  }
}
 
Example #2
Source File: TABLESWITCH.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  super.initFromFile(bytes, wide);

  int low    = bytes.readInt();
  int high   = bytes.readInt();

  match_length = high - low + 1;
  fixed_length = (short)(13 + match_length * 4);
  length       = (short)(fixed_length + padding);

  match   = new int[match_length];
  indices = new int[match_length];
  targets = new InstructionHandle[match_length];

  for(int i=low; i <= high; i++)
    match[i - low] = i;

  for(int i=0; i < match_length; i++) {
    indices[i] = bytes.readInt();
  }
}
 
Example #3
Source File: LOOKUPSWITCH.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
@Override
protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
    super.initFromFile(bytes, wide); // reads padding
    final int _match_length = bytes.readInt();
    setMatch_length(_match_length);
    final short _fixed_length = (short) (9 + _match_length * 8);
    setFixed_length(_fixed_length);
    final short _length = (short) (_match_length + super.getPadding());
    super.setLength(_length);
    super.setMatches(new int[_match_length]);
    super.setIndices(new int[_match_length]);
    super.setTargets(new InstructionHandle[_match_length]);
    for (int i = 0; i < _match_length; i++) {
        super.setMatch(i, bytes.readInt());
        super.setIndices(i, bytes.readInt());
    }
}
 
Example #4
Source File: TABLESWITCH.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  super.initFromFile(bytes, wide);

  int low    = bytes.readInt();
  int high   = bytes.readInt();

  match_length = high - low + 1;
  fixed_length = (short)(13 + match_length * 4);
  length       = (short)(fixed_length + padding);

  match   = new int[match_length];
  indices = new int[match_length];
  targets = new InstructionHandle[match_length];

  for(int i=low; i <= high; i++)
    match[i - low] = i;

  for(int i=0; i < match_length; i++) {
    indices[i] = bytes.readInt();
  }
}
 
Example #5
Source File: LocalVariableInstruction.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Read needed data (e.g. index) from file.
  * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
  */
 protected void initFromFile(ByteSequence bytes, boolean wide)
   throws IOException
 {
   if(wide) {
     n         = bytes.readUnsignedShort();
     length    = 4;
   } else if(((opcode >= Constants.ILOAD) &&
              (opcode <= Constants.ALOAD)) ||
             ((opcode >= Constants.ISTORE) &&
              (opcode <= Constants.ASTORE))) {
     n      = bytes.readUnsignedByte();
     length = 2;
   } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
     n      = (opcode - Constants.ILOAD_0) % 4;
     length = 1;
   } else { // Assert ISTORE_0 <= tag <= ASTORE_3
     n      = (opcode - Constants.ISTORE_0) % 4;
     length = 1;
   }
}
 
Example #6
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 #7
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 #8
Source File: LOOKUPSWITCH.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  super.initFromFile(bytes, wide); // reads padding

  match_length = bytes.readInt();
  fixed_length = (short)(9 + match_length * 8);
  length       = (short)(fixed_length + padding);

  match   = new int[match_length];
  indices = new int[match_length];
  targets = new InstructionHandle[match_length];

  for(int i=0; i < match_length; i++) {
    match[i]   = bytes.readInt();
    indices[i] = bytes.readInt();
  }
}
 
Example #9
Source File: TABLESWITCH.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  super.initFromFile(bytes, wide);

  int low    = bytes.readInt();
  int high   = bytes.readInt();

  match_length = high - low + 1;
  fixed_length = (short)(13 + match_length * 4);
  length       = (short)(fixed_length + padding);

  match   = new int[match_length];
  indices = new int[match_length];
  targets = new InstructionHandle[match_length];

  for(int i=low; i <= high; i++)
    match[i - low] = i;

  for(int i=0; i < match_length; i++) {
    indices[i] = bytes.readInt();
  }
}
 
Example #10
Source File: LOOKUPSWITCH.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  super.initFromFile(bytes, wide); // reads padding

  match_length = bytes.readInt();
  fixed_length = (short)(9 + match_length * 8);
  length       = (short)(fixed_length + padding);

  match   = new int[match_length];
  indices = new int[match_length];
  targets = new InstructionHandle[match_length];

  for(int i=0; i < match_length; i++) {
    match[i]   = bytes.readInt();
    indices[i] = bytes.readInt();
  }
}
 
Example #11
Source File: LOOKUPSWITCH.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  super.initFromFile(bytes, wide); // reads padding

  match_length = bytes.readInt();
  fixed_length = (short)(9 + match_length * 8);
  length       = (short)(fixed_length + padding);

  match   = new int[match_length];
  indices = new int[match_length];
  targets = new InstructionHandle[match_length];

  for(int i=0; i < match_length; i++) {
    match[i]   = bytes.readInt();
    indices[i] = bytes.readInt();
  }
}
 
Example #12
Source File: LocalVariableInstruction.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Read needed data (e.g. index) from file.
  * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
  */
 protected void initFromFile(ByteSequence bytes, boolean wide)
   throws IOException
 {
   if(wide) {
     n         = bytes.readUnsignedShort();
     length    = 4;
   } else if(((opcode >= Constants.ILOAD) &&
              (opcode <= Constants.ALOAD)) ||
             ((opcode >= Constants.ISTORE) &&
              (opcode <= Constants.ASTORE))) {
     n      = bytes.readUnsignedByte();
     length = 2;
   } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
     n      = (opcode - Constants.ILOAD_0) % 4;
     length = 1;
   } else { // Assert ISTORE_0 <= tag <= ASTORE_3
     n      = (opcode - Constants.ISTORE_0) % 4;
     length = 1;
   }
}
 
Example #13
Source File: LocalVariableInstruction.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Read needed data (e.g. index) from file.
  * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
  */
 protected void initFromFile(ByteSequence bytes, boolean wide)
   throws IOException
 {
   if(wide) {
     n         = bytes.readUnsignedShort();
     length    = 4;
   } else if(((opcode >= Constants.ILOAD) &&
              (opcode <= Constants.ALOAD)) ||
             ((opcode >= Constants.ISTORE) &&
              (opcode <= Constants.ASTORE))) {
     n      = bytes.readUnsignedByte();
     length = 2;
   } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
     n      = (opcode - Constants.ILOAD_0) % 4;
     length = 1;
   } else { // Assert ISTORE_0 <= tag <= ASTORE_3
     n      = (opcode - Constants.ISTORE_0) % 4;
     length = 1;
   }
}
 
Example #14
Source File: LocalVariableInstruction.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Read needed data (e.g. index) from file.
  * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
  */
 protected void initFromFile(ByteSequence bytes, boolean wide)
   throws IOException
 {
   if(wide) {
     n         = bytes.readUnsignedShort();
     length    = 4;
   } else if(((opcode >= Constants.ILOAD) &&
              (opcode <= Constants.ALOAD)) ||
             ((opcode >= Constants.ISTORE) &&
              (opcode <= Constants.ASTORE))) {
     n      = bytes.readUnsignedByte();
     length = 2;
   } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
     n      = (opcode - Constants.ILOAD_0) % 4;
     length = 1;
   } else { // Assert ISTORE_0 <= tag <= ASTORE_3
     n      = (opcode - Constants.ISTORE_0) % 4;
     length = 1;
   }
}
 
Example #15
Source File: Select.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
@Override
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes

  for(int i=0; i < padding; i++) {
    bytes.readByte();
  }

  // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH)
  index = bytes.readInt();
}
 
Example #16
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 #17
Source File: IINC.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  this.wide = wide;

  if(wide) {
    length = 6;
    n = bytes.readUnsignedShort();
    c = bytes.readShort();
  } else {
    length = 3;
    n = bytes.readUnsignedByte();
    c = bytes.readByte();
  }
}
 
Example #18
Source File: INVOKEINTERFACE.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (i.e., index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide)
     throws IOException
{
  super.initFromFile(bytes, wide);

  length = 5;
  nargs = bytes.readUnsignedByte();
  bytes.readByte(); // Skip 0 byte
}
 
Example #19
Source File: IINC.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  this.wide = wide;

  if(wide) {
    length = 6;
    n = bytes.readUnsignedShort();
    c = bytes.readShort();
  } else {
    length = 3;
    n = bytes.readUnsignedByte();
    c = bytes.readByte();
  }
}
 
Example #20
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 #21
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 #22
Source File: MULTIANEWARRAY.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Read needed data (i.e., no. dimension) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide)
     throws IOException
{
  super.initFromFile(bytes, wide);
  dimensions = bytes.readByte();
  length     = 4;
}
 
Example #23
Source File: LDC.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide)
     throws IOException
{
  length = 2;
  index  = bytes.readUnsignedByte();
}
 
Example #24
Source File: LDC_W.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (i.e., index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide)
     throws IOException
{
  setIndex(bytes.readUnsignedShort());
  // Override just in case it has been changed
  opcode = com.sun.org.apache.bcel.internal.Constants.LDC_W;
}
 
Example #25
Source File: RET.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
{
  this.wide = wide;

  if(wide) {
    index  = bytes.readUnsignedShort();
    length = 4;
  } else {
    index = bytes.readUnsignedByte();
    length = 2;
  }
}
 
Example #26
Source File: LDC_W.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Read needed data (i.e., index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide)
     throws IOException
{
  setIndex(bytes.readUnsignedShort());
  // Override just in case it has been changed
  opcode = com.sun.org.apache.bcel.internal.Constants.LDC_W;
}
 
Example #27
Source File: LDC.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (e.g. index) from file.
 */
protected void initFromFile(ByteSequence bytes, boolean wide)
     throws IOException
{
  length = 2;
  index  = bytes.readUnsignedByte();
}
 
Example #28
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 #29
Source File: CPInstruction.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read needed data (i.e., index) from file.
 * @param bytes input stream
 * @param wide wide prefix?
 */
protected void initFromFile(ByteSequence bytes, boolean wide)
     throws IOException
{
  setIndex(bytes.readUnsignedShort());
  length = 3;
}
 
Example #30
Source File: LDC_W.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Read needed data (i.e., index) from file.
 */
@Override
protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
    setIndex(bytes.readUnsignedShort());
    // Override just in case it has been changed
    super.setOpcode(com.sun.org.apache.bcel.internal.Const.LDC_W);
    super.setLength(3);
}