Search in sources :

Example 6 with OperandSize

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

the class THUMBUxthTranslator 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 = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0xFFFFL), dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 7 with OperandSize

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

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

Example 8 with OperandSize

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

the class ConditionGenerator method generate.

public static void generate(final long offset, final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions, final String extension, final String jumpGoal) throws InternalTranslationException {
    Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
    Preconditions.checkNotNull(instruction, "Error: Argument instruction can't be null");
    Preconditions.checkNotNull(instructions, "Error: Argument instructions can't be null");
    /*
     * 2.5.2 Execution conditions The relation of condition code suffixes to the N, Z, C and V flags
     * is shown in Table 2-1. Table 2-1 Condition code suffixes Suffix Flags Meaning EQ Z set Equal
     * NE Z clear Not equal CS/HS C set Higher or same (unsigned >= ) CC/LO C clear Lower (unsigned
     * < ) MI N set Negative PL N clear Positive or zero VS V set Overflow VC V clear No overflow HI
     * C set and Z clear Higher (unsigned > ) LS C clear or Z set Lower or same (unsigned <= ) GE N
     * and V the same Signed >= LT N and V differ Signed < GT Z clear, N and V the same Signed > LE
     * Z set, N and V differ Signed <= AL Any Always. This suffix is normally omitted.
     */
    final OperandSize bt = OperandSize.BYTE;
    // final OperandSize dw = OperandSize.DWORD;
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    final String jumpCondition = environment.getNextVariableString();
    long baseOffset = offset;
    final String[] meta = new String[0];
    if (extension.compareTo("EQ") == 0) {
        /*
       * z set
       */
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, "Z", bt, jumpCondition));
    } else if (extension.compareTo("NE") == 0) {
        /*
       * z not set
       */
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, "Z", bt, jumpCondition));
    } else if ((extension.compareTo("CS") == 0) || (extension.compareTo("HS") == 0)) {
        /*
       * c set
       */
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, "C", bt, jumpCondition));
    } else if ((extension.compareTo("CC") == 0) || (extension.compareTo("LO") == 0)) {
        /*
       * c not set
       */
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, "C", bt, jumpCondition));
    } else if (extension.compareTo("MI") == 0) {
        /*
       * n set
       */
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, "N", bt, jumpCondition));
    } else if (extension.compareTo("PL") == 0) {
        /*
       * n not set
       */
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, "N", bt, jumpCondition));
    } else if (extension.compareTo("VS") == 0) {
        /*
       * v set
       */
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, "V", bt, jumpCondition));
    } else if (extension.compareTo("VC") == 0) {
        /*
       * v not set
       */
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, "V", bt, jumpCondition));
    } else if (extension.compareTo("HI") == 0) {
        /*
       * c set and z not set
       */
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, "C", bt, tmpVar1));
        instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar1, bt, "Z", bt, jumpCondition));
    } else if (extension.compareTo("LS") == 0) {
        /*
       * c not set and z set
       */
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, "Z", bt, tmpVar1));
        instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar1, bt, "C", bt, jumpCondition));
    } else if (extension.compareTo("GE") == 0) {
        /*
       * n equal v
       */
        instructions.add(ReilHelpers.createXor(baseOffset++, bt, "N", bt, "V", bt, tmpVar1));
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, tmpVar1, bt, jumpCondition));
    } else if (extension.compareTo("LT") == 0) {
        /*
       * n is not equal v
       */
        instructions.add(ReilHelpers.createXor(baseOffset++, bt, "N", bt, "V", bt, tmpVar1));
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, tmpVar1, bt, jumpCondition));
    } else if (extension.compareTo("GT") == 0) {
        /*
       * z clear and n equals v
       */
        instructions.add(ReilHelpers.createXor(baseOffset++, bt, "N", bt, "V", bt, tmpVar1));
        instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar1, bt, "Z", bt, jumpCondition));
    } else if (extension.compareTo("LE") == 0) {
        /*
       * z set and n is not equal v
       */
        instructions.add(ReilHelpers.createXor(baseOffset++, bt, "N", bt, "V", bt, tmpVar1));
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, tmpVar1, bt, tmpVar3));
        instructions.add(ReilHelpers.createBisz(baseOffset++, bt, "Z", bt, tmpVar2));
        instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar3, bt, tmpVar2, bt, jumpCondition));
    } else if (extension.compareTo("AL") == 0) {
        /*
       * any
       */
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, String.valueOf(0L), bt, jumpCondition));
    } else if (extension.compareTo("NV") == 0) {
        /*
       * none
       */
        instructions.add(ReilHelpers.createStr(baseOffset++, bt, String.valueOf(1L), bt, jumpCondition));
    } else {
        throw new InternalTranslationException("ERROR: unknown condition " + extension);
    }
    instructions.add(ReilHelpers.createJcc(baseOffset++, bt, jumpCondition, OperandSize.ADDRESS, jumpGoal, meta));
}
Also used : InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 9 with OperandSize

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

the class Helpers method addOverflow.

/**
   * @param offset
   * @param environment A valid REIL translation environment
   * @param instructions A list of REIL instructions where the new REIL code is added
   * @param firstOperand A String containing the first Operand witch was added
   * @param secondOperand A String containing the second Operand witch was added
   * @param resultOperand A String holding the result of the addition
   * @param overflow A String which is set to 1 if Overflow has occurred
   * @param size A long holding the size for overflow calculation
   */
public static void addOverflow(final long offset, final ITranslationEnvironment environment, final List<ReilInstruction> instructions, final OperandSize firstOperandSize, final String firstOperand, final OperandSize secondOperandSize, final String secondOperand, final OperandSize resultOperandSize, final String resultOperand, final String overflow, final long size) throws IllegalArgumentException {
    Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
    Preconditions.checkNotNull(firstOperand, "Error: Argument firstOperand can't be null");
    Preconditions.checkNotNull(secondOperand, "Error: Argument secondOperand can't be null");
    Preconditions.checkNotNull(resultOperand, "Error: Argument resultOperand can't be null");
    Preconditions.checkArgument(size != 0, "Error: Argument size can't be null");
    Preconditions.checkNotNull(instructions, "Error: Argument instructions can't be null");
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize wd = OperandSize.WORD;
    final String msbVara = environment.getNextVariableString();
    final String msbVarb = environment.getNextVariableString();
    final String msbVarr = environment.getNextVariableString();
    final String tmpVar3 = environment.getNextVariableString();
    final String tmpVar4 = environment.getNextVariableString();
    final String shiftValue = "-" + String.valueOf(size - 1);
    long baseOffset = offset;
    // Isolate summands msb's
    instructions.add(ReilHelpers.createBsh(baseOffset++, firstOperandSize, firstOperand, wd, shiftValue, bt, msbVara));
    instructions.add(ReilHelpers.createBsh(baseOffset++, secondOperandSize, secondOperand, wd, shiftValue, bt, msbVarb));
    // Isolate MSB(Result)
    instructions.add(ReilHelpers.createBsh(baseOffset++, resultOperandSize, resultOperand, wd, shiftValue, bt, msbVarr));
    // clean leftovers
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, msbVara, bt, String.valueOf(1), bt, msbVara));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, msbVarb, bt, String.valueOf(1), bt, msbVarb));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, msbVarr, bt, String.valueOf(1), bt, msbVarr));
    // perform overflow calculation ( msbA XOR msbR ) AND ( msbB XOR msbR ) == OF
    instructions.add(ReilHelpers.createXor(baseOffset++, bt, msbVara, bt, msbVarr, bt, tmpVar4));
    instructions.add(ReilHelpers.createXor(baseOffset++, bt, msbVarb, bt, msbVarr, bt, tmpVar3));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar4, bt, tmpVar3, bt, overflow));
}
Also used : OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 10 with OperandSize

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

the class Helpers method signExtend.

/**
   * sign Extend 8,16,32 Bit Registers
   *
   * @param offset
   * @param environment
   * @param instruction
   * @param instructions
   * @param firstOperand
   * @param resultOperand
   * @param size
   */
public static void signExtend(final long offset, final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions, final OperandSize firstOperandSize, final String firstOperand, final OperandSize resultOperandSize, final String resultOperand, final int size) {
    final OperandSize dw = OperandSize.DWORD;
    String fMask = "";
    String eightMask = "";
    final String tmpVar1 = environment.getNextVariableString();
    final String tmpVar2 = environment.getNextVariableString();
    if (size == 8) {
        fMask = String.valueOf(0xFFL);
        eightMask = String.valueOf(0x80L);
    } else if (size == 16) {
        fMask = String.valueOf(0xFFFFL);
        eightMask = String.valueOf(0x8000L);
    } else /* size == 32 */
    {
        fMask = String.valueOf(0xFFFFFFFFL);
        eightMask = String.valueOf(0x80000000L);
    }
    long baseOffset = offset;
    instructions.add(ReilHelpers.createAdd(baseOffset++, firstOperandSize, firstOperand, dw, eightMask, dw, tmpVar1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar1, dw, fMask, dw, tmpVar2));
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, tmpVar2, dw, eightMask, resultOperandSize, resultOperand));
}
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