Search in sources :

Example 1 with Register

use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register in project binnavi by google.

the class BaseTransformer method transformRegisterLiteral.

/**
   * Transforms MNEM R1, L1, R2 to (R2 => COMBINE(R1, L1))
   * 
   * @param instruction The instruction in question.
   * @param incomingState The incoming state from the parents of the instruction.
   * @param generator Combines the input operand values of the instruction.
   * 
   * @return The new state of the graph node that represents the instruction.
   */
protected static ValueTrackerElement transformRegisterLiteral(final ReilInstruction instruction, final ValueTrackerElement incomingState, final IElementGenerator generator) {
    // Combine a register to a literal. This means we have to look up the state of the input
    // register
    // in the incoming state.
    final boolean registerFirst = inputOperandsAreRegisterLiteral(instruction);
    final ReilOperand registerOperand = registerFirst ? instruction.getFirstOperand() : instruction.getSecondOperand();
    final ReilOperand literalOperand = registerFirst ? instruction.getSecondOperand() : instruction.getFirstOperand();
    final ReilOperand outputOperand = instruction.getThirdOperand();
    final IValueElement previousState = incomingState.getState(registerOperand.getValue());
    final IValueElement result = getOutputValue(registerOperand, previousState, literalOperand, null, generator);
    if (previousState instanceof BitwiseAnd) {
        return AndSimplifier.simplifyAnd(instruction, registerOperand, literalOperand, (BitwiseAnd) previousState, incomingState, generator);
    } else {
        return incomingState.update(instruction, new Register(outputOperand.getValue()), result);
    }
}
Also used : IValueElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement) Register(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register) BitwiseAnd(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.BitwiseAnd) ReilOperand(com.google.security.zynamics.reil.ReilOperand)

Example 2 with Register

use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register in project binnavi by google.

the class BiszTransformer method transform.

public static ValueTrackerElement transform(final ReilInstruction instruction, final ValueTrackerElement incomingState) {
    final ReilOperand inputOperand = instruction.getFirstOperand();
    final ReilOperand outputOperand = instruction.getThirdOperand();
    final Register outputRegister = new Register(outputOperand.getValue());
    final IValueElement inputValue = getOperandValue(inputOperand, incomingState);
    final IValueElement outputValue = getOutputValue(inputOperand, inputValue);
    return incomingState.update(instruction, outputRegister, outputValue);
}
Also used : IValueElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement) Register(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register) ReilOperand(com.google.security.zynamics.reil.ReilOperand)

Example 3 with Register

use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register in project binnavi by google.

the class LdmTransformer method transform.

public static ValueTrackerElement transform(final ReilInstruction instruction, final ValueTrackerElement incomingState) {
    final ReilOperand memoryAddressOperand = instruction.getFirstOperand();
    final ReilOperand outputOperand = instruction.getThirdOperand();
    final Register outputRegister = new Register(outputOperand.getValue());
    final IValueElement memoryAddress = getOperandValue(memoryAddressOperand, incomingState);
    if ((memoryAddress == null) || (memoryAddress instanceof Undefined)) {
        final IValueElement memoryAddressValue = getAtomicType(memoryAddressOperand);
        final Dereference dereference = new Dereference(memoryAddressValue);
        return incomingState.update(instruction, outputRegister, dereference);
    } else {
        final IValueElement previousState2 = incomingState.getState(new MemoryCell(memoryAddress));
        if (previousState2 == null) {
            return incomingState.update(instruction, outputRegister, new Dereference(memoryAddress));
        } else {
            return incomingState.update(instruction, outputRegister, previousState2);
        }
    }
}
Also used : Undefined(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Undefined) IValueElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement) Register(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register) ReilOperand(com.google.security.zynamics.reil.ReilOperand) Dereference(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Dereference) MemoryCell(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.MemoryCell)

Example 4 with Register

use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register in project binnavi by google.

the class AndSimplifier method simplifyAnd.

public static ValueTrackerElement simplifyAnd(final ReilInstruction instruction, final ReilOperand firstOperand, final ReilOperand secondOperand, final BitwiseAnd previousAnd, final ValueTrackerElement state, final IElementGenerator generator) {
    final ReilOperand thirdOperand = instruction.getThirdOperand();
    final Register targetRegister = new Register(thirdOperand.getValue());
    if (isTruncateMask(previousAnd.getLhs(), firstOperand.getSize())) {
        // (0xFFFFFFFF & X) + Y => (X + Y) & 0xFFFFFFFF
        // final Addition newAddition = new Addition(previousAnd.getRhs(), new Literal(new
        // BigInteger(secondOperand.getValue())));
        final IValueElement newAddition = generator.generate(previousAnd.getRhs(), new Literal(new BigInteger(secondOperand.getValue())));
        final BitwiseAnd newBitwiseAnd = new BitwiseAnd(new Literal(newAddition.evaluate()), previousAnd.getLhs());
        return state.update(instruction, targetRegister, newBitwiseAnd);
    } else if (isTruncateMask(previousAnd.getRhs(), firstOperand.getSize())) {
        // (X & 0xFFFFFFFF) + Y => (X + Y) & 0xFFFFFFFF
        final IValueElement previousLhs = previousAnd.getLhs();
        if (previousLhs instanceof Undefined) {
            return state.update(instruction, targetRegister, new Undefined());
        } else {
            // final Addition newAddition = new Addition(previousLhs, new Literal(new
            // BigInteger(secondOperand.getValue())));
            final IValueElement newAddition = generator.generate(previousLhs, new Literal(new BigInteger(secondOperand.getValue())));
            final BitwiseAnd newBitwiseAnd = new BitwiseAnd(newAddition.getSimplified(), previousAnd.getRhs());
            return state.update(instruction, targetRegister, newBitwiseAnd);
        }
    } else {
        final IValueElement previousState = state.getState(firstOperand.getValue());
        // final IValueElement addition = new Addition(previousState, new Literal(new
        // BigInteger(secondOperand.getValue())));
        final IValueElement addition = generator.generate(previousState, new Literal(new BigInteger(secondOperand.getValue())));
        return state.update(instruction, targetRegister, addition);
    }
}
Also used : Undefined(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Undefined) IValueElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement) Register(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register) Literal(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Literal) BitwiseAnd(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.BitwiseAnd) ReilOperand(com.google.security.zynamics.reil.ReilOperand) BigInteger(java.math.BigInteger)

Example 5 with Register

use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register in project binnavi by google.

the class BaseTransformer method transformRegisters.

/**
   * Transforms MNEM R1, R2, R3 to (R3 => COMBINE(R1, R2))
   * 
   * @param instruction The instruction in question.
   * @param incomingState The incoming state from the parents of the instruction.
   * @param generator Combines the input operand values of the instruction.
   * 
   * @return The new state of the graph node that represents the instruction.
   */
protected static ValueTrackerElement transformRegisters(final ReilInstruction instruction, final ValueTrackerElement incomingState, final IElementGenerator generator) {
    final ReilOperand firstOperand = instruction.getFirstOperand();
    final ReilOperand secondOperand = instruction.getSecondOperand();
    final ReilOperand thirdOperand = instruction.getThirdOperand();
    final IValueElement previousState1 = incomingState.getState(firstOperand.getValue());
    final IValueElement previousState2 = incomingState.getState(secondOperand.getValue());
    final IValueElement outputValue = getOutputValue(firstOperand, previousState1, secondOperand, previousState2, generator);
    return incomingState.update(instruction, new Register(thirdOperand.getValue()), outputValue);
}
Also used : IValueElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement) Register(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register) ReilOperand(com.google.security.zynamics.reil.ReilOperand)

Aggregations

ReilOperand (com.google.security.zynamics.reil.ReilOperand)7 IValueElement (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement)7 Register (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Register)7 BitwiseAnd (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.BitwiseAnd)2 Literal (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Literal)2 Undefined (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Undefined)2 Dereference (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Dereference)1 MemoryCell (com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.MemoryCell)1 BigInteger (java.math.BigInteger)1