Search in sources :

Example 51 with OperandSize

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

the class ARMUsub8Translator 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 OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String diff1 = environment.getNextVariableString();
    final String diff2 = environment.getNextVariableString();
    final String diff3 = environment.getNextVariableString();
    final String diff4 = environment.getNextVariableString();
    final String tmpRm15to8 = environment.getNextVariableString();
    final String tmpRm23to16 = environment.getNextVariableString();
    final String tmpRm31to24 = environment.getNextVariableString();
    final String tmpRm7to0 = environment.getNextVariableString();
    final String tmpRn15to8 = environment.getNextVariableString();
    final String tmpRn23to16 = environment.getNextVariableString();
    final String tmpRn31to24 = environment.getNextVariableString();
    final String tmpRn7to0 = environment.getNextVariableString();
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    final String tmpVar4 = environment.getNextVariableString();
    final String tmpVar5 = environment.getNextVariableString();
    // Rn
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0x000000FFL), dw, tmpRn7to0));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0x0000FF00L), dw, tmpVar1));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar1, dw, String.valueOf(-8), dw, tmpRn15to8));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0x00FF0000L), dw, tmpVar2));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar2, dw, String.valueOf(-16), dw, tmpRn23to16));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0xFF000000L), dw, tmpVar3));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar3, dw, String.valueOf(-24), dw, tmpRn31to24));
    // Rm
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister2, dw, String.valueOf(0x000000FFL), dw, tmpRm7to0));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister2, dw, String.valueOf(0x0000FF00L), dw, tmpVar1));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar1, dw, String.valueOf(-8), dw, tmpRm15to8));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister2, dw, String.valueOf(0x00FF0000L), dw, tmpVar2));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar2, dw, String.valueOf(-16), dw, tmpRm23to16));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister2, dw, String.valueOf(0xFF000000L), dw, tmpVar3));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar3, dw, String.valueOf(-24), dw, tmpRm31to24));
    // Do the Subs
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, tmpRn7to0, dw, tmpRm7to0, dw, diff1));
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, tmpRn15to8, dw, tmpRm15to8, dw, diff2));
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, tmpRn23to16, dw, tmpRm23to16, dw, diff3));
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, tmpRn31to24, dw, tmpRm31to24, dw, diff4));
    // CPSR GE
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff1, wd, String.valueOf(-7), bt, "CPSR_GE_0"));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff2, wd, String.valueOf(-7), bt, "CPSR_GE_1"));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff3, wd, String.valueOf(-7), bt, "CPSR_GE_2"));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff4, wd, String.valueOf(-7), bt, "CPSR_GE_3"));
    // get the results together
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff2, dw, String.valueOf(8), dw, diff2));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff3, dw, String.valueOf(16), dw, diff3));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff4, dw, String.valueOf(24), dw, diff4));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, diff1, dw, String.valueOf(0x000000FFL), dw, diff1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, diff2, dw, String.valueOf(0x0000FF00L), dw, diff2));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, diff3, dw, String.valueOf(0x00FF0000L), dw, diff3));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, diff4, dw, String.valueOf(0xFF000000L), dw, diff4));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, diff1, dw, diff2, dw, tmpVar4));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, diff3, dw, diff4, dw, tmpVar5));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpVar4, dw, tmpVar5, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 52 with OperandSize

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

the class ARMUsubaddxTranslator method translateCore.

@Override
protected final 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 tmpVar1 = environment.getNextVariableString();
            final String tmpVar2 = environment.getNextVariableString();
            long baseOffset = offset;
            // do the add
            instructions.add(ReilHelpers.createAdd(baseOffset++, dw, firstTwo[0], dw, secondTwo[1], dw, sum1));
            // do the sub
            instructions.add(ReilHelpers.createSub(baseOffset++, dw, firstTwo[1], dw, secondTwo[0], dw, diff1));
            // CPSR GE
            // borrow
            instructions.add(ReilHelpers.createBsh(baseOffset++, dw, diff1, wd, String.valueOf(-15L), bt, tmpVar1));
            instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar1, bt, String.valueOf(1L), bt, "CPSR_GE_2"));
            instructions.add(ReilHelpers.createStr(baseOffset++, bt, "CPSR_GE_2", bt, "CPSR_GE_3"));
            // carry
            instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sum1, wd, String.valueOf(-16L), bt, tmpVar2));
            instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar2, bt, String.valueOf(1L), bt, "CPSR_GE_0"));
            instructions.add(ReilHelpers.createStr(baseOffset++, bt, "CPSR_GE_0", bt, "CPSR_GE_1"));
            return new String[] { sum1, diff1 };
        }
    }.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 53 with OperandSize

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

the class ARMUxtabTranslator 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();
    final String operand2 = environment.getNextVariableString();
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String shifterOperand = shifterPair.first();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, dw, String.valueOf(0x000000FFL), dw, operand2));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, sourceRegister, dw, operand2, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 54 with OperandSize

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

the class ARMUxtahTranslator 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();
    final String operand2 = environment.getNextVariableString();
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String shifterOperand = shifterPair.first();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, dw, String.valueOf(0x0000FFFFL), dw, operand2));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, sourceRegister, dw, operand2, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 55 with OperandSize

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

the class ARMUxtb16Translator 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 shifter = instruction.getOperands().get(1).getRootNode();
    final String targetRegister = (registerOperand1.getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String shifterOperand = shifterPair.first();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, dw, String.valueOf(0x00FF00FFL), 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