Search in sources :

Example 6 with MockFunction

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

the class CUnInlinerTest method testUninlineSingleBlockConnectNeighbors.

@Test
public void testUninlineSingleBlockConnectNeighbors() {
    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 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);
    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(childNode1);
    nodes.add(childNode2);
    final CNaviViewEdge parentEdge = new CNaviViewEdge(0, parentNode, upperNode, EdgeType.JUMP_UNCONDITIONAL, 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, childNode1, EdgeType.JUMP_CONDITIONAL_FALSE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge childEdge2 = new CNaviViewEdge(4, lowerNode, childNode2, EdgeType.JUMP_CONDITIONAL_TRUE, 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);
    edges.add(childEdge2);
    connect(parentNode, upperNode, parentEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(lowerNode, childNode1, childEdge1);
    connect(lowerNode, childNode2, childEdge2);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(4, view.getNodeCount());
    assertEquals(3, view.getEdgeCount());
    assertEquals(EdgeType.JUMP_UNCONDITIONAL, view.getGraph().getEdges().get(0).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_FALSE, view.getGraph().getEdges().get(1).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_TRUE, view.getGraph().getEdges().get(2).getType());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(3);
    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 7 with MockFunction

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

the class CViewInserterTest method test.

@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final INaviModule mockModule = new MockModule();
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(mockProvider);
    final IUser user = userManager.addUser(" VIEW INSERTER USER ");
    userManager.setCurrentActiveUser(user);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view.load();
    final MockFunction mockFunction = new MockFunction(mockProvider);
    final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
    final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
    @SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
    final MockInstruction instruction1 = new MockInstruction();
    final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    @SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
    final CTextNode tnode1 = view.getContent().createTextNode(comments);
    @SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
    final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
    gnode1.appendComment("TEST GROUP NODE COMMENT 1");
    final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view2.load();
    CViewInserter.insertView(view, view2);
    final List<INaviViewNode> nodes = view2.getGraph().getNodes();
    assertEquals(view2.getNodeCount(), 6);
    assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
    assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 8 with MockFunction

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

the class ZyGraphTest method testAddedFunctionNode.

@Test
public void testAddedFunctionNode() {
    assertEquals(7, m_graph.visibleNodeCount());
    assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
    assertEquals(96, m_graph.getRawView().getNodeCount());
    final CFunctionNode functionNode = m_graph.getRawView().getContent().createFunctionNode(new MockFunction(m_provider));
    assertEquals(8, m_graph.visibleNodeCount());
    assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
    assertEquals(97, m_graph.getRawView().getNodeCount());
    final List<NaviNode> nodes = GraphHelpers.getNodes(m_graph);
    final NaviNode cnn = searchNode(nodes, functionNode);
    assertTrue(functionNode.isVisible());
    assertEquals(functionNode.isVisible(), cnn.isVisible());
    functionNode.setVisible(false);
    assertFalse(functionNode.isVisible());
    assertEquals(functionNode.isVisible(), cnn.isVisible());
    functionNode.setVisible(true);
    assertTrue(functionNode.isVisible());
    assertEquals(functionNode.isVisible(), cnn.isVisible());
    assertFalse(functionNode.isSelected());
    assertEquals(functionNode.isSelected(), cnn.isSelected());
    functionNode.setSelected(false);
    assertFalse(functionNode.isSelected());
    assertEquals(functionNode.isSelected(), cnn.isSelected());
    functionNode.setSelected(true);
    assertTrue(functionNode.isSelected());
    assertEquals(functionNode.isSelected(), cnn.isSelected());
    assertEquals(functionNode.getColor(), cnn.getRealizer().getFillColor());
    functionNode.setColor(Color.GREEN);
    assertEquals(Color.GREEN, functionNode.getColor());
    assertEquals(functionNode.getColor(), cnn.getRealizer().getFillColor());
    functionNode.setX(100);
    assertEquals(100, functionNode.getX(), 0.1);
    assertEquals(functionNode.getX(), cnn.getX(), 0.1);
    functionNode.setY(200);
    assertEquals(200, functionNode.getY(), 0.1);
    assertEquals(functionNode.getY(), cnn.getY(), 0.1);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) Test(org.junit.Test)

Example 9 with MockFunction

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

the class CCrossReferenceTest method test1Simple.

@Test
public void test1Simple() {
    final CCrossReference reference = new CCrossReference(new MockFunction(), new MockFunction());
    final CCrossReference reference2 = new CCrossReference(new MockFunction(), new MockFunction());
    assertFalse(reference.equals(reference2));
    assertTrue(reference.equals(reference));
}
Also used : CCrossReference(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.CrossReferences.CCrossReference) MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) Test(org.junit.Test)

Example 10 with MockFunction

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

the class CCrossReferencesModelTest method test4getRowCount.

@Test
public void test4getRowCount() {
    final CCrossReferencesModel model = new CCrossReferencesModel();
    final CCrossReference reference = new CCrossReference(new MockFunction(), new MockFunction());
    final List<CCrossReference> crossReferences = new ArrayList<CCrossReference>();
    crossReferences.add(reference);
    model.setCrossReferences(crossReferences);
    assertEquals(1, model.getRowCount());
}
Also used : CCrossReference(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.CrossReferences.CCrossReference) MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) ArrayList(java.util.ArrayList) CCrossReferencesModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.CrossReferences.CCrossReferencesModel) Test(org.junit.Test)

Aggregations

MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)25 Test (org.junit.Test)23 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)12 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)8 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)8 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 CCrossReference (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.CrossReferences.CCrossReference)7 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)7 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)6 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)6 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)6 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)6 MockCodeNodeData (com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeData)5 MockCodeNodeProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeProvider)5 CCodeNodeParser (com.google.security.zynamics.binnavi.Database.NodeParser.CCodeNodeParser)5 CCrossReferencesModel (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.CrossReferences.CCrossReferencesModel)5 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)5 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)5 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)5 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)4