Search in sources :

Example 1 with OperandType

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

the class BaseTransformer method inputOperandsAreRegisters.

/**
   * Determines whether the two input operands of an instruction are both registers.
   * 
   * @param instruction The instruction whose input operands are checked.
   * 
   * @return True, if both input operands of the instruction are registers.
   */
private static boolean inputOperandsAreRegisters(final ReilInstruction instruction) {
    final OperandType firstOperandType = instruction.getFirstOperand().getType();
    final OperandType secondOperandType = instruction.getSecondOperand().getType();
    return (firstOperandType == OperandType.REGISTER) && (secondOperandType == OperandType.REGISTER);
}
Also used : OperandType(com.google.security.zynamics.reil.OperandType)

Example 2 with OperandType

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

the class StmTransformer method transform.

public static ValueTrackerElement transform(final ReilInstruction instruction, final ValueTrackerElement state) {
    // STM x, , y
    final ReilOperand inputOperand = instruction.getFirstOperand();
    final ReilOperand addressOperand = instruction.getThirdOperand();
    final OperandType inputOperandType = inputOperand.getType();
    if (inputOperandType == OperandType.INTEGER_LITERAL) {
        final IValueElement previousAddressState = state.getState(addressOperand.getValue());
        final IValueElement outputValue = getValue(inputOperand, previousAddressState);
        if ((previousAddressState == null) || (previousAddressState instanceof Undefined)) {
            final IValueElement newThirdState = getAtomicType(addressOperand);
            return state.update(instruction, new MemoryCell(newThirdState), outputValue);
        } else {
            final IValueElement previousState2b = state.getState(new MemoryCell(previousAddressState));
            if ((previousState2b == null) || (previousState2b instanceof Undefined)) {
                return state.update(instruction, new MemoryCell(previousAddressState), outputValue);
            } else {
                return state.update(instruction, new MemoryCell(previousState2b), outputValue);
            }
        }
    } else if (inputOperandType == OperandType.REGISTER) {
        final IValueElement newThirdState = getAtomicType(addressOperand);
        final IValueElement previousStateInput = state.getState(inputOperand.getValue());
        final IValueElement previousState2 = getOperandValue(addressOperand, state);
        if ((previousStateInput == null) && (previousState2 == null)) {
            return state.update(instruction, new MemoryCell(newThirdState), getAtomicType(inputOperand));
        } else if ((previousStateInput == null) && (previousState2 != null)) {
            final IValueElement previousState2b = state.getState(new MemoryCell(previousState2));
            if (previousState2b == null) {
                return state.update(instruction, new MemoryCell(previousState2), getAtomicType(inputOperand));
            } else {
                return state.update(instruction, new MemoryCell(previousState2b), getAtomicType(inputOperand));
            }
        } else if ((previousStateInput != null) && (previousState2 == null)) {
            return state.update(instruction, new MemoryCell(newThirdState), previousStateInput);
        } else if (previousState2 instanceof Undefined) {
            return state.update(instruction, new MemoryCell(newThirdState), new Undefined());
        } else {
            final IValueElement previousState2b = state.getState(new MemoryCell(previousState2));
            if ((previousState2b == null) || (previousState2b instanceof Undefined)) {
                return state.update(instruction, new MemoryCell(previousState2), previousStateInput);
            } else {
                return state.update(instruction, new MemoryCell(previousState2b), previousStateInput);
            }
        }
    }
    throw new IllegalStateException("Not yet implemented");
}
Also used : Undefined(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Undefined) IValueElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement) OperandType(com.google.security.zynamics.reil.OperandType) ReilOperand(com.google.security.zynamics.reil.ReilOperand) MemoryCell(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.MemoryCell)

Example 3 with OperandType

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

the class ReilInterpreter method loadLongValue.

/**
   * Loads the value of an operand into a long value.
   *
   * @param operand The operand to load
   * @return A pair made of a bool and a long value. The bool indicates whether loading the value
   *         was successful.
   */
private Pair<Boolean, BigInteger> loadLongValue(final ReilOperand operand) {
    final OperandType type = operand.getType();
    String value = operand.getValue();
    if (type == OperandType.INTEGER_LITERAL) {
        return new Pair<Boolean, BigInteger>(true, new BigInteger(value));
    } else if (type == OperandType.REGISTER) {
        // Check if we have a negative prefix before the register name. This is
        // a bit of a hack, because we never explicitly stated that we would allow
        // a negation of a register operand in REIL.
        // TODO(thomasdullien) remove this code once we have introduced explicit 
        // left-shift and right-shift instructions.
        value = (value.charAt(0) == '-') ? operand.getValue().substring(1) : value;
        return !isDefined(value) ? new Pair<Boolean, BigInteger>(false, BigInteger.ZERO) : new Pair<Boolean, BigInteger>(true, getVariableValue(value));
    } else {
        return new Pair<Boolean, BigInteger>(false, BigInteger.ZERO);
    }
}
Also used : OperandType(com.google.security.zynamics.reil.OperandType) BigInteger(java.math.BigInteger) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 4 with OperandType

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

the class BaseTransformer method inputOperandsAreLiteralRegister.

/**
   * Determines whether the two input operands of an instruction are a literal (first operand) and a
   * register (second operand).
   * 
   * @param instruction The instruction whose input operands are checked.
   * 
   * @return True, if the first operand is a literal and the second operand is a register. False,
   *         otherwise.
   */
private static boolean inputOperandsAreLiteralRegister(final ReilInstruction instruction) {
    final OperandType firstOperandType = instruction.getFirstOperand().getType();
    final OperandType secondOperandType = instruction.getSecondOperand().getType();
    return (firstOperandType == OperandType.INTEGER_LITERAL) && (secondOperandType == OperandType.REGISTER);
}
Also used : OperandType(com.google.security.zynamics.reil.OperandType)

Example 5 with OperandType

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

the class BaseTransformer method inputOperandsAreRegisterLiteral.

/**
   * Determines whether the two input operands of an instruction are a register (first operand) and
   * a literal (second operand).
   * 
   * @param instruction The instruction whose input operands are checked.
   * 
   * @return True, if the first operand is a register and the second operand is a literal. False,
   *         otherwise.
   */
protected static boolean inputOperandsAreRegisterLiteral(final ReilInstruction instruction) {
    final OperandType firstOperandType = instruction.getFirstOperand().getType();
    final OperandType secondOperandType = instruction.getSecondOperand().getType();
    return (firstOperandType == OperandType.REGISTER) && (secondOperandType == OperandType.INTEGER_LITERAL);
}
Also used : OperandType(com.google.security.zynamics.reil.OperandType)

Aggregations

OperandType (com.google.security.zynamics.reil.OperandType)9 OperandSize (com.google.security.zynamics.reil.OperandSize)2 ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)2 InternalTranslationException (com.google.security.zynamics.reil.translators.InternalTranslationException)2 TranslationResult (com.google.security.zynamics.reil.translators.TranslationResult)2 Pair (com.google.security.zynamics.zylib.general.Pair)2 ReilOperand (com.google.security.zynamics.reil.ReilOperand)1 IValueElement (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement)1 MemoryCell (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.MemoryCell)1 Undefined (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Undefined)1 TranslationResultType (com.google.security.zynamics.reil.translators.TranslationResultType)1 IOperandTree (com.google.security.zynamics.zylib.disassembly.IOperandTree)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1