Search in sources :

Example 1 with AddressInsn

use of soot.toDex.instructions.AddressInsn in project soot by Sable.

the class StmtVisitor method addPayloads.

private void addPayloads() {
    // add switch payloads to the end of the insns
    for (AbstractPayload payload : payloads) {
        addInsn(new AddressInsn(payload), null);
        addInsn(payload, null);
    }
}
Also used : AddressInsn(soot.toDex.instructions.AddressInsn) AbstractPayload(soot.toDex.instructions.AbstractPayload)

Example 2 with AddressInsn

use of soot.toDex.instructions.AddressInsn in project soot by Sable.

the class StmtVisitor method getRealInsns.

public List<BuilderInstruction> getRealInsns(LabelAssigner labelAssigner) {
    List<BuilderInstruction> finalInsns = new ArrayList<BuilderInstruction>();
    for (Insn i : insns) {
        if (i instanceof AddressInsn) {
            // skip non-insns
            continue;
        }
        BuilderInstruction realInsn = i.getRealInsn(labelAssigner);
        finalInsns.add(realInsn);
        if (insnStmtMap.containsKey(i)) {
            // get tags
            instructionInsnMap.put(realInsn, i);
        }
        LocalRegisterAssignmentInformation assignmentInfo = insnRegisterMap.get(i);
        if (assignmentInfo != null)
            instructionRegisterMap.put(realInsn, assignmentInfo);
        if (i instanceof AbstractPayload)
            instructionPayloadMap.put(realInsn, (AbstractPayload) i);
    }
    return finalInsns;
}
Also used : AddressInsn(soot.toDex.instructions.AddressInsn) Insn(soot.toDex.instructions.Insn) BuilderInstruction(org.jf.dexlib2.builder.BuilderInstruction) ArrayList(java.util.ArrayList) AddressInsn(soot.toDex.instructions.AddressInsn) AbstractPayload(soot.toDex.instructions.AbstractPayload)

Example 3 with AddressInsn

use of soot.toDex.instructions.AddressInsn in project soot by Sable.

the class RegisterAssigner method getRegsNeeded.

/**
 * Gets the maximum number of registers needed by a single instruction in
 * the given list of instructions.
 *
 * @param regsAlreadyReserved
 * @param insns
 * @param insnsStmtMap
 * @return
 */
private int getRegsNeeded(int regsAlreadyReserved, List<Insn> insns, Map<Insn, Stmt> insnsStmtMap) {
    // we only need regs that weren't
    int regsNeeded = regsAlreadyReserved;
    // reserved yet
    for (int i = 0; i < insns.size(); i++) {
        Insn insn = insns.get(i);
        if (insn instanceof AddressInsn) {
            // needs no regs/fitting
            continue;
        }
        // first try to find a better opcode
        Insn fittingInsn = findFittingInsn(insn);
        if (fittingInsn != null) {
            // use the fitting instruction and continue with next one
            insns.set(i, fittingInsn);
            insnsStmtMap.put(fittingInsn, insnsStmtMap.get(insn));
            insnsStmtMap.remove(insn);
            continue;
        }
        // no fitting instruction -> save if we need more registers
        int newRegsNeeded = insn.getMinimumRegsNeeded();
        if (newRegsNeeded > regsNeeded) {
            regsNeeded = newRegsNeeded;
        }
    }
    return regsNeeded;
}
Also used : Insn(soot.toDex.instructions.Insn) TwoRegInsn(soot.toDex.instructions.TwoRegInsn) AddressInsn(soot.toDex.instructions.AddressInsn) AddressInsn(soot.toDex.instructions.AddressInsn)

Example 4 with AddressInsn

use of soot.toDex.instructions.AddressInsn in project soot by Sable.

the class StmtVisitor method reduceInstructions.

/**
 * Reduces the instruction list by removing unnecessary instruction pairs
 * such as move v0 v1; move v1 v0;
 * @param trapReferences
 */
private void reduceInstructions(Set<Unit> trapReferences) {
    for (int i = 0; i < this.insns.size() - 1; i++) {
        Insn curInsn = this.insns.get(i);
        // Only consider real instructions
        if (curInsn instanceof AddressInsn)
            continue;
        if (!isReducableMoveInstruction(curInsn.getOpcode()))
            continue;
        // Skip over following address instructions
        Insn nextInsn = null;
        int nextIndex = -1;
        for (int j = i + 1; j < this.insns.size(); j++) {
            Insn candidate = this.insns.get(j);
            if (candidate instanceof AddressInsn)
                continue;
            nextInsn = candidate;
            nextIndex = j;
            break;
        }
        if (nextInsn == null || !isReducableMoveInstruction(nextInsn.getOpcode()))
            continue;
        // jump targets to the successor
        if (nextIndex == this.insns.size() - 1)
            continue;
        // Check if we have a <- b; b <- a;
        Register firstTarget = curInsn.getRegs().get(0);
        Register firstSource = curInsn.getRegs().get(1);
        Register secondTarget = nextInsn.getRegs().get(0);
        Register secondSource = nextInsn.getRegs().get(1);
        if (firstTarget.equals(secondSource) && secondTarget.equals(firstSource)) {
            Stmt nextStmt = insnStmtMap.get(nextInsn);
            // instructions may depend on the register being set.
            if (nextStmt == null || (!isJumpTarget(nextStmt) && !trapReferences.contains(nextStmt))) {
                insns.remove(nextIndex);
                if (nextStmt != null) {
                    Insn nextInst = this.insns.get(nextIndex + 1);
                    insnStmtMap.remove(nextInsn);
                    insnStmtMap.put(nextInst, nextStmt);
                }
            }
        }
    }
}
Also used : AddressInsn(soot.toDex.instructions.AddressInsn) Insn(soot.toDex.instructions.Insn) AddressInsn(soot.toDex.instructions.AddressInsn) BreakpointStmt(soot.jimple.BreakpointStmt) ReturnVoidStmt(soot.jimple.ReturnVoidStmt) InvokeStmt(soot.jimple.InvokeStmt) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) NopStmt(soot.jimple.NopStmt) GotoStmt(soot.jimple.GotoStmt) RetStmt(soot.jimple.RetStmt) AssignStmt(soot.jimple.AssignStmt) ThrowStmt(soot.jimple.ThrowStmt) IfStmt(soot.jimple.IfStmt) IdentityStmt(soot.jimple.IdentityStmt) TableSwitchStmt(soot.jimple.TableSwitchStmt) MonitorStmt(soot.jimple.MonitorStmt) LookupSwitchStmt(soot.jimple.LookupSwitchStmt) ReturnStmt(soot.jimple.ReturnStmt) ExitMonitorStmt(soot.jimple.ExitMonitorStmt) Stmt(soot.jimple.Stmt)

Example 5 with AddressInsn

use of soot.toDex.instructions.AddressInsn in project soot by Sable.

the class StmtVisitor method beginNewStmt.

protected void beginNewStmt(Stmt s) {
    // It's a new statement, so we can re-use registers
    regAlloc.resetImmediateConstantsPool();
    addInsn(new AddressInsn(s), null);
}
Also used : AddressInsn(soot.toDex.instructions.AddressInsn)

Aggregations

AddressInsn (soot.toDex.instructions.AddressInsn)5 Insn (soot.toDex.instructions.Insn)3 AbstractPayload (soot.toDex.instructions.AbstractPayload)2 ArrayList (java.util.ArrayList)1 BuilderInstruction (org.jf.dexlib2.builder.BuilderInstruction)1 AssignStmt (soot.jimple.AssignStmt)1 BreakpointStmt (soot.jimple.BreakpointStmt)1 EnterMonitorStmt (soot.jimple.EnterMonitorStmt)1 ExitMonitorStmt (soot.jimple.ExitMonitorStmt)1 GotoStmt (soot.jimple.GotoStmt)1 IdentityStmt (soot.jimple.IdentityStmt)1 IfStmt (soot.jimple.IfStmt)1 InvokeStmt (soot.jimple.InvokeStmt)1 LookupSwitchStmt (soot.jimple.LookupSwitchStmt)1 MonitorStmt (soot.jimple.MonitorStmt)1 NopStmt (soot.jimple.NopStmt)1 RetStmt (soot.jimple.RetStmt)1 ReturnStmt (soot.jimple.ReturnStmt)1 ReturnVoidStmt (soot.jimple.ReturnVoidStmt)1 Stmt (soot.jimple.Stmt)1