use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class ShldTranslatorTest method testNull.
@Test
public void testNull() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(0x2000), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ebx", BigInteger.valueOf(0xFFFF), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "eax"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "ebx"));
final MockOperandTree operandTree3 = new MockOperandTree();
operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "0"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
final IInstruction instruction = new MockInstruction("shld", operands);
translator.translate(environment, instruction, instructions);
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
System.out.println(instructions);
long counter = 0x10000;
for (final ReilInstruction inst : instructions) {
assertEquals(counter, inst.getAddress().toLong());
counter++;
}
assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class ShldTranslatorTest method testProperMemory.
@Test
public void testProperMemory() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setMemory(100, 0xF0, 4);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.MEMDEREF, "["));
operandTree1.root.m_children.get(0).m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "100"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "ebx"));
final MockOperandTree operandTree3 = new MockOperandTree();
operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "2"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
final IInstruction instruction = new MockInstruction("shld", operands);
translator.translate(environment, instruction, instructions);
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
System.out.println(instructions);
long counter = 0x10000;
for (final ReilInstruction inst : instructions) {
assertEquals(counter, inst.getAddress().toLong());
counter++;
}
assertEquals(5, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(0x3C2, interpreter.getMemory().load(100, 4));
assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.ZERO_FLAG));
assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.CARRY_FLAG));
assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.SIGN_FLAG));
assertEquals(BigInteger.valueOf(4L), BigInteger.valueOf(interpreter.getMemorySize()));
assertEquals(BigInteger.valueOf(4L), BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class ShldTranslatorTest method testTooLarge.
@Test
public void testTooLarge() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "word");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ax"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "word");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "bx"));
final MockOperandTree operandTree3 = new MockOperandTree();
operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "17"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
final IInstruction instruction = new MockInstruction("shld", operands);
translator.translate(environment, instruction, instructions);
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
System.out.println(instructions);
long counter = 0x10000;
for (final ReilInstruction inst : instructions) {
assertEquals(counter, inst.getAddress().toLong());
counter++;
}
assertEquals(2, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class ShldTranslatorTest method testProper.
@Test
public void testProper() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("eax", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
final MockOperandTree operandTree1 = new MockOperandTree();
operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "eax"));
final MockOperandTree operandTree2 = new MockOperandTree();
operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "ebx"));
final MockOperandTree operandTree3 = new MockOperandTree();
operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "2"));
final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
final IInstruction instruction = new MockInstruction("shld", operands);
translator.translate(environment, instruction, instructions);
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
System.out.println(instructions);
long counter = 0x10000;
for (final ReilInstruction inst : instructions) {
assertEquals(counter, inst.getAddress().toLong());
counter++;
}
assertEquals(6, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
assertEquals(BigInteger.valueOf(2L), interpreter.getVariableValue("eax"));
assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.ZERO_FLAG));
assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.CARRY_FLAG));
assertEquals(BigInteger.valueOf(0), interpreter.getVariableValue(Helpers.SIGN_FLAG));
assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.
the class StateCombiner method combine.
private static ValueTrackerElement combine(final ValueTrackerElement state1, final ValueTrackerElement state2) {
final Map<IAloc, IValueElement> values1 = state1.getStates();
final Map<IAloc, IValueElement> values2 = state2.getStates();
final Map<IAloc, IValueElement> combinedState = new HashMap<IAloc, IValueElement>();
final Set<ReilInstruction> combinedInfluences = state1.getInfluences();
combinedInfluences.addAll(state2.getInfluences());
final Map<String, Set<IAddress>> combinedWritten = new HashMap<String, Set<IAddress>>();
combinedWritten.putAll(state1.getLastWritten());
for (final Map.Entry<String, Set<IAddress>> lastWritten : state2.getLastWritten().entrySet()) {
if (combinedWritten.containsKey(lastWritten.getKey())) {
combinedWritten.get(lastWritten.getKey()).addAll(lastWritten.getValue());
} else {
combinedWritten.put(lastWritten.getKey(), new HashSet<IAddress>(lastWritten.getValue()));
}
}
for (final Map.Entry<IAloc, IValueElement> entry : values1.entrySet()) {
final IAloc aloc = entry.getKey();
if (values2.containsKey(aloc)) {
final IValueElement lhs = entry.getValue();
final IValueElement rhs = values2.get(aloc);
combinedState.put(aloc, combine(lhs, rhs));
} else {
combinedState.put(aloc, new Undefined());
}
}
for (final Map.Entry<IAloc, IValueElement> entry : values2.entrySet()) {
final IAloc aloc = entry.getKey();
if (!values1.containsKey(aloc)) {
combinedState.put(aloc, new Undefined());
}
}
if ((combinedState.size() < state1.getStates().size()) || (combinedState.size() < state2.getStates().size())) {
throw new IllegalStateException();
}
return new ValueTrackerElement(combinedInfluences, combinedState, combinedWritten);
}
Aggregations