Search in sources :

Example 16 with OperandSize

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

the class ARMMsrTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
    final IOperandTreeNode sourceOperand = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final String sourceRegister = (sourceOperand.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    final String tmpZ = environment.getNextVariableString();
    final String tmpC = environment.getNextVariableString();
    final String tmpV = environment.getNextVariableString();
    final String tmpQ = environment.getNextVariableString();
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-31), bt, "N"));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-30), bt, tmpZ));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpZ, bt, String.valueOf(1L), bt, "Z"));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-29), bt, tmpC));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpC, bt, String.valueOf(1L), bt, "C"));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-28), bt, tmpV));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpV, bt, String.valueOf(1L), bt, "C"));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-29), bt, tmpQ));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpQ, bt, String.valueOf(1L), bt, "C"));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 17 with OperandSize

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

the class ARMMulTranslator 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);
    final String targetRegister = (registerOperand1.getValue());
    final String multRegister1 = (registerOperand2.getValue());
    final String multRegister2 = (registerOperand3.getValue());
    final String tmpVar1 = environment.getNextVariableString();
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    instructions.add(ReilHelpers.createMul(baseOffset++, dw, multRegister1, dw, multRegister2, qw, tmpVar1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpVar1, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
    if (instruction.getMnemonic().endsWith("S") && (instruction.getMnemonic().length() != 5)) {
        // 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();
        // 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"));
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 18 with OperandSize

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

the class ARMOrrTranslator 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 dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    // 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();
    // Rd = Rn OR shifter_operand
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, sourceRegister, dw, shifterOperand, dw, targetRegister));
    if (instruction.getMnemonic().endsWith("S") && (instruction.getMnemonic().length() != 5)) {
        // 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();
        // 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 shifter_carryout
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, shifterCarryOut, bt, "C"));
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 19 with OperandSize

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

the class ARMPkhbtTranslator 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 dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    // 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 tmpResult1 = environment.getNextVariableString();
    final String tmpResult2 = environment.getNextVariableString();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, dw, String.valueOf(0xFFFF0000L), dw, tmpResult1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0xFFFFL), dw, tmpResult2));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpResult1, dw, tmpResult2, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 20 with OperandSize

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

the class ARMBlxTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
    final String[] meta = new String[] { "isCall", "true" };
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final String sourceRegister1 = registerOperand1.getValue();
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize bt = OperandSize.BYTE;
    final String jumpOperand = environment.getNextVariableString();
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createStr(baseOffset++, dw, String.valueOf(instruction.getAddress().toLong() + 0x4), dw, "LR"));
    if (registerOperand1.getType() == ExpressionType.REGISTER) {
        /**
       * instruction TYPE (2)
       * 
       * BLX{<cond>} <Rm>
       * 
       * if ConditionPassed(cond) then target = Rm LR = address of instruction after the BLX
       * instruction CPSR T bit = target[0] PC = target AND 0xFFFFFFFE
       * 
       */
        instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, bt, String.valueOf(1), bt, "T"));
        instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0xFFFFFFFEL), dw, jumpOperand));
    } else {
        /**
       * instruction TYPE (1)
       * 
       * BLX <target_addr>
       * 
       * LR = address of the instruction after the BLX instruction CPSR T bit = 1 PC = PC +
       * (SignExtend(signed_immed_24) << 2) + (H << 1)
       */
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, String.valueOf(1), bt, "T"));
        instructions.add(ReilHelpers.createStr(baseOffset++, dw, sourceRegister1, dw, jumpOperand));
    }
    instructions.add(ReilHelpers.createJcc(baseOffset++, bt, String.valueOf(1L), dw, jumpOperand, meta));
}
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