com.android.dx.dex.code.DalvInsnList Java Examples

The following examples show how to use com.android.dx.dex.code.DalvInsnList. 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: DebugInfoDecoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #2
Source File: CodeItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Does a human-friendly dump of this instance.
 *
 * @param out {@code non-null;} where to dump
 * @param prefix {@code non-null;} per-line prefix to use
 * @param verbose whether to be verbose with the output
 */
public void debugPrint(PrintWriter out, String prefix, boolean verbose) {
    out.println(ref.toHuman() + ":");

    DalvInsnList insns = code.getInsns();
    out.println("regs: " + Hex.u2(getRegistersSize()) +
            "; ins: " + Hex.u2(getInsSize()) + "; outs: " +
            Hex.u2(getOutsSize()));

    insns.debugPrint(out, prefix, verbose);

    String prefix2 = prefix + "  ";

    if (catches != null) {
        out.print(prefix);
        out.println("catches");
        catches.debugPrint(out, prefix2);
    }

    if (debugInfo != null) {
        out.print(prefix);
        out.println("debug info");
        debugInfo.debugPrint(out, prefix2);
    }
}
 
Example #3
Source File: DebugInfoItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #4
Source File: DebugInfoDecoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #5
Source File: CodeItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Does a human-friendly dump of this instance.
 *
 * @param out {@code non-null;} where to dump
 * @param prefix {@code non-null;} per-line prefix to use
 * @param verbose whether to be verbose with the output
 */
public void debugPrint(PrintWriter out, String prefix, boolean verbose) {
    out.println(ref.toHuman() + ":");

    DalvInsnList insns = code.getInsns();
    out.println("regs: " + Hex.u2(getRegistersSize()) +
            "; ins: " + Hex.u2(getInsSize()) + "; outs: " +
            Hex.u2(getOutsSize()));

    insns.debugPrint(out, prefix, verbose);

    String prefix2 = prefix + "  ";

    if (catches != null) {
        out.print(prefix);
        out.println("catches");
        catches.debugPrint(out, prefix2);
    }

    if (debugInfo != null) {
        out.print(prefix);
        out.println("debug info");
        debugInfo.debugPrint(out, prefix2);
    }
}
 
Example #6
Source File: DebugInfoItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #7
Source File: DebugInfoDecoder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #8
Source File: CodeItem.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Does a human-friendly dump of this instance.
 *
 * @param out {@code non-null;} where to dump
 * @param prefix {@code non-null;} per-line prefix to use
 * @param verbose whether to be verbose with the output
 */
public void debugPrint(PrintWriter out, String prefix, boolean verbose) {
    out.println(ref.toHuman() + ":");

    DalvInsnList insns = code.getInsns();
    out.println("regs: " + Hex.u2(getRegistersSize()) +
            "; ins: " + Hex.u2(getInsSize()) + "; outs: " +
            Hex.u2(getOutsSize()));

    insns.debugPrint(out, prefix, verbose);

    String prefix2 = prefix + "  ";

    if (catches != null) {
        out.print(prefix);
        out.println("catches");
        catches.debugPrint(out, prefix2);
    }

    if (debugInfo != null) {
        out.print(prefix);
        out.println("debug info");
        debugInfo.debugPrint(out, prefix2);
    }
}
 
Example #9
Source File: DebugInfoItem.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #10
Source File: DebugInfoDecoder.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #11
Source File: CodeItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Does a human-friendly dump of this instance.
 *
 * @param out {@code non-null;} where to dump
 * @param prefix {@code non-null;} per-line prefix to use
 * @param verbose whether to be verbose with the output
 */
public void debugPrint(PrintWriter out, String prefix, boolean verbose) {
    out.println(ref.toHuman() + ":");

    DalvInsnList insns = code.getInsns();
    out.println("regs: " + Hex.u2(getRegistersSize()) +
            "; ins: " + Hex.u2(getInsSize()) + "; outs: " +
            Hex.u2(getOutsSize()));

    insns.debugPrint(out, prefix, verbose);

    String prefix2 = prefix + "  ";

    if (catches != null) {
        out.print(prefix);
        out.println("catches");
        catches.debugPrint(out, prefix2);
    }

    if (debugInfo != null) {
        out.print(prefix);
        out.println("debug info");
        debugInfo.debugPrint(out, prefix2);
    }
}
 
Example #12
Source File: DebugInfoItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #encode} to do most of the work.
 *
 * @param file {@code null-ok;} file to refer to during encoding
 * @param prefix {@code null-ok;} prefix to attach to each line of output
 * @param debugPrint {@code null-ok;} if specified, an alternate output for
 * annotations
 * @param out {@code null-ok;} if specified, where annotations should go
 * @param consume whether to claim to have consumed output for
 * {@code out}
 * @return {@code non-null;} the encoded array
 */
private byte[] encode0(DexFile file, String prefix, PrintWriter debugPrint,
        AnnotatedOutput out, boolean consume) {
    PositionList positions = code.getPositions();
    LocalList locals = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int regSize = insns.getRegistersSize();

    DebugInfoEncoder encoder =
        new DebugInfoEncoder(positions, locals,
                file, codeSize, regSize, isStatic, ref);

    byte[] result;

    if ((debugPrint == null) && (out == null)) {
        result = encoder.convert();
    } else {
        result = encoder.convertAndAnnotate(prefix, debugPrint, out,
                consume);
    }

    return result;
}
 
Example #13
Source File: CodeItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #writeTo0} which writes out the actual bytecode.
 *
 * @param file {@code non-null;} file we are part of
 * @param out {@code non-null;} where to write to
 */
private void writeCodes(DexFile file, AnnotatedOutput out) {
    DalvInsnList insns = code.getInsns();

    try {
        insns.writeTo(out);
    } catch (RuntimeException ex) {
        throw ExceptionWithContext.withContext(ex, "...while writing " +
                "instructions for " + ref.toHuman());
    }
}
 
Example #14
Source File: CodeItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #writeTo0} which writes out the actual bytecode.
 *
 * @param file {@code non-null;} file we are part of
 * @param out {@code non-null;} where to write to
 */
private void writeCodes(DexFile file, AnnotatedOutput out) {
    DalvInsnList insns = code.getInsns();

    try {
        insns.writeTo(out);
    } catch (RuntimeException ex) {
        throw ExceptionWithContext.withContext(ex, "...while writing " +
                "instructions for " + ref.toHuman());
    }
}
 
Example #15
Source File: CodeItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #writeTo0} which writes out the actual bytecode.
 *
 * @param file {@code non-null;} file we are part of
 * @param out {@code non-null;} where to write to
 */
private void writeCodes(DexFile file, AnnotatedOutput out) {
    DalvInsnList insns = code.getInsns();

    try {
        insns.writeTo(out);
    } catch (RuntimeException ex) {
        throw ExceptionWithContext.withContext(ex, "...while writing " +
                "instructions for " + ref.toHuman());
    }
}
 
Example #16
Source File: CodeItem.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #writeTo0} which writes out the actual bytecode.
 *
 * @param file {@code non-null;} file we are part of
 * @param out {@code non-null;} where to write to
 */
private void writeCodes(DexFile file, AnnotatedOutput out) {
    DalvInsnList insns = code.getInsns();

    try {
        insns.writeTo(out);
    } catch (RuntimeException ex) {
        throw ExceptionWithContext.withContext(ex, "...while writing " +
                "instructions for " + ref.toHuman());
    }
}