com.android.dex.DexException Java Examples

The following examples show how to use com.android.dex.DexException. 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: InstructionTransformer.java    From Box with Apache License 2.0 6 votes vote down vote up
public short[] transform(IndexMap indexMap, short[] encodedInstructions) throws DexException {
    DecodedInstruction[] decodedInstructions =
        DecodedInstruction.decodeAll(encodedInstructions);
    int size = decodedInstructions.length;

    this.indexMap = indexMap;
    mappedInstructions = new DecodedInstruction[size];
    mappedAt = 0;
    reader.visitAll(decodedInstructions);

    ShortArrayCodeOutput out = new ShortArrayCodeOutput(size);
    for (DecodedInstruction instruction : mappedInstructions) {
        if (instruction != null) {
            instruction.encode(out);
        }
    }

    this.indexMap = null;
    return out.getArray();
}
 
Example #2
Source File: DecodedInstruction.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Decodes an array of instructions. The result has non-null
 * elements at each offset that represents the start of an
 * instruction.
 */
public static DecodedInstruction[] decodeAll(short[] encodedInstructions) {
    int size = encodedInstructions.length;
    DecodedInstruction[] decoded = new DecodedInstruction[size];
    ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions);

    try {
        while (in.hasMore()) {
            decoded[in.cursor()] = DecodedInstruction.decode(in);
        }
    } catch (EOFException ex) {
        throw new DexException(ex);
    }

    return decoded;
}
 
Example #3
Source File: DecodedInstruction.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Decodes an array of instructions. The result has non-null
 * elements at each offset that represents the start of an
 * instruction.
 */
public static DecodedInstruction[] decodeAll(short[] encodedInstructions) {
    int size = encodedInstructions.length;
    DecodedInstruction[] decoded = new DecodedInstruction[size];
    ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions);

    try {
        while (in.hasMore()) {
            decoded[in.cursor()] = DecodedInstruction.decode(in);
        }
    } catch (EOFException ex) {
        throw new DexException(ex);
    }

    return decoded;
}
 
Example #4
Source File: InstructionTransformer.java    From Box with Apache License 2.0 6 votes vote down vote up
public short[] transform(IndexMap indexMap, short[] encodedInstructions) throws DexException {
    DecodedInstruction[] decodedInstructions =
        DecodedInstruction.decodeAll(encodedInstructions);
    int size = decodedInstructions.length;

    this.indexMap = indexMap;
    mappedInstructions = new DecodedInstruction[size];
    mappedAt = 0;
    reader.visitAll(decodedInstructions);

    ShortArrayCodeOutput out = new ShortArrayCodeOutput(size);
    for (DecodedInstruction instruction : mappedInstructions) {
        if (instruction != null) {
            instruction.encode(out);
        }
    }

    this.indexMap = null;
    return out.getArray();
}
 
Example #5
Source File: InstructionTransformer.java    From buck with Apache License 2.0 6 votes vote down vote up
public short[] transform(IndexMap indexMap, short[] encodedInstructions) throws DexException {
    DecodedInstruction[] decodedInstructions =
        DecodedInstruction.decodeAll(encodedInstructions);
    int size = decodedInstructions.length;

    this.indexMap = indexMap;
    mappedInstructions = new DecodedInstruction[size];
    mappedAt = 0;
    reader.visitAll(decodedInstructions);

    ShortArrayCodeOutput out = new ShortArrayCodeOutput(size);
    for (DecodedInstruction instruction : mappedInstructions) {
        if (instruction != null) {
            instruction.encode(out);
        }
    }

    this.indexMap = null;
    return out.getArray();
}
 
Example #6
Source File: DecodedInstruction.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Decodes an array of instructions. The result has non-null
 * elements at each offset that represents the start of an
 * instruction.
 */
public static DecodedInstruction[] decodeAll(short[] encodedInstructions) {
    int size = encodedInstructions.length;
    DecodedInstruction[] decoded = new DecodedInstruction[size];
    ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions);

    try {
        while (in.hasMore()) {
            decoded[in.cursor()] = DecodedInstruction.decode(in);
        }
    } catch (EOFException ex) {
        throw new DexException(ex);
    }

    return decoded;
}
 
Example #7
Source File: MergeConflictTest.java    From buck with Apache License 2.0 6 votes vote down vote up
public void testMergeConflict() throws IOException {
    Dex a = resourceToDexBuffer("/testdata/A.dex");
    Dex b = resourceToDexBuffer("/testdata/B.dex");

    // a and b don't overlap; this should succeed
    Dex ab = new DexMerger(a, b, CollisionPolicy.FAIL).merge();

    // a and ab overlap; this should fail
    DexMerger dexMerger = new DexMerger(a, ab, CollisionPolicy.FAIL);
    try {
        dexMerger.merge();
        fail();
    } catch (DexException expected) {
        assertEquals("Multiple dex files define Ltestdata/A;", expected.getMessage());
    }
}
 
Example #8
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the literal value, masked to be a byte in size. This will
 * throw if the value is out of the range of a signed byte.
 */
public final int getLiteralByte() {
    if (literal != (byte) literal) {
        throw new DexException("Literal out of range: " + Hex.u8(literal));
    }

    return (int) literal & 0xff;
}
 
Example #9
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the D register number, as a nibble. This will throw if the
 * value is out of the range of an unsigned nibble.
 */
public final short getDNibble() {
    int d = getD();

    if ((d & ~0xf) != 0) {
        throw new DexException("Register D out of range: " + Hex.u8(d));
    }

    return (short) d;
}
 
Example #10
Source File: CodeReader.java    From Box with Apache License 2.0 5 votes vote down vote up
public void visitAll(DecodedInstruction[] decodedInstructions)
        throws DexException {
    int size = decodedInstructions.length;

    for (int i = 0; i < size; i++) {
        DecodedInstruction one = decodedInstructions[i];
        if (one == null) {
            continue;
        }

        callVisit(decodedInstructions, one);
    }
}
 
Example #11
Source File: OutputFinisher.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the proper opcode for the given instruction, ignoring
 * register constraints.
 *
 * @param insn {@code non-null;} the instruction in question
 * @return {@code non-null;} the opcode that fits
 */
private Dop findExpandedOpcodeForInsn(DalvInsn insn) {
    Dop result = findOpcodeForInsn(insn.getLowRegVersion(), insn.getOpcode());
    if (result == null) {
        throw new DexException("No expanded opcode for " + insn);
    }
    return result;
}
 
Example #12
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the C register number, as a nibble. This will throw if the
 * value is out of the range of an unsigned nibble.
 */
public final short getCNibble() {
    int c = getC();

    if ((c & ~0xf) != 0) {
        throw new DexException("Register C out of range: " + Hex.u8(c));
    }

    return (short) c;
}
 
Example #13
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the target as a relative offset from the given base
 * address, as a code unit. This will throw if the value is out of
 * the range of a signed code unit.
 */
public final short getTargetUnit(int baseAddress) {
    int relativeTarget = getTarget(baseAddress);

    if (relativeTarget != (short) relativeTarget) {
        throw new DexException("Target out of range: "
                + Hex.s4(relativeTarget));
    }

    return (short) relativeTarget;
}
 
Example #14
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the target as a relative offset from the given base
 * address, masked to be a byte in size. This will throw if the
 * value is out of the range of a signed byte.
 */
public final int getTargetByte(int baseAddress) {
    int relativeTarget = getTarget(baseAddress);

    if (relativeTarget != (byte) relativeTarget) {
        throw new DexException("Target out of range: "
                + Hex.s4(relativeTarget));
    }

    return relativeTarget & 0xff;
}
 
Example #15
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the literal value, masked to be an int in size. This will
 * throw if the value is out of the range of a signed int.
 */
public final int getLiteralInt() {
    if (literal != (int) literal) {
        throw new DexException("Literal out of range: " + Hex.u8(literal));
    }

    return (int) literal;
}
 
Example #16
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the literal value, as a code unit. This will throw if the
 * value is out of the range of a signed code unit.
 */
public final short getLiteralUnit() {
    if (literal != (short) literal) {
        throw new DexException("Literal out of range: " + Hex.u8(literal));
    }

    return (short) literal;
}
 
Example #17
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the register count, as a code unit. This will throw if the
 * value is out of the range of an unsigned code unit.
 */
public final short getRegisterCountUnit() {
    int registerCount = getRegisterCount();

    if ((registerCount & ~0xffff) != 0) {
        throw new DexException("Register count out of range: "
                + Hex.u8(registerCount));
    }

    return (short) registerCount;
}
 
Example #18
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the A register number, as a byte. This will throw if the
 * value is out of the range of an unsigned byte.
 */
public final short getAByte() {
    int a = getA();

    if ((a & ~0xff) != 0) {
        throw new DexException("Register A out of range: " + Hex.u8(a));
    }

    return (short) a;
}
 
Example #19
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the D register number, as a nibble. This will throw if the
 * value is out of the range of an unsigned nibble.
 */
public final short getDNibble() {
    int d = getD();

    if ((d & ~0xf) != 0) {
        throw new DexException("Register D out of range: " + Hex.u8(d));
    }

    return (short) d;
}
 
Example #20
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the D register number, as a byte. This will throw if the
 * value is out of the range of an unsigned byte.
 */
public final short getDByte() {
    int d = getD();

    if ((d & ~0xff) != 0) {
        throw new DexException("Register D out of range: " + Hex.u8(d));
    }

    return (short) d;
}
 
Example #21
Source File: DecodedInstruction.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the D register number, as a byte. This will throw if the
 * value is out of the range of an unsigned byte.
 */
public final short getDByte() {
    int d = getD();

    if ((d & ~0xff) != 0) {
        throw new DexException("Register D out of range: " + Hex.u8(d));
    }

    return (short) d;
}
 
Example #22
Source File: DecodedInstruction.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the literal value, masked to be an int in size. This will
 * throw if the value is out of the range of a signed int.
 */
public final int getLiteralInt() {
    if (literal != (int) literal) {
        throw new DexException("Literal out of range: " + Hex.u8(literal));
    }

    return (int) literal;
}
 
Example #23
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the C register number, as a byte. This will throw if the
 * value is out of the range of an unsigned byte.
 */
public final short getCByte() {
    int c = getC();

    if ((c & ~0xff) != 0) {
        throw new DexException("Register C out of range: " + Hex.u8(c));
    }

    return (short) c;
}
 
Example #24
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the C register number, as a code unit. This will throw if the
 * value is out of the range of an unsigned code unit.
 */
public final short getCUnit() {
    int c = getC();

    if ((c & ~0xffff) != 0) {
        throw new DexException("Register C out of range: " + Hex.u8(c));
    }

    return (short) c;
}
 
Example #25
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the B register number, as a nibble. This will throw if the
 * value is out of the range of an unsigned nibble.
 */
public final short getBNibble() {
    int b = getB();

    if ((b & ~0xf) != 0) {
        throw new DexException("Register B out of range: " + Hex.u8(b));
    }

    return (short) b;
}
 
Example #26
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the B register number, as a byte. This will throw if the
 * value is out of the range of an unsigned byte.
 */
public final short getBByte() {
    int b = getB();

    if ((b & ~0xff) != 0) {
        throw new DexException("Register B out of range: " + Hex.u8(b));
    }

    return (short) b;
}
 
Example #27
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the B register number, as a code unit. This will throw if the
 * value is out of the range of an unsigned code unit.
 */
public final short getBUnit() {
    int b = getB();

    if ((b & ~0xffff) != 0) {
        throw new DexException("Register B out of range: " + Hex.u8(b));
    }

    return (short) b;
}
 
Example #28
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the A register number, as a nibble. This will throw if the
 * value is out of the range of an unsigned nibble.
 */
public final short getANibble() {
    int a = getA();

    if ((a & ~0xf) != 0) {
        throw new DexException("Register A out of range: " + Hex.u8(a));
    }

    return (short) a;
}
 
Example #29
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the A register number, as a byte. This will throw if the
 * value is out of the range of an unsigned byte.
 */
public final short getAByte() {
    int a = getA();

    if ((a & ~0xff) != 0) {
        throw new DexException("Register A out of range: " + Hex.u8(a));
    }

    return (short) a;
}
 
Example #30
Source File: DecodedInstruction.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the A register number, as a code unit. This will throw if the
 * value is out of the range of an unsigned code unit.
 */
public final short getAUnit() {
    int a = getA();

    if ((a & ~0xffff) != 0) {
        throw new DexException("Register A out of range: " + Hex.u8(a));
    }

    return (short) a;
}