Search in sources :

Example 11 with MockInstruction

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

the class ViewTest method testGraph.

@Test
public void testGraph() {
    final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
    final List<INaviEdge> edges = new ArrayList<INaviEdge>();
    final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
    final int viewId = new BigInteger(31, new SecureRandom()).intValue();
    final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
    final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
    final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
    final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
    @SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
    @SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
    internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final MockViewListener listener = new MockViewListener();
    final View view = new View(module, internalView, tagManager, m_viewTagManager);
    view.addListener(listener);
    assertEquals(4, view.getGraph().getNodes().size());
    assertEquals(1, view.getGraph().getEdges().size());
    internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
    assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
Also used : ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) SecureRandom(java.security.SecureRandom) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) Test(org.junit.Test)

Example 12 with MockInstruction

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

the class ViewTest method testCreateNode.

@Test
public void testCreateNode() throws PartialLoadException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException {
    final MockViewListener listener = new MockViewListener();
    final Function function = module.getFunctions().get(0);
    final List<Instruction> instructions = Lists.newArrayList(new Instruction(new MockInstruction()));
    m_view.load();
    final CodeNode codeNode = m_view.createCodeNode(function, instructions);
    final FunctionNode functionNode = m_view.createFunctionNode(function);
    final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " COMMENT VIEW TEST "));
    final TextNode textNode = m_view.createTextNode(comment);
    assertEquals(3, m_view.getNodeCount());
    m_view.addListener(listener);
    @SuppressWarnings("unused") final CodeNode clonedCodeNode = (CodeNode) m_view.createNode(codeNode);
    @SuppressWarnings("unused") final FunctionNode clonedFunctionNode = (FunctionNode) m_view.createNode(functionNode);
    @SuppressWarnings("unused") final TextNode clonedTextNode = (TextNode) m_view.createNode(textNode);
    m_view.removeListener(listener);
}
Also used : INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) Test(org.junit.Test)

Example 13 with MockInstruction

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

the class CodeNodeTest method testAddInstruction.

@Test
public void testAddInstruction() {
    final MockCodeNodeListener listener = new MockCodeNodeListener();
    m_node.addListener(listener);
    final Instruction instruction = new Instruction(new MockInstruction());
    final Instruction clonedInstruction = m_node.addInstruction(instruction);
    m_node.setInstructionColor(instruction, 10000, Color.RED);
    assertEquals("addedInstruction;", listener.events);
    m_node.removeInstruction(clonedInstruction);
    try {
        m_node.setInstructionColor(clonedInstruction, 10000, Color.RED);
        fail();
    } catch (final IllegalArgumentException e) {
    }
    assertEquals("addedInstruction;removedInstruction;", listener.events);
    m_node.removeListener(listener);
}
Also used : MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) Test(org.junit.Test)

Example 14 with MockInstruction

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

the class CUnInlinerTest method testUninlineSingleBlockNested.

@Test
public void testUninlineSingleBlockNested() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction(m_provider);
    final INaviFunction mockFunction2 = new MockFunction(m_provider);
    final MockInstruction mi1 = new MockInstruction(0x123);
    final MockInstruction mi2 = new MockInstruction(0x124);
    final MockInstruction mi3 = new MockInstruction(0x125);
    final CCodeNode parentNode = new CCodeNode(1, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode upperNode = new CCodeNode(2, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(3, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(4, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode = new CCodeNode(5, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    upperNode.addInstruction(mi1, null);
    inlinedNode.addInstruction(mi2, null);
    lowerNode.addInstruction(mi3, null);
    nodes.add(parentNode);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(lowerNode);
    nodes.add(childNode);
    final CNaviViewEdge parentEdge = new CNaviViewEdge(0, parentNode, upperNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge enteringEdge = new CNaviViewEdge(1, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge leavingEdge = new CNaviViewEdge(2, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge childEdge1 = new CNaviViewEdge(3, lowerNode, childNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(parentEdge);
    edges.add(enteringEdge);
    edges.add(leavingEdge);
    edges.add(childEdge1);
    connect(parentNode, upperNode, parentEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(lowerNode, childNode, childEdge1);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(3, view.getNodeCount());
    assertEquals(2, view.getEdgeCount());
    assertEquals(EdgeType.ENTER_INLINED_FUNCTION, view.getGraph().getEdges().get(0).getType());
    assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, view.getGraph().getEdges().get(1).getType());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(2);
    assertEquals(2, Iterables.size(cnode.getInstructions()));
    assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
    assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Example 15 with MockInstruction

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

the class CUnInlinerTest method testUninlineSingleBlockLoop.

@Test
public void testUninlineSingleBlockLoop() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction(m_provider);
    final INaviFunction mockFunction2 = new MockFunction(m_provider);
    final MockInstruction mi1 = new MockInstruction(0x111);
    final MockInstruction mi2 = new MockInstruction(0x222);
    final MockInstruction mi3 = new MockInstruction(0x333);
    final MockInstruction mi4 = new MockInstruction(0x444);
    final MockInstruction mi5 = new MockInstruction(0x555);
    final MockInstruction mi6 = new MockInstruction(0x666);
    final CCodeNode parentNode = new CCodeNode(1, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode upperNode = new CCodeNode(2, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(3, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(4, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode1 = new CCodeNode(5, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode2 = new CCodeNode(6, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    parentNode.addInstruction(mi1, null);
    upperNode.addInstruction(mi2, null);
    inlinedNode.addInstruction(mi3, null);
    lowerNode.addInstruction(mi4, null);
    childNode1.addInstruction(mi5, null);
    childNode2.addInstruction(mi6, null);
    nodes.add(parentNode);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(lowerNode);
    nodes.add(childNode1);
    nodes.add(childNode2);
    final CNaviViewEdge parentUpperEdge = new CNaviViewEdge(1, parentNode, upperNode, EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge upperInlinedEdge = new CNaviViewEdge(2, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge inlingedLowerEdge = new CNaviViewEdge(3, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge lowerChild1Edge = new CNaviViewEdge(4, lowerNode, childNode1, EdgeType.JUMP_CONDITIONAL_TRUE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge lowerChild2Edge = new CNaviViewEdge(5, lowerNode, childNode2, EdgeType.JUMP_CONDITIONAL_FALSE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge child1UpperEdge = new CNaviViewEdge(6, childNode1, upperNode, EdgeType.JUMP_UNCONDITIONAL_LOOP, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(parentUpperEdge);
    edges.add(upperInlinedEdge);
    edges.add(inlingedLowerEdge);
    edges.add(lowerChild1Edge);
    edges.add(lowerChild2Edge);
    edges.add(child1UpperEdge);
    connect(parentNode, upperNode, parentUpperEdge);
    connect(upperNode, inlinedNode, upperInlinedEdge);
    connect(inlinedNode, lowerNode, inlingedLowerEdge);
    connect(lowerNode, childNode1, lowerChild1Edge);
    connect(lowerNode, childNode2, lowerChild2Edge);
    connect(childNode1, upperNode, child1UpperEdge);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(4, view.getNodeCount());
    assertEquals(4, view.getEdgeCount());
    assertEquals(EdgeType.JUMP_UNCONDITIONAL, view.getGraph().getEdges().get(0).getType());
    assertEquals(EdgeType.JUMP_UNCONDITIONAL_LOOP, view.getGraph().getEdges().get(1).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_TRUE, view.getGraph().getEdges().get(2).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_FALSE, view.getGraph().getEdges().get(3).getType());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(3);
    assertEquals(2, Iterables.size(cnode.getInstructions()));
    assertEquals(mi2.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
    assertEquals(mi4.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Aggregations

MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)16 Test (org.junit.Test)15 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)11 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)8 Date (java.util.Date)8 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)7 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)7 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)7 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)6 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)6 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)6 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)6 ArrayList (java.util.ArrayList)6 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)5 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)5 CBasicBlock (com.google.security.zynamics.binnavi.disassembly.CBasicBlock)4 CBlockNode (com.google.security.zynamics.binnavi.disassembly.CBlockNode)4