Search in sources :

Example 1 with InvalidInstructionOffset

use of org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset in project atlas by alibaba.

the class MethodDefinition method findPayloadOffset.

public int findPayloadOffset(int targetOffset, Opcode type) {
    int targetIndex;
    try {
        targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
    } catch (InvalidInstructionOffset ex) {
        throw new InvalidSwitchPayload(targetOffset);
    }
    //TODO: does dalvik let you pad with multiple nops?
    //TODO: does dalvik let a switch instruction point to a non-payload instruction?
    Instruction instruction = instructions.get(targetIndex);
    if (instruction.getOpcode() != type) {
        // maybe it's pointing to a NOP padding instruction. Look at the next instruction
        if (instruction.getOpcode() == Opcode.NOP) {
            targetIndex += 1;
            if (targetIndex < instructions.size()) {
                instruction = instructions.get(targetIndex);
                if (instruction.getOpcode() == type) {
                    return instructionOffsetMap.getInstructionCodeOffset(targetIndex);
                }
            }
        }
        throw new InvalidSwitchPayload(targetOffset);
    } else {
        return targetOffset;
    }
}
Also used : InvalidInstructionOffset(org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset) OffsetInstruction(org.jf.dexlib2.iface.instruction.OffsetInstruction) AnalyzedInstruction(org.jf.dexlib2.analysis.AnalyzedInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction)

Example 2 with InvalidInstructionOffset

use of org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset in project smali by JesusFreke.

the class MethodDefinition method findPayloadOffset.

public int findPayloadOffset(int targetOffset, Opcode type) {
    int targetIndex;
    try {
        targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
    } catch (InvalidInstructionOffset ex) {
        throw new InvalidSwitchPayload(targetOffset);
    }
    //TODO: does dalvik let you pad with multiple nops?
    //TODO: does dalvik let a switch instruction point to a non-payload instruction?
    Instruction instruction = instructions.get(targetIndex);
    if (instruction.getOpcode() != type) {
        // maybe it's pointing to a NOP padding instruction. Look at the next instruction
        if (instruction.getOpcode() == Opcode.NOP) {
            targetIndex += 1;
            if (targetIndex < instructions.size()) {
                instruction = instructions.get(targetIndex);
                if (instruction.getOpcode() == type) {
                    return instructionOffsetMap.getInstructionCodeOffset(targetIndex);
                }
            }
        }
        throw new InvalidSwitchPayload(targetOffset);
    } else {
        return targetOffset;
    }
}
Also used : InvalidInstructionOffset(org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset) OffsetInstruction(org.jf.dexlib2.iface.instruction.OffsetInstruction) AnalyzedInstruction(org.jf.dexlib2.analysis.AnalyzedInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction)

Example 3 with InvalidInstructionOffset

use of org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset in project atlas by alibaba.

the class MethodDefinition method findSwitchPayload.

public Instruction findSwitchPayload(int targetOffset, Opcode type) {
    int targetIndex;
    try {
        targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
    } catch (InvalidInstructionOffset ex) {
        throw new InvalidSwitchPayload(targetOffset);
    }
    //TODO: does dalvik let you pad with multiple nops?
    //TODO: does dalvik let a switch instruction point to a non-payload instruction?
    Instruction instruction = instructions.get(targetIndex);
    if (instruction.getOpcode() != type) {
        // maybe it's pointing to a NOP padding instruction. Look at the next instruction
        if (instruction.getOpcode() == Opcode.NOP) {
            targetIndex += 1;
            if (targetIndex < instructions.size()) {
                instruction = instructions.get(targetIndex);
                if (instruction.getOpcode() == type) {
                    return instruction;
                }
            }
        }
        throw new InvalidSwitchPayload(targetOffset);
    } else {
        return instruction;
    }
}
Also used : InvalidInstructionOffset(org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset) OffsetInstruction(org.jf.dexlib2.iface.instruction.OffsetInstruction) AnalyzedInstruction(org.jf.dexlib2.analysis.AnalyzedInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction)

Example 4 with InvalidInstructionOffset

use of org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset in project smali by JesusFreke.

the class MethodDefinition method findSwitchPayload.

public Instruction findSwitchPayload(int targetOffset, Opcode type) {
    int targetIndex;
    try {
        targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
    } catch (InvalidInstructionOffset ex) {
        throw new InvalidSwitchPayload(targetOffset);
    }
    //TODO: does dalvik let you pad with multiple nops?
    //TODO: does dalvik let a switch instruction point to a non-payload instruction?
    Instruction instruction = instructions.get(targetIndex);
    if (instruction.getOpcode() != type) {
        // maybe it's pointing to a NOP padding instruction. Look at the next instruction
        if (instruction.getOpcode() == Opcode.NOP) {
            targetIndex += 1;
            if (targetIndex < instructions.size()) {
                instruction = instructions.get(targetIndex);
                if (instruction.getOpcode() == type) {
                    return instruction;
                }
            }
        }
        throw new InvalidSwitchPayload(targetOffset);
    } else {
        return instruction;
    }
}
Also used : InvalidInstructionOffset(org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset) OffsetInstruction(org.jf.dexlib2.iface.instruction.OffsetInstruction) AnalyzedInstruction(org.jf.dexlib2.analysis.AnalyzedInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction)

Aggregations

AnalyzedInstruction (org.jf.dexlib2.analysis.AnalyzedInstruction)4 Instruction (org.jf.dexlib2.iface.instruction.Instruction)4 OffsetInstruction (org.jf.dexlib2.iface.instruction.OffsetInstruction)4 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)4 InvalidInstructionOffset (org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset)4