Search in sources :

Example 56 with OperandSize

use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.

the class ARMStmTranslator method translateCore.

/**
   * STM{<cond>}<addressing_mode> <Rn>{!}, <registers
   */
@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    String typeValue = "";
    if (instruction.getMnemonic().endsWith(".W")) {
        typeValue = instruction.getMnemonic().length() == 9 ? instruction.getMnemonic().substring(5, 7) : instruction.getMnemonic().substring(3, 5);
    } else {
        typeValue = instruction.getMnemonic().length() == 7 ? instruction.getMnemonic().substring(5) : instruction.getMnemonic().substring(3);
    }
    IOperandTreeNode registerOperand1;
    String wBit = "1";
    if (instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().size() == 1) {
        wBit = "2";
        registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().get(0);
    } else {
        registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    }
    final IOperandTreeNode rootNodeOfRegisterList = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final String registerNodeValue = (registerOperand1.getValue());
    final int registerListLength = rootNodeOfRegisterList.getChildren().size();
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    String tmpAddress = AddressingModeFourGenerator.generate(baseOffset, environment, instruction, instructions, typeValue, registerNodeValue, wBit, rootNodeOfRegisterList);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    for (int i = 0; i < registerListLength; i++) {
        // STM Ri, addi
        // ADD addi, 4, addi+1
        final String nextAddress = environment.getNextVariableString();
        instructions.add(ReilHelpers.createStm(baseOffset++, dw, (rootNodeOfRegisterList.getChildren().get(i).getValue()), dw, tmpAddress));
        instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpAddress, bt, String.valueOf(4L), dw, nextAddress));
        tmpAddress = nextAddress;
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 57 with OperandSize

use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.

the class ARMStrdTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    final Boolean writeBack = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().size() == 1 ? true : false;
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().size() == 1 ? instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().get(0) : instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode rootNode = instruction.getOperands().get(1).getRootNode();
    final String registerNodeValue = (registerOperand1.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final Pair<String, String> resultPair = AddressingModeTwoGenerator.generate(baseOffset, environment, instruction, instructions, rootNode);
    final String tmpAddress = resultPair.first();
    final String tmpAddress2 = environment.getNextVariableString();
    final int registerNum = Helpers.getRegisterIndex(registerNodeValue);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    if (((registerNum % 2) == 0) && (registerNum != 14)) {
        instructions.add(ReilHelpers.createStm(baseOffset++, dw, registerNodeValue, dw, tmpAddress));
        instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpAddress, bt, String.valueOf(4), dw, tmpAddress2));
        instructions.add(ReilHelpers.createStm(baseOffset++, dw, "R" + String.valueOf(registerNum + 1), dw, tmpAddress2));
        if (writeBack) {
            instructions.add(ReilHelpers.createStr(baseOffset++, dw, tmpAddress2, dw, registerNodeValue));
        }
    } else {
        instructions.add(ReilHelpers.createUnknown(baseOffset++));
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 58 with OperandSize

use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.

the class ARMStrtTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode rootNode = instruction.getOperands().get(1).getRootNode();
    final String registerNodeValue = (registerOperand1.getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final Pair<String, String> resultPair = AddressingModeTwoGenerator.generate(baseOffset, environment, instruction, instructions, rootNode);
    final String tmpAddress = resultPair.first();
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createStm(baseOffset++, dw, registerNodeValue, dw, tmpAddress));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 59 with OperandSize

use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.

the class ARMSubTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final IOperandTreeNode shifter = instruction.getOperands().get(2).getRootNode();
    final String targetRegister = (registerOperand1.getValue());
    final String sourceRegister = (registerOperand2.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String tmpVar1 = environment.getNextVariableString();
    // compute <shifter_operand>
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String shifterOperand = shifterPair.first();
    // final String shifterCarryOut = shifterPair.second();
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, sourceRegister, dw, shifterOperand, dw, tmpVar1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar1, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
    if (instruction.getMnemonic().endsWith("S")) {
        // match the case where we have to set flags this does not handle the S == 1 and Rd == R15
        // case !!!
        final String tmpVar3 = environment.getNextVariableString();
        final String tmpVar4 = environment.getNextVariableString();
        final String tmpVar5 = environment.getNextVariableString();
        // N Flag Rd[31]
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, targetRegister, dw, String.valueOf(-31L), bt, tmpVar3));
        instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar3, bt, String.valueOf(1L), bt, "N"));
        // Z Flag if Rd == 0 then 1 else 0
        instructions.add(ReilHelpers.createBisz(baseOffset++, dw, targetRegister, bt, "Z"));
        // C Flag NOT BorrowFrom(Rn - shifter_operand)
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar1, wd, String.valueOf(-31L), bt, tmpVar4));
        instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar4, bt, String.valueOf(1L), bt, tmpVar5));
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, tmpVar5, bt, "C"));
        // V Flag OverflowFrom(Rn - shifter_operand)
        Helpers.subOverflow(baseOffset, environment, instruction, instructions, dw, shifterOperand, dw, sourceRegister, dw, tmpVar1, "V", 32);
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 60 with OperandSize

use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.

the class ARMSwpTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final IOperandTreeNode registerOperand3 = instruction.getOperands().get(2).getRootNode().getChildren().get(0).getChildren().get(0);
    final String targetRegister = (registerOperand1.getValue());
    final String sourceRegister1 = (registerOperand2.getValue());
    final String memoryRegister2 = (registerOperand3.getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String negRotVal2 = environment.getNextVariableString();
    final String rotVal1 = environment.getNextVariableString();
    final String rotVal2 = environment.getNextVariableString();
    final String tmpResult = environment.getNextVariableString();
    final String tmpRotate1 = environment.getNextVariableString();
    final String tmpRotate2 = environment.getNextVariableString();
    final String tmpVal1 = environment.getNextVariableString();
    // load
    instructions.add(ReilHelpers.createLdm(baseOffset++, dw, memoryRegister2, dw, tmpVal1));
    // rotate
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, memoryRegister2, dw, String.valueOf(0x3), dw, rotVal1));
    instructions.add(ReilHelpers.createMul(baseOffset++, dw, rotVal1, dw, String.valueOf(8), dw, rotVal2));
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, String.valueOf(0), dw, rotVal2, dw, negRotVal2));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVal1, dw, negRotVal2, dw, tmpRotate1));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVal1, dw, rotVal2, dw, tmpRotate2));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpRotate1, dw, tmpRotate2, dw, tmpResult));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
    // store
    instructions.add(ReilHelpers.createStm(baseOffset++, dw, sourceRegister1, dw, memoryRegister2));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Aggregations

OperandSize (com.google.security.zynamics.reil.OperandSize)442 IOperandTreeNode (com.google.security.zynamics.zylib.disassembly.IOperandTreeNode)257 IOperandTree (com.google.security.zynamics.zylib.disassembly.IOperandTree)53 InternalTranslationException (com.google.security.zynamics.reil.translators.InternalTranslationException)46 TranslationResult (com.google.security.zynamics.reil.translators.TranslationResult)45 ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)16 ArrayList (java.util.ArrayList)15 BigInteger (java.math.BigInteger)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)5 OperandType (com.google.security.zynamics.reil.OperandType)2 ReilOperandNode (com.google.security.zynamics.reil.ReilOperandNode)2 TranslationResultType (com.google.security.zynamics.reil.translators.TranslationResultType)2 ReilBlock (com.google.security.zynamics.reil.ReilBlock)1 ReilEdge (com.google.security.zynamics.reil.ReilEdge)1 ReilGraph (com.google.security.zynamics.reil.ReilGraph)1 ReilOperand (com.google.security.zynamics.reil.ReilOperand)1 Pair (com.google.security.zynamics.zylib.general.Pair)1 EdgeType (com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType)1 HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1