/** * Returns a slice (that is, a sub-array) of this instance. * * @param start {@code >= 0;} start index of the slice (inclusive) * @param end {@code >= start, <= size();} end index of * the slice (exclusive) * @return {@code non-null;} the slice */ public ByteArray slice(int start, int end) { checkOffsets(start, end); return new ByteArray(bytes, start + this.start, end + this.start); }
/** * Gets the {@code signed short} value at a particular offset. * * @param off {@code >= 0, < (size() - 1);} offset to fetch * @return {@code signed short} at that offset */ public int getShort(int off) { checkOffsets(off, off + 2); return (getByte0(off) << 8) | getUnsignedByte0(off + 1); }
/** * Gets the total length of this structure in bytes, when included in * a {@code Code} attribute. The returned value includes the * array size plus four bytes for {@code code_length}. * * @return {@code >= 4;} the total length, in bytes */ public int byteLength() { return 4 + bytes.size(); }
/** * Gets the {@code signed byte} value at a particular offset. * * @param off {@code >= 0, < size();} offset to fetch * @return {@code signed byte} at that offset */ public int getByte(int off) { checkOffsets(off, off + 1); return getByte0(off); }
/** * Gets the {@code unsigned short} value at a particular offset. * * @param off {@code >= 0, < (size() - 1);} offset to fetch * @return {@code unsigned short} at that offset */ public int getUnsignedShort(int off) { checkOffsets(off, off + 2); return (getUnsignedByte0(off) << 8) | getUnsignedByte0(off + 1); }
int opcode = bytes.getUnsignedByte(offset); int value = bytes.getByte(offset + 1); visitor.visitConstant(ByteOps.LDC, offset, 2, CstInteger.make(value), value); int value = bytes.getShort(offset + 1); visitor.visitConstant(ByteOps.LDC, offset, 3, CstInteger.make(value), value); int idx = bytes.getUnsignedByte(offset + 1); Constant cst = pool.get(idx); int value = (cst instanceof CstInteger) ? int idx = bytes.getUnsignedShort(offset + 1); Constant cst = pool.get(idx); int value = (cst instanceof CstInteger) ? int idx = bytes.getUnsignedShort(offset + 1); Constant cst = pool.get(idx); visitor.visitConstant(ByteOps.LDC2_W, offset, 3, cst, 0); int idx = bytes.getUnsignedByte(offset + 1); visitor.visitLocal(ByteOps.ILOAD, offset, 2, idx, Type.INT, 0); int idx = bytes.getUnsignedByte(offset + 1); visitor.visitLocal(ByteOps.ILOAD, offset, 2, idx, Type.LONG, 0);
ConstantPool pool, ParseObserver observer, int count, boolean typeTable) { if (bytes.size() != (count * 10)) { ByteArray.MyDataInputStream in = bytes.makeDataInputStream(); LocalVariableList list = new LocalVariableList(count);
/** * Constructs an instance. * * @param cf {@code non-null;} class file to parse from * @param offset {@code >= 0;} offset into the class file data to parse at * @param length {@code >= 0;} number of bytes left in the attribute data * @param observer {@code null-ok;} parse observer to notify, if any */ public AnnotationParser(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (cf == null) { throw new NullPointerException("cf == null"); } this.cf = cf; this.pool = cf.getConstantPool(); this.observer = observer; this.bytes = cf.getBytes().slice(offset, offset + length); this.input = bytes.makeDataInputStream(); this.parseCursor = 0; }
/** * Helper to produce the first bit of output for each instruction. * * @param offset the offset to the start of the instruction */ private String header(int offset) { /* * Note: This uses the original bytecode, not the * possibly-transformed one. */ int opcode = bytes.getUnsignedByte(offset); String name = ByteOps.opName(opcode); if (opcode == ByteOps.WIDE) { opcode = bytes.getUnsignedByte(offset + 1); name += " " + ByteOps.opName(opcode); } return Hex.u2(offset) + ": " + name; }
/** * Constructs an instance from a {@code String}. * * @param string {@code non-null;} the UTF-8 value as a string */ public CstString(String string) { if (string == null) { throw new NullPointerException("string == null"); } this.string = string.intern(); this.bytes = new ByteArray(stringToUtf8Bytes(string)); }
/** * Gets a {@code DataInputStream} that reads from this instance, * with the cursor starting at the beginning of this instance's data. * <b>Note:</b> The returned instance may be cast to {@link #GetCursor} * if needed. * * @return {@code non-null;} an appropriately-constructed * {@code DataInputStream} instance */ public MyDataInputStream makeDataInputStream() { return new MyDataInputStream(makeInputStream()); }
padding = (padding << 8) | bytes.getUnsignedByte(i); int defaultTarget = offset + bytes.getInt(at); int npairs = bytes.getInt(at + 4); at += 8; int match = bytes.getInt(at); int target = offset + bytes.getInt(at + 4); at += 8; cases.add(match, target);
byte[] bytes = NuwaProcessor.referHackWhenInit(classFile.getBytes().makeDataInputStream());
int opcode = bytes.getUnsignedByte(offset); int info = ByteOps.opInfo(opcode); int fmt = info & ByteOps.FMT_MASK; int value = bytes.getByte(offset + 1); visitor.visitConstant(ByteOps.LDC, offset, 2, CstInteger.make(value), value); int value = bytes.getShort(offset + 1); visitor.visitConstant(ByteOps.LDC, offset, 3, CstInteger.make(value), value); int idx = bytes.getUnsignedByte(offset + 1); Constant cst = pool.get(idx); int value = (cst instanceof CstInteger) ? int idx = bytes.getUnsignedShort(offset + 1); Constant cst = pool.get(idx); int value = (cst instanceof CstInteger) ? int idx = bytes.getUnsignedShort(offset + 1); Constant cst = pool.get(idx); visitor.visitConstant(ByteOps.LDC2_W, offset, 3, cst, 0); int idx = bytes.getUnsignedByte(offset + 1); visitor.visitLocal(ByteOps.ILOAD, offset, 2, idx, Type.INT, 0); int idx = bytes.getUnsignedByte(offset + 1);
/** * Gets the {@code unsigned byte} value at a particular offset. * * @param off {@code >= 0, < size();} offset to fetch * @return {@code unsigned byte} at that offset */ public int getUnsignedByte(int off) { checkOffsets(off, off + 1); return getUnsignedByte0(off); }
/** * Gets the {@code signed byte} value at a particular offset. * * @param off {@code >= 0, < size();} offset to fetch * @return {@code signed byte} at that offset */ public int getByte(int off) { checkOffsets(off, off + 1); return getByte0(off); }
ConstantPool pool, ParseObserver observer, int count, boolean typeTable) { if (bytes.size() != (count * 10)) { ByteArray.MyDataInputStream in = bytes.makeDataInputStream(); LocalVariableList list = new LocalVariableList(count);
/** * Constructs an instance. * * @param cf {@code non-null;} class file to parse from * @param offset {@code >= 0;} offset into the class file data to parse at * @param length {@code >= 0;} number of bytes left in the attribute data * @param observer {@code null-ok;} parse observer to notify, if any */ public AnnotationParser(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (cf == null) { throw new NullPointerException("cf == null"); } this.cf = cf; this.pool = cf.getConstantPool(); this.observer = observer; this.bytes = cf.getBytes().slice(offset, offset + length); this.input = bytes.makeDataInputStream(); this.parseCursor = 0; }