Search in sources :

Example 81 with OperandSize

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

the class ARMSsub16Translator 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 long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    new Processor() {

        @Override
        protected int getResultShiftDelta() {
            return 0;
        }

        @Override
        protected String[] process(final long offset, final String[] firstTwo, final String[] secondTwo) {
            final String diff1 = environment.getNextVariableString();
            final String diff2 = environment.getNextVariableString();
            final String trueDiff1 = environment.getNextVariableString();
            final String trueDiff2 = environment.getNextVariableString();
            final String tmpVar1 = environment.getNextVariableString();
            final String tmpVar2 = environment.getNextVariableString();
            long baseOffset = offset;
            // do the subs
            Helpers.signedSub(baseOffset, environment, instruction, instructions, secondTwo[0], firstTwo[0], diff1, trueDiff1);
            baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
            Helpers.signedSub(baseOffset, environment, instruction, instructions, secondTwo[1], firstTwo[1], diff2, trueDiff2);
            baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
            // CPSR GE
            instructions.add(ReilHelpers.createXor(baseOffset++, dw, trueDiff1, dw, String.valueOf(0xFFFFL), dw, tmpVar1));
            instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar1, dw, String.valueOf(-15L), bt, "CPSR_GE_0"));
            instructions.add(ReilHelpers.createStr(baseOffset++, bt, "CPSR_GE_0", bt, "CPSR_GE_1"));
            instructions.add(ReilHelpers.createXor(baseOffset++, dw, trueDiff2, dw, String.valueOf(0xFFFFL), dw, tmpVar2));
            instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar2, dw, String.valueOf(-15L), bt, "CPSR_GE_2"));
            instructions.add(ReilHelpers.createStr(baseOffset++, bt, "CPSR_GE_2", bt, "CPSR_GE_3"));
            return new String[] { diff1, diff2 };
        }
    }.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 82 with OperandSize

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

the class SwrTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "swr");
    final OperandSize dw = OperandSize.DWORD;
    final String lastTwoAddressBits = environment.getNextVariableString();
    final String shiftValue = environment.getNextVariableString();
    final String memoryMaskShiftValue = environment.getNextVariableString();
    final String registerShiftAmount = environment.getNextVariableString();
    final String memoryContent = environment.getNextVariableString();
    final String memoryMask = environment.getNextVariableString();
    final String memoryMaskedContent = environment.getNextVariableString();
    final String combinedContent = environment.getNextVariableString();
    final String registerShiftedContent = environment.getNextVariableString();
    final String address = environment.getNextVariableString();
    final String resultValue = environment.getNextVariableString();
    final IOperandTreeNode sourceRegister = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
    long offset = baseOffset;
    final String extendedValue = SignExtendGenerator.extendAndAdd(offset, environment, instruction.getOperands().get(1), instructions);
    offset = baseOffset + instructions.size();
    instructions.add(ReilHelpers.createAnd(offset++, dw, extendedValue, dw, String.valueOf(0xFFFFFFFCL), dw, address));
    instructions.add(ReilHelpers.createLdm(offset++, dw, address, dw, memoryContent));
    instructions.add(ReilHelpers.createAnd(offset++, dw, extendedValue, dw, String.valueOf(3L), dw, lastTwoAddressBits));
    instructions.add(ReilHelpers.createBsh(offset++, dw, lastTwoAddressBits, dw, String.valueOf(3L), dw, shiftValue));
    final String endianess = "little";
    if (endianess.equalsIgnoreCase("little")) {
        // little endianess case
        // address bits 1:0 00
        // register contents 0x11223344 shifted left by 0 -> 0x11223344
        // memory contents 0xAABBCCDD anded with mask 0x00000000 -> 0x00000000
        // both ored -> 0x11223344
        // anded and stored
        instructions.add(ReilHelpers.createAdd(offset++, dw, String.valueOf(0L), dw, shiftValue, dw, registerShiftAmount));
        instructions.add(ReilHelpers.createAdd(offset++, dw, String.valueOf(-32L), dw, shiftValue, dw, memoryMaskShiftValue));
    } else if (endianess.equalsIgnoreCase("big")) {
        // big endian case
        // address bits 1:0 00
        // register contents 0x11223344 shifted left by 24 -> 0x11223344000000
        // memory contents 0xAABBCCDD anded with mask 0x00FFFFFF -> 0x00BBCCDD
        // both ored -> 0x11223344BBCCDD
        // and stored
        instructions.add(ReilHelpers.createSub(offset++, dw, String.valueOf(24L), dw, shiftValue, dw, registerShiftAmount));
        instructions.add(ReilHelpers.createSub(offset++, dw, String.valueOf(-8L), dw, shiftValue, dw, memoryMaskShiftValue));
    }
    // prepare memory to be correct for storage
    instructions.add(ReilHelpers.createBsh(offset++, dw, String.valueOf(0xFFFFFFFFL), dw, memoryMaskShiftValue, dw, memoryMask));
    instructions.add(ReilHelpers.createAnd(offset++, dw, memoryContent, dw, memoryMask, dw, memoryMaskedContent));
    // prepare register for storage
    instructions.add(ReilHelpers.createBsh(offset++, dw, sourceRegister.getValue(), dw, registerShiftAmount, dw, registerShiftedContent));
    // combine memory and register
    instructions.add(ReilHelpers.createOr(offset++, dw, registerShiftedContent, dw, memoryMaskedContent, dw, combinedContent));
    // store to memory
    instructions.add(ReilHelpers.createAnd(offset++, dw, combinedContent, dw, String.valueOf(0xFFFFFFFFL), dw, resultValue));
    instructions.add(ReilHelpers.createStm(offset++, dw, resultValue, dw, address));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 83 with OperandSize

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

the class WsbhTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "wsbh");
    final String rd = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue();
    final String rt = instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue();
    final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
    long offset = baseOffset;
    final OperandSize dw = OperandSize.DWORD;
    final String rtByte1 = environment.getNextVariableString();
    final String rtByte2 = environment.getNextVariableString();
    final String rtByte3 = environment.getNextVariableString();
    final String rtByte4 = environment.getNextVariableString();
    final String newRtByte1 = environment.getNextVariableString();
    final String newRtByte2 = environment.getNextVariableString();
    final String newRtByte3 = environment.getNextVariableString();
    final String newRtByte4 = environment.getNextVariableString();
    final String tempResultLower = environment.getNextVariableString();
    final String tempResultUpper = environment.getNextVariableString();
    instructions.add(ReilHelpers.createAnd(offset++, dw, rt, dw, String.valueOf(0xFF000000L), dw, rtByte4));
    instructions.add(ReilHelpers.createAnd(offset++, dw, rt, dw, String.valueOf(0x00FF0000L), dw, rtByte3));
    instructions.add(ReilHelpers.createAnd(offset++, dw, rt, dw, String.valueOf(0x0000FF00L), dw, rtByte2));
    instructions.add(ReilHelpers.createAnd(offset++, dw, rt, dw, String.valueOf(0x000000FFL), dw, rtByte1));
    instructions.add(ReilHelpers.createBsh(offset++, dw, rtByte4, dw, String.valueOf(-8L), dw, newRtByte3));
    instructions.add(ReilHelpers.createBsh(offset++, dw, rtByte3, dw, String.valueOf(8L), dw, newRtByte4));
    instructions.add(ReilHelpers.createBsh(offset++, dw, rtByte2, dw, String.valueOf(-8L), dw, newRtByte1));
    instructions.add(ReilHelpers.createBsh(offset++, dw, rtByte1, dw, String.valueOf(8L), dw, newRtByte2));
    instructions.add(ReilHelpers.createOr(offset++, dw, newRtByte3, dw, newRtByte4, dw, tempResultUpper));
    instructions.add(ReilHelpers.createOr(offset++, dw, newRtByte1, dw, newRtByte2, dw, tempResultLower));
    instructions.add(ReilHelpers.createOr(offset, dw, tempResultUpper, dw, tempResultLower, dw, rd));
}
Also used : OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 84 with OperandSize

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

the class XoriTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "xori");
    final Triple<IOperandTree, IOperandTree, IOperandTree> operands = OperandLoader.loadDuplicateFirst(instruction);
    final String targetRegister = operands.first().getRootNode().getChildren().get(0).getValue();
    final String sourceRegister = operands.second().getRootNode().getChildren().get(0).getValue();
    final String sourceImmediate = operands.third().getRootNode().getChildren().get(0).getValue();
    final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
    final long offset = baseOffset;
    final OperandSize dw = OperandSize.DWORD;
    instructions.add(ReilHelpers.createXor(offset, dw, sourceRegister, dw, sourceImmediate, dw, targetRegister));
}
Also used : IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 85 with OperandSize

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

the class THUMBStrTranslator 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);
    // Hack for STR Rx, =0xSOMEADDR
    IOperandTreeNode registerOperand2 = null;
    if ((instruction.getOperands().get(1).getRootNode().getChildren().get(0).getChildren().get(0).getType() == ExpressionType.IMMEDIATE_INTEGER) || (instruction.getOperands().get(1).getRootNode().getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER)) {
        registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0).getChildren().get(0);
    } else {
        registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0).getChildren().get(0).getChildren().get(0);
    }
    IOperandTreeNode variableOperand1 = null;
    if (instruction.getOperands().get(1).getRootNode().getChildren().get(0).getChildren().get(0).getChildren().size() == 2) {
        variableOperand1 = instruction.getOperands().get(1).getRootNode().getChildren().get(0).getChildren().get(0).getChildren().get(1);
    }
    final String targetRegister1 = (registerOperand1.getValue());
    final String sourceRegister2 = (registerOperand2.getValue());
    final String sourceVariable1 = variableOperand1 == null ? "0" : (variableOperand1.getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String tmpAddress = environment.getNextVariableString();
    final String tmpVar1 = environment.getNextVariableString();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, targetRegister1, dw, String.valueOf(0xFFFFFFFFL), dw, tmpVar1));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, sourceRegister2, dw, sourceVariable1, dw, tmpAddress));
    instructions.add(ReilHelpers.createStm(baseOffset++, dw, tmpVar1, dw, tmpAddress));
}
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