Search in sources :

Example 66 with OperandSize

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

the class ARMSmladTranslator 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 IOperandTreeNode registerOperand4 = instruction.getOperands().get(3).getRootNode().getChildren().get(0);
    final String targetRegister = (registerOperand1.getValue());
    final String sourceRegister1 = (registerOperand2.getValue());
    final String sourceRegister2 = (registerOperand3.getValue());
    final String sourceRegister3 = (registerOperand4.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;
    final OperandSize wd = OperandSize.WORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String operand2 = environment.getNextVariableString();
    final String operand2from15to0 = environment.getNextVariableString();
    final String operand2from31to16 = environment.getNextVariableString();
    final String overflow1 = environment.getNextVariableString();
    final String overflow2 = environment.getNextVariableString();
    final String product1 = environment.getNextVariableString();
    final String product2 = environment.getNextVariableString();
    final String registerRm15to0 = environment.getNextVariableString();
    final String registerRm31to16 = environment.getNextVariableString();
    final String tmpAddResult1 = environment.getNextVariableString();
    final String tmpResult1 = environment.getNextVariableString();
    final String tmpRotate1 = environment.getNextVariableString();
    final String tmpRotate2 = environment.getNextVariableString();
    final String trueproduct1 = environment.getNextVariableString();
    final String trueproduct2 = environment.getNextVariableString();
    if (instruction.getMnemonic().contains("X")) {
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister2, bt, String.valueOf(-16), dw, tmpRotate1));
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister2, bt, String.valueOf(16), dw, tmpRotate2));
        instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpRotate1, dw, tmpRotate2, dw, operand2));
        instructions.add(ReilHelpers.createAnd(baseOffset++, dw, operand2, dw, String.valueOf(0xFFFFFFFFL), dw, operand2));
    } else {
        instructions.add(ReilHelpers.createStr(baseOffset++, dw, sourceRegister2, dw, operand2));
    }
    // extract operand_2 high and low halves
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, operand2, dw, String.valueOf(0xFFFFL), dw, operand2from15to0));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, operand2, dw, String.valueOf(-16L), dw, operand2from31to16));
    // extract Rm high and low halves
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0xFFFFL), dw, registerRm15to0));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister1, dw, String.valueOf(-16L), dw, registerRm31to16));
    Helpers.signedMul(baseOffset, environment, instruction, instructions, wd, registerRm15to0, wd, operand2from15to0, dw, trueproduct1);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    Helpers.signedMul(baseOffset, environment, instruction, instructions, wd, registerRm31to16, wd, operand2from31to16, dw, trueproduct2);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, trueproduct1, dw, trueproduct2, qw, tmpAddResult1));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, sourceRegister3, qw, tmpAddResult1, qw, tmpResult1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpResult1, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
    // calculate Overflow OF( product1 + priduct2 ) = sum | OF( sum + Rn )
    Helpers.addOverflow(baseOffset, environment, instructions, dw, product1, dw, product2, qw, tmpAddResult1, overflow1, 16);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    Helpers.addOverflow(baseOffset, environment, instructions, dw, sourceRegister3, qw, tmpAddResult1, qw, tmpResult1, overflow2, 16);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createOr(baseOffset++, bt, overflow1, bt, overflow2, bt, "Q"));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 67 with OperandSize

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

the class ARMSmlalTranslator 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 IOperandTreeNode registerOperand4 = instruction.getOperands().get(3).getRootNode().getChildren().get(0);
    final String sourceRegister1 = (registerOperand1.getValue());
    final String sourceRegister2 = (registerOperand2.getValue());
    final String sourceRegister3 = (registerOperand3.getValue());
    final String sourceRegister4 = (registerOperand4.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String firstZero = environment.getNextVariableString();
    final String secondZero = environment.getNextVariableString();
    final String tmpCarry = environment.getNextVariableString();
    final String tmpResult1 = environment.getNextVariableString();
    final String tmpResult2 = environment.getNextVariableString();
    final String tmpResult3 = environment.getNextVariableString();
    final String tmpResult4 = environment.getNextVariableString();
    final String trueCarry = environment.getNextVariableString();
    final String tmpResult = environment.getNextVariableString();
    Helpers.signedMul(baseOffset, environment, instruction, instructions, dw, sourceRegister3, dw, sourceRegister4, qw, tmpResult);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    // RdLo
    instructions.add(ReilHelpers.createAdd(baseOffset++, qw, tmpResult, dw, sourceRegister1, qw, tmpResult1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpResult1, dw, String.valueOf(0xFFFFFFFFL), dw, sourceRegister1));
    // carry
    instructions.add(ReilHelpers.createBsh(baseOffset++, qw, tmpResult1, wd, String.valueOf(-32), bt, tmpCarry));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpCarry, bt, String.valueOf(1L), bt, trueCarry));
    // RdHi
    instructions.add(ReilHelpers.createBsh(baseOffset++, qw, tmpResult, dw, String.valueOf(-32L), dw, tmpResult2));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpResult2, bt, trueCarry, qw, tmpResult3));
    instructions.add(ReilHelpers.createAdd(baseOffset++, qw, tmpResult3, dw, sourceRegister2, qw, tmpResult4));
    instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpResult4, dw, String.valueOf(0xFFFFFFFFL), dw, sourceRegister2));
    if (instruction.getMnemonic().endsWith("S") && (instruction.getMnemonic().length() != 7)) {
        /**
       * if S == 1 then N Flag = RdHi[31] Z Flag = if (RdHi == 0) and (RdLo == 0) then 1 else 0
       */
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister2, wd, String.valueOf(-31), bt, "N"));
        instructions.add(ReilHelpers.createBisz(baseOffset++, dw, sourceRegister2, bt, firstZero));
        instructions.add(ReilHelpers.createBisz(baseOffset++, dw, sourceRegister1, bt, secondZero));
        instructions.add(ReilHelpers.createAnd(baseOffset++, bt, firstZero, bt, secondZero, bt, "Z"));
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 68 with OperandSize

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

the class ARMSmlsdTranslator 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 IOperandTreeNode registerOperand4 = instruction.getOperands().get(3).getRootNode().getChildren().get(0);
    final String targetRegister = (registerOperand1.getValue());
    final String sourceRegister1 = (registerOperand2.getValue());
    final String sourceRegister2 = (registerOperand3.getValue());
    final String sourceRegister3 = (registerOperand4.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize wd = OperandSize.WORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String operand2 = environment.getNextVariableString();
    final String tmpRotate1 = environment.getNextVariableString();
    final String tmpRotate2 = environment.getNextVariableString();
    final String diffOfProducts = environment.getNextVariableString();
    final String operand2from15to0 = environment.getNextVariableString();
    final String operand2from31to16 = environment.getNextVariableString();
    final String registerRmfrom15to0 = environment.getNextVariableString();
    final String registerRmfrom31to16 = environment.getNextVariableString();
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    final String trueDiffOfProducts = environment.getNextVariableString();
    final String product1 = environment.getNextVariableString();
    final String product2 = environment.getNextVariableString();
    if (instruction.getMnemonic().contains("X")) {
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister2, bt, String.valueOf(-16), dw, tmpRotate1));
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister2, bt, String.valueOf(16), dw, tmpRotate2));
        instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpRotate1, dw, tmpRotate2, dw, operand2));
        instructions.add(ReilHelpers.createAnd(baseOffset++, dw, operand2, dw, String.valueOf(0xFFFFFFFFL), dw, operand2));
    } else {
        instructions.add(ReilHelpers.createStr(baseOffset++, dw, sourceRegister2, dw, operand2));
    }
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, operand2, dw, String.valueOf(0xFFFFL), dw, operand2from15to0));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0xFFFFL), dw, registerRmfrom15to0));
    Helpers.signedMul(baseOffset, environment, instruction, instructions, wd, operand2from15to0, wd, registerRmfrom15to0, dw, product1);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, operand2, dw, String.valueOf(-16L), dw, tmpVar1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar1, dw, String.valueOf(0xFFFFL), dw, operand2from31to16));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister1, dw, String.valueOf(-16L), dw, tmpVar2));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar2, dw, String.valueOf(0xFFFFL), dw, registerRmfrom31to16));
    Helpers.signedMul(baseOffset, environment, instruction, instructions, wd, operand2from31to16, wd, registerRmfrom31to16, dw, product2);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    Helpers.signedSub(baseOffset, environment, instruction, instructions, product2, product1, diffOfProducts, trueDiffOfProducts);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, sourceRegister3, dw, diffOfProducts, dw, tmpVar3));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar3, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
    Helpers.overflowCondition(baseOffset, environment, instruction, instructions, tmpVar3);
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 69 with OperandSize

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

the class ARMSmmlsTranslator 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 IOperandTreeNode registerOperand4 = instruction.getOperands().get(3).getRootNode().getChildren().get(0);
    final String targetRegister = (registerOperand1.getValue());
    final String sourceRegister1 = (registerOperand2.getValue());
    final String sourceRegister2 = (registerOperand3.getValue());
    final String sourceRegister3 = (registerOperand4.getValue());
    final OperandSize wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    final String tmpVar4 = environment.getNextVariableString();
    final String value = environment.getNextVariableString();
    Helpers.signedMul(baseOffset, environment, instruction, instructions, dw, sourceRegister1, dw, sourceRegister2, qw, value);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister3, dw, String.valueOf(32L), qw, tmpVar1));
    if (instruction.getMnemonic().contains("R")) {
        instructions.add(ReilHelpers.createSub(baseOffset++, qw, tmpVar1, qw, value, qw, tmpVar2));
        instructions.add(ReilHelpers.createAdd(baseOffset++, qw, tmpVar2, dw, String.valueOf(0x80000000L), qw, tmpVar3));
    } else {
        instructions.add(ReilHelpers.createSub(baseOffset++, qw, tmpVar1, qw, value, qw, tmpVar3));
    }
    instructions.add(ReilHelpers.createBsh(baseOffset++, qw, tmpVar3, wd, String.valueOf(-32L), dw, tmpVar4));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar4, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 70 with OperandSize

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

the class ARMSmmulTranslator 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 sourceRegister1 = (registerOperand2.getValue());
    final String sourceRegister2 = (registerOperand3.getValue());
    final OperandSize wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String tmpVar1 = environment.getNextVariableString();
    final String value = environment.getNextVariableString();
    Helpers.signedMul(baseOffset, environment, instruction, instructions, dw, sourceRegister1, dw, sourceRegister2, qw, value);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    if (instruction.getMnemonic().contains("R")) {
        instructions.add(ReilHelpers.createAdd(baseOffset++, qw, value, dw, String.valueOf(0x80000000L), dw, value));
    }
    instructions.add(ReilHelpers.createBsh(baseOffset++, qw, value, wd, String.valueOf(-32L), dw, tmpVar1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar1, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
}
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