Search in sources :

Example 1 with MockCodeContainer

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

the class RegisterTrackerTest method setUp.

@Before
public void setUp() throws InternalTranslationException {
    final MockOperandTree operandTreeFirst1 = new MockOperandTree();
    operandTreeFirst1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTreeFirst1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ecx"));
    final MockOperandTree operandTreeFirst2 = new MockOperandTree();
    operandTreeFirst2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTreeFirst2.root.m_children.add(new MockOperandTreeNode(ExpressionType.MEMDEREF, "["));
    operandTreeFirst2.root.m_children.get(0).m_children.add(new MockOperandTreeNode(ExpressionType.OPERATOR, "+"));
    operandTreeFirst2.root.m_children.get(0).m_children.get(0).m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ebp"));
    operandTreeFirst2.root.m_children.get(0).m_children.get(0).m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "5"));
    final List<MockOperandTree> operandsFirst = Lists.newArrayList(operandTreeFirst1, operandTreeFirst2);
    m_movInstruction = new MockInstruction(Long.parseLong("5"), "mov", operandsFirst);
    final MockOperandTree operandTreeSecond1 = new MockOperandTree();
    operandTreeSecond1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTreeSecond1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ecx"));
    final MockOperandTree operandTreeSecond2 = new MockOperandTree();
    operandTreeSecond2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTreeSecond2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "edx"));
    final MockOperandTree operandTreesecond3 = new MockOperandTree();
    operandTreesecond3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "byte");
    operandTreesecond3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "9"));
    final List<MockOperandTree> operandsSecond = Lists.newArrayList(operandTreeSecond1, operandTreeSecond2, operandTreesecond3);
    m_shldInstruction = new MockInstruction(Long.parseLong("8"), "shld", operandsSecond);
    final MockCodeContainer block = new MockCodeContainer();
    block.m_instructions.add(m_movInstruction);
    block.m_instructions.add(m_shldInstruction);
    final ReilTranslator<MockInstruction> reilTranslator = new ReilTranslator<MockInstruction>();
    m_graph = reilTranslator.translate(environment, block);
    m_function = new ReilFunction("REGISTER_TRACKER_TEST", m_graph);
}
Also used : MockCodeContainer(com.google.security.zynamics.zylib.disassembly.MockCodeContainer) MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) ReilTranslator(com.google.security.zynamics.reil.translators.ReilTranslator) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) ReilFunction(com.google.security.zynamics.reil.ReilFunction) Before(org.junit.Before)

Example 2 with MockCodeContainer

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

the class ReilTranslatorTest method testRepStosStos.

@Test
public void testRepStosStos() throws InternalTranslationException {
    final MockCodeContainer container = new MockCodeContainer();
    container.m_instructions.add(new MockInstruction(0x100, "rep stosb", Lists.newArrayList(new MockOperandTree(), new MockOperandTree())));
    container.m_instructions.add(new MockInstruction(0x200, "stosb", new ArrayList<MockOperandTree>()));
    final ReilGraph g = m_translator.translate(new StandardEnvironment(), container);
    System.out.println(g);
    assertEquals(9, g.nodeCount());
    assertEquals(11, g.edgeCount());
}
Also used : ReilGraph(com.google.security.zynamics.reil.ReilGraph) MockCodeContainer(com.google.security.zynamics.zylib.disassembly.MockCodeContainer) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) ArrayList(java.util.ArrayList) StandardEnvironment(com.google.security.zynamics.reil.translators.StandardEnvironment) Test(org.junit.Test)

Example 3 with MockCodeContainer

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

the class ReilTranslatorTest method testInlinedFunctionGeneration.

@Test
public void testInlinedFunctionGeneration() throws InternalTranslationException {
    final MockBlockContainer container = new MockBlockContainer();
    final MockCodeContainer block1 = new MockCodeContainer();
    block1.m_instructions.add(createMov(0x1000, "eax", "1"));
    final MockCodeContainer block2 = new MockCodeContainer();
    block2.m_instructions.add(createMov(0x1200, "ebx", "eax"));
    final MockCodeContainer block3 = new MockCodeContainer();
    block3.m_instructions.add(createMov(0x1001, "ecx", "ebx"));
    container.m_blocks.add(block1);
    container.m_blocks.add(block2);
    container.m_blocks.add(block3);
    container.m_edges.add(new MockCodeEdge<MockCodeContainer>(block1, block2, EdgeType.ENTER_INLINED_FUNCTION));
    container.m_edges.add(new MockCodeEdge<MockCodeContainer>(block2, block3, EdgeType.LEAVE_INLINED_FUNCTION));
    final ReilFunction function = m_translator.translate(new StandardEnvironment(), container);
    System.out.println(function.getGraph().getNodes());
    System.out.println(function.getGraph().getEdges());
    assertEquals(3, function.getGraph().getNodes().size());
    assertEquals(2, function.getGraph().getEdges().size());
    final MonoReilSolverResult<RegisterSetLatticeElement> result = RegisterTracker.track(function, Iterables.getFirst(block1.getInstructions(), null), "eax", new RegisterTrackingOptions(true, new HashSet<String>(), true, AnalysisDirection.DOWN));
    System.out.println(result);
}
Also used : MockCodeContainer(com.google.security.zynamics.zylib.disassembly.MockCodeContainer) RegisterTrackingOptions(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterTrackingOptions) RegisterSetLatticeElement(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterSetLatticeElement) MockBlockContainer(com.google.security.zynamics.zylib.disassembly.MockBlockContainer) ReilFunction(com.google.security.zynamics.reil.ReilFunction) StandardEnvironment(com.google.security.zynamics.reil.translators.StandardEnvironment) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with MockCodeContainer

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

the class ReilTranslatorTest method testInlinedFunctionGeneration2.

@Test
public void testInlinedFunctionGeneration2() throws InternalTranslationException {
    final MockBlockContainer container = new MockBlockContainer();
    final MockCodeContainer block1 = new MockCodeContainer();
    block1.m_instructions.add(createPush(0x1000, "eax"));
    block1.m_instructions.add(createMov(0x1001, "edx", "3"));
    block1.m_instructions.add(createCall(0x1002));
    final MockCodeContainer block2 = new MockCodeContainer();
    block2.m_instructions.add(createPush(0x2500, "ebx"));
    final MockCodeContainer block3 = new MockCodeContainer();
    block3.m_instructions.add(createPush(0x1003, "ecx"));
    container.m_blocks.add(block1);
    container.m_blocks.add(block2);
    container.m_blocks.add(block3);
    final MockCodeEdge<MockCodeContainer> edge1 = new MockCodeEdge<MockCodeContainer>(block1, block2, EdgeType.ENTER_INLINED_FUNCTION);
    final MockCodeEdge<MockCodeContainer> edge2 = new MockCodeEdge<MockCodeContainer>(block2, block3, EdgeType.LEAVE_INLINED_FUNCTION);
    block1.m_outgoingEdges.add(edge1);
    container.m_edges.add(edge1);
    container.m_edges.add(edge2);
    final ReilFunction function = m_translator.translate(new StandardEnvironment(), container);
    System.out.println(function.getGraph().getEdges());
    assertEquals(3, function.getGraph().getNodes().size());
    assertEquals(2, function.getGraph().getEdges().size());
    final MonoReilSolverResult<RegisterSetLatticeElement> result = RegisterTracker.track(function, Iterables.get(block1.getInstructions(), 0), "esp", new RegisterTrackingOptions(true, new HashSet<String>(), true, AnalysisDirection.DOWN));
    System.out.println(result);
}
Also used : MockCodeContainer(com.google.security.zynamics.zylib.disassembly.MockCodeContainer) MockCodeEdge(com.google.security.zynamics.zylib.disassembly.MockCodeEdge) RegisterTrackingOptions(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterTrackingOptions) RegisterSetLatticeElement(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterSetLatticeElement) MockBlockContainer(com.google.security.zynamics.zylib.disassembly.MockBlockContainer) ReilFunction(com.google.security.zynamics.reil.ReilFunction) StandardEnvironment(com.google.security.zynamics.reil.translators.StandardEnvironment) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MockCodeContainer (com.google.security.zynamics.zylib.disassembly.MockCodeContainer)4 ReilFunction (com.google.security.zynamics.reil.ReilFunction)3 StandardEnvironment (com.google.security.zynamics.reil.translators.StandardEnvironment)3 Test (org.junit.Test)3 RegisterSetLatticeElement (com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterSetLatticeElement)2 RegisterTrackingOptions (com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterTrackingOptions)2 MockBlockContainer (com.google.security.zynamics.zylib.disassembly.MockBlockContainer)2 MockInstruction (com.google.security.zynamics.zylib.disassembly.MockInstruction)2 MockOperandTree (com.google.security.zynamics.zylib.disassembly.MockOperandTree)2 HashSet (java.util.HashSet)2 ReilGraph (com.google.security.zynamics.reil.ReilGraph)1 ReilTranslator (com.google.security.zynamics.reil.translators.ReilTranslator)1 MockCodeEdge (com.google.security.zynamics.zylib.disassembly.MockCodeEdge)1 MockOperandTreeNode (com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1