use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Literal in project binnavi by google.
the class AddTransformerTest method testAddConstants.
@Test
public void testAddConstants() {
final ReilInstruction instruction = ReilHelpers.createAdd(0x100, OperandSize.DWORD, "2", OperandSize.DWORD, "4", OperandSize.QWORD, "t0");
final ValueTrackerElement state = new ValueTrackerElement();
final ValueTrackerElement result = AddTransformer.transform(instruction, state);
assertTrue(result.getState("t0") instanceof Literal);
assertEquals(6, ((Literal) result.getState("t0")).getValue().longValue());
}
use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Literal in project binnavi by google.
the class AddTransformerTest method testAddRegisterConstant.
@Test
public void testAddRegisterConstant() {
final ReilInstruction instruction = ReilHelpers.createAdd(0x100, OperandSize.DWORD, "t0", OperandSize.DWORD, "4", OperandSize.QWORD, "t1");
final ValueTrackerElement state = new ValueTrackerElement();
final ValueTrackerElement result = AddTransformer.transform(instruction, state);
assertTrue(result.getState("t1") instanceof Addition);
assertTrue(((Addition) result.getState("t1")).getLhs() instanceof Symbol);
assertTrue(((Addition) result.getState("t1")).getRhs() instanceof Literal);
}
use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Literal 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);
}
}
use of com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Literal in project binnavi by google.
the class BaseTransformer method transformLiterals.
/**
* Transforms MNEM L1, L2, R1 to (R1 => CALC(L1, L2))
*
* @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 transformLiterals(final ReilInstruction instruction, final ValueTrackerElement incomingState, final IElementGenerator generator) {
// The easiest case is handling the combination of two integer literals.
// The result of this combination is obviously another literal.
final ReilOperand firstOperand = instruction.getFirstOperand();
final ReilOperand secondOperand = instruction.getSecondOperand();
final String thirdOperand = instruction.getThirdOperand().getValue();
// Now we can update the state of the registers after this instruction is executed.
// The register in the output operand is updated while the values of all other
// registers are taken from the incoming state.
final Register resultAloc = new Register(thirdOperand);
final IValueElement alocValue = generator.generate(getAtomicType(firstOperand), getAtomicType(secondOperand));
assert alocValue instanceof Literal : "The combination of two literals was not a literal";
return incomingState.update(instruction, resultAloc, alocValue);
}
Aggregations