Search in sources :

Example 11 with BuilderInstruction

use of org.jf.dexlib2.builder.BuilderInstruction in project tinker by Tencent.

the class BuilderMutableMethodImplementation method replaceInstruction.

public void replaceInstruction(int index, @Nonnull BuilderInstruction replacementInstruction) {
    if (index >= instructionList.size() - 1) {
        throw new IndexOutOfBoundsException();
    }
    MethodLocation replaceLocation = instructionList.get(index);
    replacementInstruction.location = replaceLocation;
    BuilderInstruction old = replaceLocation.instruction;
    assert old != null;
    old.location = null;
    replaceLocation.instruction = replacementInstruction;
    // TODO: factor out index/address fix up loop
    int codeAddress = replaceLocation.codeAddress + replaceLocation.instruction.getCodeUnits();
    for (int i = index + 1; i < instructionList.size(); i++) {
        MethodLocation location = instructionList.get(i);
        location.codeAddress = codeAddress;
        Instruction instruction = location.getInstruction();
        if (instruction != null) {
            codeAddress += instruction.getCodeUnits();
        } else {
            assert i == instructionList.size() - 1;
        }
    }
    this.fixInstructions = true;
}
Also used : Instruction(org.jf.dexlib2.iface.instruction.Instruction)

Example 12 with BuilderInstruction

use of org.jf.dexlib2.builder.BuilderInstruction in project tinker by Tencent.

the class BuilderMutableMethodImplementation method swapInstructions.

public void swapInstructions(int index1, int index2) {
    if (index1 >= instructionList.size() - 1 || index2 >= instructionList.size() - 1) {
        throw new IndexOutOfBoundsException();
    }
    MethodLocation first = instructionList.get(index1);
    MethodLocation second = instructionList.get(index2);
    // only the last MethodLocation may have a null instruction
    assert first.instruction != null;
    assert second.instruction != null;
    first.instruction.location = second;
    second.instruction.location = first;
    {
        BuilderInstruction tmp = second.instruction;
        second.instruction = first.instruction;
        first.instruction = tmp;
    }
    if (index2 < index1) {
        int tmp = index2;
        index2 = index1;
        index1 = tmp;
    }
    int codeAddress = first.codeAddress + first.instruction.getCodeUnits();
    for (int i = index1 + 1; i <= index2; i++) {
        MethodLocation location = instructionList.get(i);
        location.codeAddress = codeAddress;
        Instruction instruction = location.instruction;
        assert instruction != null;
        codeAddress += location.instruction.getCodeUnits();
    }
    this.fixInstructions = true;
}
Also used : Instruction(org.jf.dexlib2.iface.instruction.Instruction)

Example 13 with BuilderInstruction

use of org.jf.dexlib2.builder.BuilderInstruction in project smali by JesusFreke.

the class MutableMethodImplementation method swapInstructions.

public void swapInstructions(int index1, int index2) {
    if (index1 >= instructionList.size() - 1 || index2 >= instructionList.size() - 1) {
        throw new IndexOutOfBoundsException();
    }
    MethodLocation first = instructionList.get(index1);
    MethodLocation second = instructionList.get(index2);
    // only the last MethodLocation may have a null instruction
    assert first.instruction != null;
    assert second.instruction != null;
    first.instruction.location = second;
    second.instruction.location = first;
    {
        BuilderInstruction tmp = second.instruction;
        second.instruction = first.instruction;
        first.instruction = tmp;
    }
    if (index2 < index1) {
        int tmp = index2;
        index2 = index1;
        index1 = tmp;
    }
    int codeAddress = first.codeAddress + first.instruction.getCodeUnits();
    for (int i = index1 + 1; i <= index2; i++) {
        MethodLocation location = instructionList.get(i);
        location.codeAddress = codeAddress;
        Instruction instruction = location.instruction;
        assert instruction != null;
        codeAddress += location.instruction.getCodeUnits();
    }
    this.fixInstructions = true;
}
Also used : Instruction(org.jf.dexlib2.iface.instruction.Instruction)

Aggregations

BuilderInstruction (org.jf.dexlib2.builder.BuilderInstruction)8 Instruction (org.jf.dexlib2.iface.instruction.Instruction)7 ImmutableStringReference (org.jf.dexlib2.immutable.reference.ImmutableStringReference)5 MutableMethodImplementation (org.jf.dexlib2.builder.MutableMethodImplementation)4 BuilderInstruction21c (org.jf.dexlib2.builder.instruction.BuilderInstruction21c)4 BuilderInstruction35c (org.jf.dexlib2.builder.instruction.BuilderInstruction35c)4 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)4 IdentityStmt (soot.jimple.IdentityStmt)3 MonitorStmt (soot.jimple.MonitorStmt)3 NopStmt (soot.jimple.NopStmt)3 Stmt (soot.jimple.Stmt)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 BuilderOffsetInstruction (org.jf.dexlib2.builder.BuilderOffsetInstruction)2 Label (org.jf.dexlib2.builder.Label)2 Insn (soot.toDex.instructions.Insn)2 InsnWithOffset (soot.toDex.instructions.InsnWithOffset)2 HashSet (java.util.HashSet)1 MethodImplementationBuilder (org.jf.dexlib2.builder.MethodImplementationBuilder)1