Search in sources :

Example 41 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MutableMethodImplementation method newBuilderSparseSwitchPayload.

@Nonnull
private BuilderSparseSwitchPayload newBuilderSparseSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull SparseSwitchPayload instruction) {
    List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
    if (switchElements.size() == 0) {
        return new BuilderSparseSwitchPayload(null);
    }
    MethodLocation switchLocation = findSwitchForPayload(location);
    int baseAddress;
    if (switchLocation == null) {
        baseAddress = 0;
    } else {
        baseAddress = switchLocation.codeAddress;
    }
    List<SwitchLabelElement> labelElements = Lists.newArrayList();
    for (SwitchElement element : switchElements) {
        labelElements.add(new SwitchLabelElement(element.getKey(), newLabel(codeAddressToIndex, element.getOffset() + baseAddress)));
    }
    return new BuilderSparseSwitchPayload(labelElements);
}
Also used : SwitchElement(org.jf.dexlib2.iface.instruction.SwitchElement) Nonnull(javax.annotation.Nonnull)

Example 42 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MutableMethodImplementation method removeInstruction.

public void removeInstruction(int index) {
    if (index >= instructionList.size() - 1) {
        throw new IndexOutOfBoundsException();
    }
    MethodLocation toRemove = instructionList.get(index);
    toRemove.instruction = null;
    MethodLocation next = instructionList.get(index + 1);
    toRemove.mergeInto(next);
    instructionList.remove(index);
    int codeAddress = toRemove.codeAddress;
    for (int i = index; i < instructionList.size(); i++) {
        MethodLocation location = instructionList.get(i);
        location.index = 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 43 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MutableMethodImplementation 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 44 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MutableMethodImplementation method newBuilderPackedSwitchPayload.

@Nonnull
private BuilderPackedSwitchPayload newBuilderPackedSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull PackedSwitchPayload instruction) {
    List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
    if (switchElements.size() == 0) {
        return new BuilderPackedSwitchPayload(0, null);
    }
    MethodLocation switchLocation = findSwitchForPayload(location);
    int baseAddress;
    if (switchLocation == null) {
        baseAddress = 0;
    } else {
        baseAddress = switchLocation.codeAddress;
    }
    List<Label> labels = Lists.newArrayList();
    for (SwitchElement element : switchElements) {
        labels.add(newLabel(codeAddressToIndex, element.getOffset() + baseAddress));
    }
    return new BuilderPackedSwitchPayload(switchElements.get(0).getKey(), labels);
}
Also used : SwitchElement(org.jf.dexlib2.iface.instruction.SwitchElement) Nonnull(javax.annotation.Nonnull)

Example 45 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project atlas by alibaba.

the class DexCompareUtils method equalsInstruction.

/**
     * 比较method重的tryBlock块
     *
     * @param a
     * @param b
     * @return
     */
private static boolean equalsInstruction(List<Instruction> a, List<Instruction> b) {
    if (a.size() != b.size()) {
        return false;
    }
    Instruction at, bt;
    for (int i = 0; i < a.size(); i++) {
        at = a.get(i);
        bt = b.get(i);
        if (!at.getOpcode().equals(bt.getOpcode()) || !(at.getCodeUnits() == bt.getCodeUnits())) {
            return false;
        }
    }
    return true;
}
Also used : Instruction(org.jf.dexlib2.iface.instruction.Instruction)

Aggregations

Instruction (org.jf.dexlib2.iface.instruction.Instruction)35 Test (org.junit.Test)20 Opcode (org.jf.dexlib2.Opcode)16 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)16 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)15 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)13 OffsetInstruction (org.jf.dexlib2.iface.instruction.OffsetInstruction)12 AnalyzedInstruction (org.jf.dexlib2.analysis.AnalyzedInstruction)11 ExceptionWithContext (org.jf.util.ExceptionWithContext)11 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)10 Nonnull (javax.annotation.Nonnull)7 ClassDef (org.jf.dexlib2.iface.ClassDef)7 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)7 IOException (java.io.IOException)6 BuilderInstruction10x (org.jf.dexlib2.builder.instruction.BuilderInstruction10x)6 Reference (org.jf.dexlib2.iface.reference.Reference)6 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)5 BuilderInstruction10t (org.jf.dexlib2.builder.instruction.BuilderInstruction10t)4 InvalidItemIndex (org.jf.dexlib2.dexbacked.DexBackedDexFile.InvalidItemIndex)4 DexFile (org.jf.dexlib2.iface.DexFile)4