private byte[] getCodeBytes(Method m, int start, int end) { byte[] code = m.getCode().getCode(); byte[] bytes = new byte[end - start]; System.arraycopy(code, start, bytes, 0, end - start); try { ByteSequence sequence = new ByteSequence(code); while ((sequence.available() > 0) && (sequence.getIndex() < start)) { Instruction.readInstruction(sequence); } int pos; while (sequence.available() > 0 && ((pos = sequence.getIndex()) < end)) { Instruction ins = Instruction.readInstruction(sequence); if ((ins instanceof BranchInstruction) && !(ins instanceof TABLESWITCH) && !(ins instanceof LOOKUPSWITCH)) { BranchInstruction bi = (BranchInstruction) ins; int offset = bi.getIndex(); int target = offset + pos; if (target >= end) { // or target < start ?? byte hiByte = (byte) ((target >> 8) & 0x000000FF); byte loByte = (byte) (target & 0x000000FF); bytes[pos + bi.getLength() - 2 - start] = hiByte; bytes[pos + bi.getLength() - 1 - start] = loByte; } } } } catch (IOException ioe) { } return bytes; }
/** * @return an array of instructions without target information for branch instructions. */ public Instruction[] getInstructions() { final List<Instruction> instructions = new ArrayList<>(); try (ByteSequence bytes = new ByteSequence(getByteCode())) { while (bytes.available() > 0) { instructions.add(Instruction.readInstruction(bytes)); } } catch (final IOException e) { throw new ClassGenException(e.toString(), e); } return instructions.toArray(new Instruction[instructions.size()]); }
/** * @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; }
private byte[] getCodeBytes(Method m, int start, int end) { byte[] code = m.getCode().getCode(); byte[] bytes = new byte[end - start]; System.arraycopy(code, start, bytes, 0, end - start); try { ByteSequence sequence = new ByteSequence(code); while ((sequence.available() > 0) && (sequence.getIndex() < start)) { Instruction.readInstruction(sequence); } int pos; while (sequence.available() > 0 && ((pos = sequence.getIndex()) < end)) { Instruction ins = Instruction.readInstruction(sequence); if ((ins instanceof BranchInstruction) && !(ins instanceof TABLESWITCH) && !(ins instanceof LOOKUPSWITCH)) { BranchInstruction bi = (BranchInstruction) ins; int offset = bi.getIndex(); int target = offset + pos; if (target >= end) { // or target < start ?? byte hiByte = (byte) ((target >> 8) & 0x000000FF); byte loByte = (byte) (target & 0x000000FF); bytes[pos + bi.getLength() - 2 - start] = hiByte; bytes[pos + bi.getLength() - 1 - start] = loByte; } } } } catch (IOException ioe) { } return bytes; }
Instruction i = Instruction.readInstruction(bytes); InstructionHandle ih; if(i instanceof BranchInstruction) // Use proper append() method
final Instruction i = Instruction.readInstruction(bytes); InstructionHandle ih; if (i instanceof BranchInstruction) {