/** * Writes a code unit. */ public void write(short codeUnit) { ensureArrayLength(1); array[cursor()] = codeUnit; advance(1); }
public void visitPackedSwitchPayloadInsn(int currentAddress, int opcode, int firstKey, int[] targets) { int baseAddress = codeOut.baseAddressForCursor(); short opcodeUnit = (short) opcode; codeOut.write(opcodeUnit); codeOut.write(InstructionCodec.asUnsignedUnit(targets.length)); codeOut.writeInt(firstKey); if (this.hasPromoter) { for (int target : targets) { target = this.insnPromoter.getPromotedAddress(target); codeOut.writeInt(target - baseAddress); } } else { for (int target : targets) { codeOut.writeInt(target - baseAddress); } } }
/** * Writes the contents of the given array. */ public void write(long[] data) { for (long l : data) { writeLong(l); } }
public void visitFillArrayDataPayloadInsn(int currentAddress, int opcode, Object data, int size, int elementWidth) { short opcodeUnit = (short) opcode; codeOut.write(opcodeUnit); codeOut.write(elementWidthUnit); codeOut.writeInt(size); codeOut.write((byte[]) data); break; codeOut.write((short[]) data); break; codeOut.write((int[]) data); break; codeOut.write((long[]) data); break;
public short[] transform(short[] encodedInstructions) throws DexException { ShortArrayCodeOutput out = new ShortArrayCodeOutput(encodedInstructions.length); InstructionPromoter ipmo = new InstructionPromoter(); InstructionWriter iw = new InstructionWriter(out, ipmo); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(encodedInstructions)); try { // First visit, we collect mappings from original target address to promoted target address. ir.accept(new InstructionTransformVisitor(ipmo)); // Then do the real transformation work. ir.accept(new InstructionTransformVisitor(iw)); } catch (EOFException e) { throw new DexException(e); } return out.getArray(); }
case Opcodes.CONST_4: { short opcodeUnit = (short) opcode; codeOut.write( InstructionCodec.codeUnit( opcodeUnit, case Opcodes.MONITOR_EXIT: case Opcodes.THROW: { codeOut.write(InstructionCodec.codeUnit(opcode, a)); break; case Opcodes.IF_GTZ: case Opcodes.IF_LEZ: { short relativeTarget = InstructionCodec.getTargetUnit(target, codeOut.cursor()); codeOut.write(InstructionCodec.codeUnit(opcode, a), relativeTarget); break; codeOut.write(InstructionCodec.codeUnit(opcode, a), InstructionCodec.getLiteralUnit(literal)); break; int shift = (opcode == Opcodes.CONST_HIGH16) ? 16 : 48; short literalShifted = (short) (literal >> shift); codeOut.write(InstructionCodec.codeUnit(opcode, a), literalShifted); break; if (this.hasPromoter) { if (index > 0xFFFF) { codeOut.write( InstructionCodec.codeUnit(Opcodes.CONST_STRING_JUMBO, a),
case Opcodes.RETURN_VOID: { short opcodeUnit = (short) opcode; codeOut.write(opcodeUnit); break; int relativeTarget = InstructionCodec.getTarget(target, codeOut.cursor()); if (relativeTarget != (byte) relativeTarget) { if (relativeTarget != (short) relativeTarget) { short opcodeUnit = (short) Opcodes.GOTO_32; codeOut.write(opcodeUnit, InstructionCodec.unit0(relativeTarget), InstructionCodec.unit1(relativeTarget)); } else { short shortRelativeTarget = (short) relativeTarget; short opcodeUnit = (short) Opcodes.GOTO_16; codeOut.write(opcodeUnit, shortRelativeTarget); codeOut.write(InstructionCodec.codeUnit(opcode, relativeTarget)); int relativeTarget = InstructionCodec.getTargetByte(target, codeOut.cursor()); codeOut.write(InstructionCodec.codeUnit(opcode, relativeTarget)); int relativeTarget = InstructionCodec.getTarget(target, codeOut.cursor()); if (relativeTarget != (short) relativeTarget) { short opcodeUnit = (short) Opcodes.GOTO_32; codeOut.write(opcodeUnit, InstructionCodec.unit0(relativeTarget), InstructionCodec.unit1(relativeTarget)); } else { short shortRelativeTarget = (short) relativeTarget; short opcodeUnit = (short) opcode; codeOut.write(opcodeUnit, shortRelativeTarget);
private void ensureArrayLength(int shortCountToWrite) { int currPos = cursor(); if (array.length - currPos < shortCountToWrite) { short[] newArray = new short[array.length + (array.length >> 1)]; System.arraycopy(array, 0, newArray, 0, currPos); array = newArray; } } }
/** * Writes the contents of the given array. */ public void write(int[] data) { for (int i : data) { writeInt(i); } }
public short[] transform(short[] encodedInstructions) throws DexException { ShortArrayCodeOutput out = new ShortArrayCodeOutput(encodedInstructions.length); InstructionPromoter ipmo = new InstructionPromoter(); InstructionWriter iw = new InstructionWriter(out, ipmo); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(encodedInstructions)); try { // First visit, we collect mappings from original target address to promoted target address. ir.accept(new InstructionTransformVisitor(ipmo)); // Then do the real transformation work. ir.accept(new InstructionTransformVisitor(iw)); } catch (EOFException e) { throw new DexException(e); } return out.getArray(); }
case Opcodes.CONST_4: { short opcodeUnit = (short) opcode; codeOut.write( InstructionCodec.codeUnit( opcodeUnit, case Opcodes.MONITOR_EXIT: case Opcodes.THROW: { codeOut.write(InstructionCodec.codeUnit(opcode, a)); break; case Opcodes.IF_GTZ: case Opcodes.IF_LEZ: { short relativeTarget = InstructionCodec.getTargetUnit(target, codeOut.cursor()); codeOut.write(InstructionCodec.codeUnit(opcode, a), relativeTarget); break; codeOut.write(InstructionCodec.codeUnit(opcode, a), InstructionCodec.getLiteralUnit(literal)); break; int shift = (opcode == Opcodes.CONST_HIGH16) ? 16 : 48; short literalShifted = (short) (literal >> shift); codeOut.write(InstructionCodec.codeUnit(opcode, a), literalShifted); break; if (this.hasPromoter) { if (index > 0xFFFF) { codeOut.write( InstructionCodec.codeUnit(Opcodes.CONST_STRING_JUMBO, a),
case Opcodes.REM_DOUBLE_2ADDR: { short opcodeUnit = (short) opcode; codeOut.write( InstructionCodec.codeUnit( opcodeUnit, case Opcodes.MOVE_WIDE_FROM16: case Opcodes.MOVE_OBJECT_FROM16: { codeOut.write( InstructionCodec.codeUnit(opcode, a), InstructionCodec.getBUnit(b) case Opcodes.SHR_INT_LIT8: case Opcodes.USHR_INT_LIT8: { codeOut.write( InstructionCodec.codeUnit(opcode, a), InstructionCodec.codeUnit(b, InstructionCodec.getLiteralByte(literal)) case Opcodes.IF_GT: case Opcodes.IF_LE: { short relativeTarget = InstructionCodec.getTargetUnit(target, codeOut.cursor()); codeOut.write( InstructionCodec.codeUnit( opcode, case Opcodes.OR_INT_LIT16: case Opcodes.XOR_INT_LIT16: { codeOut.write( InstructionCodec.codeUnit(
public void visitFillArrayDataPayloadInsn(int currentAddress, int opcode, Object data, int size, int elementWidth) { short opcodeUnit = (short) opcode; codeOut.write(opcodeUnit); codeOut.write(elementWidthUnit); codeOut.writeInt(size); codeOut.write((byte[]) data); break; codeOut.write((short[]) data); break; codeOut.write((int[]) data); break; codeOut.write((long[]) data); break;
/** * Gets the array. The returned array contains exactly the data * written (e.g. no leftover space at the end). */ public short[] getArray() { int cursor = cursor(); if (cursor == array.length) { return array; } short[] result = new short[cursor]; System.arraycopy(array, 0, result, 0, cursor); return result; }
/** * Writes the contents of the given array. */ public void write(int[] data) { for (int i : data) { writeInt(i); } }
public void visitSparseSwitchPayloadInsn(int currentAddress, int opcode, int[] keys, int[] targets) { int baseAddress = codeOut.baseAddressForCursor(); short opcodeUnit = (short) opcode; codeOut.write(opcodeUnit); codeOut.write(InstructionCodec.asUnsignedUnit(targets.length)); for (int key : keys) { codeOut.writeInt(key); } if (this.hasPromoter) { for (int target : targets) { target = this.insnPromoter.getPromotedAddress(target); codeOut.writeInt(target - baseAddress); } } else { for (int target : targets) { codeOut.writeInt(target - baseAddress); } } }
public short[] transform(short[] encodedInstructions) throws DexException { ShortArrayCodeOutput out = new ShortArrayCodeOutput(encodedInstructions.length); InstructionPromoter ipmo = new InstructionPromoter(); InstructionWriter iw = new InstructionWriter(out, ipmo); InstructionReader ir = new InstructionReader(new ShortArrayCodeInput(encodedInstructions)); try { // First visit, we collect mappings from original target address to promoted target address. ir.accept(new InstructionTransformVisitor(ipmo)); // Then do the real transformation work. ir.accept(new InstructionTransformVisitor(iw)); } catch (EOFException e) { throw new DexException(e); } return out.getArray(); }
/** * Writes the contents of the given array. */ public void write(short[] data) { for (short unit : data) { write(unit); } }