Search in sources :

Example 1 with MockInstruction

use of com.google.security.zynamics.zylib.disassembly.MockInstruction in project binnavi by google.

the class SwrTranslatorTest method test1SwrAddressBitsZeroLittleEndian.

@Test
public void test1SwrAddressBitsZeroLittleEndian() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("$v1", BigInteger.valueOf(0x10000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("$v2", BigInteger.valueOf(0x55667788L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$v2"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.OPERATOR, "+"));
    operandTree2.root.getChildren().get(0).m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$v1"));
    operandTree2.root.getChildren().get(0).m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, String.valueOf(0L)));
    interpreter.setMemory(0x10000000, 0x11223344L, 4);
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);
    final IInstruction instruction = new MockInstruction("swr", operands);
    translator.translate(environment, instruction, instructions);
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    // check correct outcome
    assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(0x55667788L), interpreter.getVariableValue("$v2"));
    assertEquals(BigInteger.valueOf(0x55667788L), BigInteger.valueOf(interpreter.readMemoryDword(0x10000000L)));
    assertEquals(BigInteger.valueOf(4L), BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Example 2 with MockInstruction

use of com.google.security.zynamics.zylib.disassembly.MockInstruction in project binnavi by google.

the class XorTranslatorTest method test2XorTwo.

@Test
public void test2XorTwo() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("$a0", BigInteger.ZERO, OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("$a3", BigInteger.valueOf(0x55667788L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("$v2", BigInteger.valueOf(0x00001234L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$a0"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$a3"));
    final MockOperandTree operandTree3 = new MockOperandTree();
    operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$v2"));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
    final IInstruction instruction = new MockInstruction("xor", operands);
    translator.translate(environment, instruction, instructions);
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    // check correct outcome
    assertEquals(4, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(0x556665bcL), interpreter.getVariableValue("$a0"));
    assertEquals(BigInteger.valueOf(0x55667788L), interpreter.getVariableValue("$a3"));
    assertEquals(BigInteger.valueOf(0x1234L), interpreter.getVariableValue("$v2"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Example 3 with MockInstruction

use of com.google.security.zynamics.zylib.disassembly.MockInstruction in project binnavi by google.

the class XoriTranslatorTest method test1XoriOne.

@Test
public void test1XoriOne() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("$v1", BigInteger.ZERO, OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("$ra", BigInteger.valueOf(0x11223344L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$v1"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$ra"));
    final MockOperandTree operandTree3 = new MockOperandTree();
    operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, String.valueOf(0x00000F0FL)));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
    final IInstruction instruction = new MockInstruction("xori", operands);
    translator.translate(environment, instruction, instructions);
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    // check correct outcome
    assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(0x11223c4bL), interpreter.getVariableValue("$v1"));
    assertEquals(BigInteger.valueOf(0x11223344L), interpreter.getVariableValue("$ra"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Example 4 with MockInstruction

use of com.google.security.zynamics.zylib.disassembly.MockInstruction in project binnavi by google.

the class XoriTranslatorTest method test2XoriTwo.

@Test
public void test2XoriTwo() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("$a0", BigInteger.ZERO, OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("$a3", BigInteger.valueOf(0x55667788L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$a0"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$a3"));
    final MockOperandTree operandTree3 = new MockOperandTree();
    operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, String.valueOf(0x00001234L)));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
    final IInstruction instruction = new MockInstruction("xori", operands);
    translator.translate(environment, instruction, instructions);
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    // check correct outcome
    assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(0x556665bcL), interpreter.getVariableValue("$a0"));
    assertEquals(BigInteger.valueOf(0x55667788L), interpreter.getVariableValue("$a3"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Example 5 with MockInstruction

use of com.google.security.zynamics.zylib.disassembly.MockInstruction in project binnavi by google.

the class AddDotTranslatorTest method testSimple.

@Test
public void testSimple() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("CR0EQ", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("CR0SO", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("CR0GT", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("CR0LT", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("%r0", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("%r1", BigInteger.valueOf(0x4000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("%r2", BigInteger.valueOf(0x4000L), 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.REGISTER, "%r0"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "%r1"));
    final MockOperandTree operandTree3 = new MockOperandTree();
    operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "%r2"));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
    final IInstruction instruction = new MockInstruction("add.", operands);
    translator.translate(environment, instruction, instructions);
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100L));
    assertEquals(BigInteger.valueOf(0x8000L), interpreter.getVariableValue("%r0"));
    assertEquals(BigInteger.valueOf(0x4000L), interpreter.getVariableValue("%r1"));
    assertEquals(BigInteger.valueOf(0x4000L), interpreter.getVariableValue("%r2"));
    assertEquals(BigInteger.ONE, interpreter.getVariableValue("CR0GT"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("CR0LT"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("CR0EQ"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("CR0SO"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
    assertEquals(8, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
}
Also used : MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Aggregations

MockInstruction (com.google.security.zynamics.zylib.disassembly.MockInstruction)1054 MockOperandTree (com.google.security.zynamics.zylib.disassembly.MockOperandTree)1051 Test (org.junit.Test)1050 MockOperandTreeNode (com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode)963 IInstruction (com.google.security.zynamics.zylib.disassembly.IInstruction)954 ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)16 ArrayList (java.util.ArrayList)11 List (java.util.List)7 BigInteger (java.math.BigInteger)6 ReilFunction (com.google.security.zynamics.reil.ReilFunction)5 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)4 HashSet (java.util.HashSet)4 ReilGraph (com.google.security.zynamics.reil.ReilGraph)3 StandardEnvironment (com.google.security.zynamics.reil.translators.StandardEnvironment)3 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)3 HashMap (java.util.HashMap)3 MockCodeContainer (com.google.security.zynamics.zylib.disassembly.MockCodeContainer)2 CCallsDescription (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.InstructionHighlighter.CCallsDescription)1 CResultsTableModel (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.InstructionHighlighter.CResultsTableModel)1 CSpecialInstruction (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.InstructionHighlighter.CSpecialInstruction)1