Search in sources :

Example 61 with OperandSize

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

the class ARMSxtab16Translator 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 wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String tmpVar1 = environment.getNextVariableString();
    final String highResult = environment.getNextVariableString();
    final String lowResult = environment.getNextVariableString();
    final String tmpHighResult = environment.getNextVariableString();
    final String tmpLowResult = environment.getNextVariableString();
    final String tmpOperand2from23to16 = environment.getNextVariableString();
    final String tmpOperand2from23to16signExtended = environment.getNextVariableString();
    final String tmpOperand2from7to0 = environment.getNextVariableString();
    final String tmpOperand2from7to0signExtended = environment.getNextVariableString();
    final String tmpOperand2Shifted = environment.getNextVariableString();
    final String tmpRn15to0 = environment.getNextVariableString();
    final String tmpRn31to16 = environment.getNextVariableString();
    // compute <shifter_operand>
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String shifterOperand = shifterPair.first();
    // final String shifterCarryOut = shifterPair.second();
    // Operand2
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, wd, String.valueOf(0xFFL), dw, tmpOperand2from7to0));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, shifterOperand, wd, String.valueOf(-16L), dw, tmpOperand2Shifted));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpOperand2Shifted, wd, String.valueOf(0xFFL), dw, tmpOperand2from23to16));
    Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpOperand2from7to0, dw, tmpOperand2from7to0signExtended, 8);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpOperand2from23to16, dw, tmpOperand2from23to16signExtended, 8);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    // Rn
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, wd, String.valueOf(0xFFFFL), dw, tmpRn15to0));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, wd, String.valueOf(-16L), dw, tmpRn31to16));
    // ADD
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpRn15to0, dw, tmpOperand2from7to0signExtended, dw, tmpLowResult));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpLowResult, dw, String.valueOf(0xFFFFL), wd, lowResult));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpRn31to16, dw, tmpOperand2from23to16signExtended, dw, tmpHighResult));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpHighResult, dw, String.valueOf(0xFFFFL), wd, highResult));
    instructions.add(ReilHelpers.createBsh(baseOffset++, wd, highResult, wd, String.valueOf(16L), dw, tmpVar1));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpVar1, dw, lowResult, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 62 with OperandSize

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

the class ARMSxtahTranslator 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 wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String tmpOperand2from15to0 = environment.getNextVariableString();
    final String tmpOperand2from15to0signExtended = environment.getNextVariableString();
    final String tmpVar1 = environment.getNextVariableString();
    // compute <shifter_operand>
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String shifterOperand = shifterPair.first();
    // Operand2
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, wd, String.valueOf(0xFFFFL), dw, tmpOperand2from15to0));
    Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpOperand2from15to0, dw, tmpOperand2from15to0signExtended, 16);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, sourceRegister, dw, tmpOperand2from15to0signExtended, qw, tmpVar1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpVar1, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 63 with OperandSize

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

the class ARMSxtb16Translator 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 wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String tmpVar1 = environment.getNextVariableString();
    final String highResult = environment.getNextVariableString();
    final String lowResult = environment.getNextVariableString();
    final String tmpOperand2from23to16 = environment.getNextVariableString();
    final String tmpOperand2from23to16signExtended = environment.getNextVariableString();
    final String tmpOperand2from7to0 = environment.getNextVariableString();
    final String tmpOperand2from7to0signExtended = environment.getNextVariableString();
    final String tmpOperand2Shifted = environment.getNextVariableString();
    // compute <shifter_operand>
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String shifterOperand = shifterPair.first();
    // Operand2
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, wd, String.valueOf(0xFFL), dw, tmpOperand2from7to0));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, shifterOperand, wd, String.valueOf(-16L), dw, tmpOperand2Shifted));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpOperand2Shifted, wd, String.valueOf(0xFFL), dw, tmpOperand2from23to16));
    Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpOperand2from7to0, dw, tmpOperand2from7to0signExtended, 8);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    Helpers.signExtend(baseOffset, environment, instruction, instructions, dw, tmpOperand2from23to16, dw, tmpOperand2from23to16signExtended, 8);
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpOperand2from7to0signExtended, dw, String.valueOf(0xFFFFL), wd, lowResult));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpOperand2from23to16signExtended, dw, String.valueOf(0xFFFFL), wd, highResult));
    instructions.add(ReilHelpers.createBsh(baseOffset++, wd, highResult, wd, String.valueOf(16L), dw, tmpVar1));
    instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpVar1, dw, lowResult, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 64 with OperandSize

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

the class ARMTstTranslator 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 sourceRegister = (registerOperand1.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String tmpVar1 = environment.getNextVariableString();
    // 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();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, shifterOperand, dw, tmpVar1));
    // N Flag
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar1, dw, String.valueOf(-31L), bt, "N"));
    // Z Flag
    instructions.add(ReilHelpers.createBisz(baseOffset++, dw, tmpVar1, bt, "Z"));
    // C Flag
    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 65 with OperandSize

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

the class ARMUBFXTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
    final String operand = instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue();
    final Integer lsb = Integer.parseInt(instruction.getOperands().get(2).getRootNode().getChildren().get(0).getValue());
    final Integer width = Integer.parseInt(instruction.getOperands().get(3).getRootNode().getChildren().get(0).getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final Integer msb = (lsb + width) - 1;
    if (msb <= 31) {
        final long mask = TranslationHelpers.generateOneMask(lsb, width, OperandSize.DWORD);
        final String tempVar1 = environment.getNextVariableString();
        instructions.add(ReilHelpers.createAnd(baseOffset++, dw, operand, dw, String.valueOf(mask), dw, tempVar1));
    } else {
        instructions.add(ReilHelpers.createUnknown(baseOffset++));
    }
}
Also used : 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