Search in sources :

Example 76 with OperandSize

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

the class ARMRev16Translator 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 String targetRegister = (registerOperand1.getValue());
    final String sourceRegister = (registerOperand2.getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String tmpRm15to8 = environment.getNextVariableString();
    final String tmpRm23to16 = environment.getNextVariableString();
    final String tmpRm31to24 = environment.getNextVariableString();
    final String tmpRm7to0 = environment.getNextVariableString();
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0x000000FFL), dw, tmpRm7to0));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpRm7to0, dw, String.valueOf(8), dw, targetRegister));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0x0000FF00L), dw, tmpRm15to8));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpRm15to8, dw, String.valueOf(-8), dw, tmpVar1));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, targetRegister, dw, tmpVar1, dw, targetRegister));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0x00FF0000L), dw, tmpRm23to16));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpRm23to16, dw, String.valueOf(8), dw, tmpVar2));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, targetRegister, dw, tmpVar2, dw, targetRegister));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0xFF000000L), dw, tmpRm31to24));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpRm31to24, dw, String.valueOf(-8), dw, tmpVar3));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, targetRegister, dw, tmpVar3, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 77 with OperandSize

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

the class ARMSadd16Translator 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 bt = OperandSize.BYTE;
    final OperandSize wd = OperandSize.WORD;
    final long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    new Processor() {

        @Override
        protected String[] process(final long offset, final String[] firstTwo, final String[] secondTwo) {
            final String sum1 = environment.getNextVariableString();
            final String sum2 = environment.getNextVariableString();
            final String tmpVar1 = environment.getNextVariableString();
            final String tmpVar2 = environment.getNextVariableString();
            long baseOffset = offset;
            // do the adds
            instructions.add(ReilHelpers.createAdd(baseOffset++, dw, firstTwo[0], dw, secondTwo[0], dw, sum1));
            instructions.add(ReilHelpers.createAdd(baseOffset++, dw, firstTwo[1], dw, secondTwo[1], dw, sum2));
            instructions.add(ReilHelpers.createXor(baseOffset++, dw, sum1, dw, String.valueOf(0xFFFFFFFFL), dw, tmpVar1));
            instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar1, wd, String.valueOf(-31), bt, "CPSR_GE_0"));
            instructions.add(ReilHelpers.createStr(baseOffset++, bt, "CPSR_GE_0", bt, "CPSR_GE_1"));
            instructions.add(ReilHelpers.createXor(baseOffset++, dw, sum2, dw, String.valueOf(0xFFFFFFFFL), dw, tmpVar2));
            instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar2, wd, String.valueOf(-31), bt, "CPSR_GE_2"));
            instructions.add(ReilHelpers.createStr(baseOffset++, bt, "CPSR_GE_2", bt, "CPSR_GE_3"));
            return new String[] { sum1, sum2 };
        }
    }.generate(environment, baseOffset, 16, sourceRegister1, sourceRegister2, targetRegister, instructions);
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 78 with OperandSize

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

the class ARMSaddsubxTranslator 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 bt = OperandSize.BYTE;
    final OperandSize wd = OperandSize.WORD;
    final long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    new Processor() {

        @Override
        protected String[] process(final long offset, final String[] firstTwo, final String[] secondTwo) {
            final String sum1 = environment.getNextVariableString();
            final String diff1 = environment.getNextVariableString();
            final String trueDiff1 = environment.getNextVariableString();
            final String tmpVar1 = environment.getNextVariableString();
            final String tmpVar2 = environment.getNextVariableString();
            long baseOffset = offset - instructions.size();
            // do the adds
            instructions.add(ReilHelpers.createAdd(baseOffset + instructions.size(), dw, firstTwo[1], dw, secondTwo[0], dw, sum1));
            Helpers.signedSub(baseOffset + instructions.size(), environment, instruction, instructions, secondTwo[1], firstTwo[0], diff1, trueDiff1);
            // GE[3:2] = if sum >= 0 then 0b11 else 0
            instructions.add(ReilHelpers.createXor(baseOffset + instructions.size(), dw, sum1, dw, String.valueOf(0xFFFFFFFFL), dw, tmpVar1));
            instructions.add(ReilHelpers.createBsh(baseOffset + instructions.size(), dw, tmpVar1, wd, String.valueOf(-31), bt, "CPSR_GE_2"));
            instructions.add(ReilHelpers.createStr(baseOffset + instructions.size(), bt, "CPSR_GE_2", bt, "CPSR_GE_3"));
            // GE[1:0] = if diff >= 0 then 0b11 else 0
            instructions.add(ReilHelpers.createXor(baseOffset + instructions.size(), dw, diff1, dw, String.valueOf(0xFFFFFFFFL), dw, tmpVar2));
            instructions.add(ReilHelpers.createBsh(baseOffset + instructions.size(), dw, tmpVar2, wd, String.valueOf(-31), bt, "CPSR_GE_0"));
            instructions.add(ReilHelpers.createStr(baseOffset + instructions.size(), bt, "CPSR_GE_0", bt, "CPSR_GE_1"));
            return new String[] { diff1, sum1 };
        }
    }.generate(environment, baseOffset, 16, sourceRegister1, sourceRegister2, targetRegister, instructions);
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 79 with OperandSize

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

the class ARMSmulXYTranslator 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 operand1 = environment.getNextVariableString();
    final String operand2 = environment.getNextVariableString();
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    if (instruction.getMnemonic().contains("BB")) {
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, sourceRegister1, dw, operand1, 16);
        baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, sourceRegister2, dw, operand2, 16);
    } else if (instruction.getMnemonic().contains("BT")) {
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, sourceRegister1, dw, operand1, 16);
        baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister2, wd, String.valueOf(-16L), dw, tmpVar1));
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpVar1, dw, operand2, 16);
    } else if (instruction.getMnemonic().contains("TB")) {
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister1, wd, String.valueOf(-16L), dw, tmpVar1));
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpVar1, dw, operand1, 16);
        baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, sourceRegister2, dw, operand2, 16);
    } else if (instruction.getMnemonic().contains("TB")) {
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister1, wd, String.valueOf(-16L), dw, tmpVar1));
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpVar1, dw, operand1, 16);
        baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
        instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister2, wd, String.valueOf(-16L), dw, tmpVar2));
        Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpVar2, dw, operand2, 16);
    }
    instructions.add(ReilHelpers.createMul(baseOffset++, dw, operand1, dw, operand2, qw, tmpVar3));
    instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpVar3, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 80 with OperandSize

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

the class ARMSsat16Translator 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 sourceImmediate = (registerOperand2.getValue());
    final String sourceRegister = (registerOperand3.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String signedDoesSat1 = environment.getNextVariableString();
    final String signedDoesSat2 = environment.getNextVariableString();
    final String tmpResultHigh = environment.getNextVariableString();
    final String tmpResultLow = environment.getNextVariableString();
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0xFFFFL), dw, tmpVar1));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, wd, String.valueOf(-16L), dw, tmpVar2));
    Helpers.signedSat(baseOffset, environment, instruction, instructions, dw, tmpVar1, dw, tmpVar1, dw, tmpVar1, "", tmpResultLow, Integer.decode(sourceImmediate), signedDoesSat1);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    Helpers.signedSat(baseOffset, environment, instruction, instructions, dw, tmpVar2, dw, tmpVar2, dw, tmpVar2, "", tmpResultHigh, Integer.decode(sourceImmediate), signedDoesSat2);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpResultHigh, dw, String.valueOf(0xFFFFL), dw, tmpResultHigh));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpResultLow, dw, String.valueOf(0xFFFFL), dw, tmpResultLow));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpResultHigh, wd, String.valueOf(16L), dw, tmpVar3));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpResultLow, dw, tmpVar3, dw, targetRegister));
    instructions.add(ReilHelpers.createOr(baseOffset++, bt, signedDoesSat1, bt, signedDoesSat2, bt, "Q"));
}
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