Java Code Examples for com.android.dx.rop.code.InsnList#setImmutable()

The following examples show how to use com.android.dx.rop.code.InsnList#setImmutable() . 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: Label.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
BasicBlock toBasicBlock() {
    InsnList result = new InsnList(instructions.size());
    for (int i = 0; i < instructions.size(); i++) {
        result.set(i, instructions.get(i));
    }
    result.setImmutable();

    int primarySuccessorIndex = -1;
    IntList successors = new IntList();
    for (Label catchLabel : catchLabels) {
        successors.add(catchLabel.id);
    }
    if (primarySuccessor != null) {
        primarySuccessorIndex = primarySuccessor.id;
        successors.add(primarySuccessorIndex);
    }
    if (alternateSuccessor != null) {
        successors.add(alternateSuccessor.id);
    }
    successors.setImmutable();

    return new BasicBlock(id, result, successors, primarySuccessorIndex);
}
 
Example 2
Source File: Label.java    From dexmaker with Apache License 2.0 6 votes vote down vote up
BasicBlock toBasicBlock() {
    InsnList result = new InsnList(instructions.size());
    for (int i = 0; i < instructions.size(); i++) {
        result.set(i, instructions.get(i));
    }
    result.setImmutable();

    int primarySuccessorIndex = -1;
    IntList successors = new IntList();
    for (Label catchLabel : catchLabels) {
        successors.add(catchLabel.id);
    }
    if (primarySuccessor != null) {
        primarySuccessorIndex = primarySuccessor.id;
        successors.add(primarySuccessorIndex);
    }
    if (alternateSuccessor != null) {
        successors.add(alternateSuccessor.id);
    }
    successors.setImmutable();

    return new BasicBlock(id, result, successors, primarySuccessorIndex);
}
 
Example 3
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all {@code move-return-address} instructions, returning a new
 * {@code InsnList} if necessary. The {@code move-return-address}
 * insns are dead code after subroutines have been inlined.
 *
 * @param insns {@code InsnList} that may contain
 * {@code move-return-address} insns
 * @return {@code InsnList} with {@code move-return-address} removed
 */
private InsnList filterMoveReturnAddressInsns(InsnList insns) {
    int sz;
    int newSz = 0;

    // First see if we need to filter, and if so what the new size will be
    sz = insns.size();
    for (int i = 0; i < sz; i++) {
        if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newSz++;
        }
    }

    if (newSz == sz) {
        return insns;
    }

    // Make a new list without the MOVE_RETURN_ADDRESS insns
    InsnList newInsns = new InsnList(newSz);

    int newIndex = 0;
    for (int i = 0; i < sz; i++) {
        Insn insn = insns.get(i);
        if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newInsns.set(newIndex++, insn);
        }
    }

    newInsns.setImmutable();
    return newInsns;
}
 
Example 4
Source File: SsaToRop.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an insn list to rop form.
 *
 * @param ssaInsns {@code non-null;} old instructions
 * @return {@code non-null;} immutable instruction list
 */
private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns) {
    int insnCount = ssaInsns.size();
    InsnList result = new InsnList(insnCount);

    for (int i = 0; i < insnCount; i++) {
        result.set(i, ssaInsns.get(i).toRopInsn());
    }

    result.setImmutable();

    return result;
}
 
Example 5
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all {@code move-return-address} instructions, returning a new
 * {@code InsnList} if necessary. The {@code move-return-address}
 * insns are dead code after subroutines have been inlined.
 *
 * @param insns {@code InsnList} that may contain
 * {@code move-return-address} insns
 * @return {@code InsnList} with {@code move-return-address} removed
 */
private InsnList filterMoveReturnAddressInsns(InsnList insns) {
    int sz;
    int newSz = 0;

    // First see if we need to filter, and if so what the new size will be
    sz = insns.size();
    for (int i = 0; i < sz; i++) {
        if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newSz++;
        }
    }

    if (newSz == sz) {
        return insns;
    }

    // Make a new list without the MOVE_RETURN_ADDRESS insns
    InsnList newInsns = new InsnList(newSz);

    int newIndex = 0;
    for (int i = 0; i < sz; i++) {
        Insn insn = insns.get(i);
        if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newInsns.set(newIndex++, insn);
        }
    }

    newInsns.setImmutable();
    return newInsns;
}
 
Example 6
Source File: SsaToRop.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an insn list to rop form.
 *
 * @param ssaInsns {@code non-null;} old instructions
 * @return {@code non-null;} immutable instruction list
 */
private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns) {
    int insnCount = ssaInsns.size();
    InsnList result = new InsnList(insnCount);

    for (int i = 0; i < insnCount; i++) {
        result.set(i, ssaInsns.get(i).toRopInsn());
    }

    result.setImmutable();

    return result;
}
 
Example 7
Source File: Ropper.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all {@code move-return-address} instructions, returning a new
 * {@code InsnList} if necessary. The {@code move-return-address}
 * insns are dead code after subroutines have been inlined.
 *
 * @param insns {@code InsnList} that may contain
 * {@code move-return-address} insns
 * @return {@code InsnList} with {@code move-return-address} removed
 */
private InsnList filterMoveReturnAddressInsns(InsnList insns) {
    int sz;
    int newSz = 0;

    // First see if we need to filter, and if so what the new size will be
    sz = insns.size();
    for (int i = 0; i < sz; i++) {
        if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newSz++;
        }
    }

    if (newSz == sz) {
        return insns;
    }

    // Make a new list without the MOVE_RETURN_ADDRESS insns
    InsnList newInsns = new InsnList(newSz);

    int newIndex = 0;
    for (int i = 0; i < sz; i++) {
        Insn insn = insns.get(i);
        if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newInsns.set(newIndex++, insn);
        }
    }

    newInsns.setImmutable();
    return newInsns;
}
 
Example 8
Source File: SsaToRop.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an insn list to rop form.
 *
 * @param ssaInsns {@code non-null;} old instructions
 * @return {@code non-null;} immutable instruction list
 */
private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns) {
    int insnCount = ssaInsns.size();
    InsnList result = new InsnList(insnCount);

    for (int i = 0; i < insnCount; i++) {
        result.set(i, ssaInsns.get(i).toRopInsn());
    }

    result.setImmutable();

    return result;
}
 
Example 9
Source File: Ropper.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all {@code move-return-address} instructions, returning a new
 * {@code InsnList} if necessary. The {@code move-return-address}
 * insns are dead code after subroutines have been inlined.
 *
 * @param insns {@code InsnList} that may contain
 * {@code move-return-address} insns
 * @return {@code InsnList} with {@code move-return-address} removed
 */
private InsnList filterMoveReturnAddressInsns(InsnList insns) {
    int sz;
    int newSz = 0;

    // First see if we need to filter, and if so what the new size will be
    sz = insns.size();
    for (int i = 0; i < sz; i++) {
        if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newSz++;
        }
    }

    if (newSz == sz) {
        return insns;
    }

    // Make a new list without the MOVE_RETURN_ADDRESS insns
    InsnList newInsns = new InsnList(newSz);

    int newIndex = 0;
    for (int i = 0; i < sz; i++) {
        Insn insn = insns.get(i);
        if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
            newInsns.set(newIndex++, insn);
        }
    }

    newInsns.setImmutable();
    return newInsns;
}
 
Example 10
Source File: SsaToRop.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an insn list to rop form.
 *
 * @param ssaInsns {@code non-null;} old instructions
 * @return {@code non-null;} immutable instruction list
 */
private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns) {
    int insnCount = ssaInsns.size();
    InsnList result = new InsnList(insnCount);

    for (int i = 0; i < insnCount; i++) {
        result.set(i, ssaInsns.get(i).toRopInsn());
    }

    result.setImmutable();

    return result;
}