Search in sources :

Example 91 with INaviFunction

use of com.google.security.zynamics.binnavi.disassembly.INaviFunction 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)

Example 92 with INaviFunction

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

the class PostgreSQLGroupNodeCommentTests method appendInstructionCommentInGroupNode.

@Test
public void appendInstructionCommentInGroupNode() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1004565");
    final INaviView view = module.getContent().getViewContainer().getView(function);
    view.load();
    assertEquals(42, view.getNodeCount());
    final INaviViewNode node1 = view.getContent().getBasicBlocks().get(1);
    final INaviViewNode node2 = view.getContent().getBasicBlocks().get(2);
    view.getContent().createGroupNode(Lists.newArrayList(node1, node2));
    final ZyGraph graph = CGraphBuilder.buildGraph(view);
    final INaviView nonNativeView = graph.saveAs(new CModuleContainer(getDatabase(), module), " TEST INSTRUCTION COMMENTS IN GROUP NODE ", " TESTING GROUP NODE COMMENTS ");
    final INaviInstruction instruction = view.getContent().getBasicBlocks().get(0).getLastInstruction();
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final String firstCommentString = "TEST INSTRUCTION COMMENT PROPAGATION";
    final int firstCommentId = getProvider().appendGlobalInstructionComment(instruction, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, null, firstCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(firstCommentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(1, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(firstComment));
    final INaviInstruction instruction2 = nonNativeView.getBasicBlocks().get(0).getLastInstruction();
    assertEquals(1, instruction2.getGlobalComment().size());
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 93 with INaviFunction

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

the class CPostgreSQLZyGraphTest2 method setUp.

@Before
public void setUp() throws IOException, CouldntLoadDriverException, CouldntConnectException, IllegalStateException, CouldntLoadDataException, InvalidDatabaseException, CouldntInitializeDatabaseException, FileReadException, InvalidExporterDatabaseFormatException, InvalidDatabaseVersionException, CPartialLoadException, LoadCancelledException, MaybeNullException {
    ConfigManager.instance().read();
    final ZyGraphViewSettings settings = ConfigManager.instance().getDefaultFlowGraphSettings();
    settings.getProximitySettings().setProximityBrowsingActivationThreshold(50);
    settings.getProximitySettings().setProximityBrowsingChildren(2);
    settings.getProximitySettings().setProximityBrowsingParents(2);
    ConfigManager.instance().updateFlowgraphSettings(settings);
    final String[] parts = CConfigLoader.loadPostgreSQL();
    m_database = new CDatabase("None", CJdbcDriverNames.jdbcPostgreSQLDriverName, parts[0], "test_disassembly", parts[1], parts[2], parts[3], false, false);
    m_database2 = new CDatabase("None", CJdbcDriverNames.jdbcPostgreSQLDriverName, parts[0], "test_disassembly", parts[1], parts[2], parts[3], false, false);
    m_database.connect();
    m_database.load();
    m_module = m_database.getContent().getModules().get(0);
    m_module.load();
    final INaviFunction function = m_module.getContent().getFunctionContainer().getFunction("sub_1002B87");
    m_view = (IFlowgraphView) m_module.getContent().getViewContainer().getView(function);
    m_view.load();
    m_graph = CGraphBuilder.buildGraph(m_view);
}
Also used : CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 94 with INaviFunction

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

the class CPostgreSQLDatabaseTest method testCalc.

@Test
public void testCalc() throws CouldntLoadDataException, InternalTranslationException, LoadCancelledException {
    final INaviModule calc = m_database.getContent().getModule(2);
    calc.load();
    for (final INaviFunction function : calc.getContent().getFunctionContainer().getFunctions()) {
        function.load();
        m_translator.translate(new StandardEnvironment(), function);
        function.close();
    }
    calc.close();
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) StandardEnvironment(com.google.security.zynamics.reil.translators.StandardEnvironment) Test(org.junit.Test)

Aggregations

INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)94 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)39 Test (org.junit.Test)38 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)26 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)20 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)16 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)16 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)14 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12 ArrayList (java.util.ArrayList)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)9 HashMap (java.util.HashMap)9 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)8 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)8 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)8