Search in sources :

Example 11 with CModuleContainer

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

the class PluginInterface method showInLastWindow.

/**
   * Shows a view in the last window.
   *
   * @param view The view to show.
   *
   * @return The view2d object that is shown.
   */
public View2D showInLastWindow(final View view) {
    Preconditions.checkNotNull(view, "Error: View argument can not be null");
    final ViewContainer container = view.getContainer();
    if (container instanceof Module) {
        final Module module = (Module) container;
        return show(CWindowManager.instance().getLastWindow(), view, new CModuleContainer(container.getDatabase().getNative(), module.getNative()));
    } else {
        final Project project = (Project) container;
        return show(CWindowManager.instance().getLastWindow(), view, new CProjectContainer(container.getDatabase().getNative(), project.getNative()));
    }
}
Also used : Project(com.google.security.zynamics.binnavi.API.disassembly.Project) CProjectContainer(com.google.security.zynamics.binnavi.disassembly.CProjectContainer) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) IViewContainer(com.google.security.zynamics.binnavi.disassembly.views.IViewContainer) ViewContainer(com.google.security.zynamics.binnavi.API.disassembly.ViewContainer)

Example 12 with CModuleContainer

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

the class CViewOpener method showForwardedFunction.

/**
   * Shows a forwarded function in a graph window.
   * 
   * @param parent Parent window that is used as the parent of all dialogs.
   * @param container View container that provides the context in which a view is opened.
   * @param view The view to show.
   * @param function The imported function to show.
   * @param window Graph window where the graph is shown. If this value is null, the graph is shown
   *        in a new window.
   */
private static void showForwardedFunction(final Window parent, final IViewContainer container, final INaviView view, final INaviFunction function, final CGraphWindow window) {
    if (container instanceof CModuleContainer) {
        CMessageBox.showInformation(parent, "Please open forwarded views from inside a project.");
        return;
    }
    final IDatabase database = container.getDatabase();
    final int moduleId = function.getForwardedFunctionModuleId();
    final INaviModule forwardedModule = database.getContent().getModule(moduleId);
    if (forwardedModule == null) {
        final String message = "E00019: " + "Forwarded view can not be loaded (Unknown module)";
        final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the module of " + "the forwarding target is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the " + "forwarding target again. Restart BinNavi if the view " + "can still not be opened. Contact the BinNavi support if necessary." });
        NaviErrorDialog.show(parent, message, description);
    } else if (forwardedModule.isLoaded()) {
        final IAddress address = function.getForwardedFunctionAddress();
        final INaviFunction forwardedFunction = forwardedModule.getContent().getFunctionContainer().getFunction(address);
        if (forwardedFunction == null) {
            final String message = "E00020: " + "Forwarded view can not be loaded (Unknown function)";
            final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the target function is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the forwarding target " + "again. Restart BinNavi if the view can still not be opened. Contact the " + "BinNavi support if necessary." });
            NaviErrorDialog.show(parent, message, description);
        } else {
            final INaviView forwardedView = forwardedModule.getContent().getViewContainer().getView(forwardedFunction);
            if (forwardedView == null) {
                final String message = "E00107: " + "Forwarded view can not be loaded (Unknown view)";
                final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the target view is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the forwarding target " + "again. Restart BinNavi if the view can still not be opened. Contact the " + "BinNavi support if necessary." });
                NaviErrorDialog.show(parent, message, description);
            } else {
                CGraphOpener.showGraph(container, forwardedView, window, parent);
            }
        }
    } else {
        if (CMessageBox.showYesNoQuestion(parent, "The view can not be opened because it is forwarded to an unloaded module.\n\n" + "Do you want to load the forwarded module now?") == JOptionPane.YES_OPTION) {
            CModuleLoader.loadModule(parent, forwardedModule);
            if (forwardedModule.isLoaded()) {
                // Just call this function recursively now that the module is loaded.
                showForwardedFunction(parent, container, view, function, window);
            }
        }
    }
}
Also used : IDatabase(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabase) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 13 with CModuleContainer

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

the class CViewLoader method load.

/**
   * Loads a view.
   *
   * @throws LoadCancelledException Thrown if the user canceled the load operation.
   * @throws CPartialLoadException Thrown if not all required modules are loaded.
   * @throws CouldntLoadDataException Thrown if the view data could not be loaded from the database.
   */
public void load() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException {
    if (!view.isLoaded()) {
        view.load();
    }
    // Convert the data from the raw view into a graph that can be displayed.
    final ZyGraph graph = container instanceof CModuleContainer ? CGraphBuilder.buildDnDGraph(view, container.getModules().get(0).getTypeManager()) : CGraphBuilder.buildGraph(view);
    CRegisterHotKeys.register(graph);
    if (window == null) {
        // If the parent window of the graph is null, a new graph window is created.
        final CGraphWindow navi = new CGraphWindow();
        final CGraphModel model = new CGraphModel(navi, container.getDatabase(), container, graph);
        CNodeUpdaterInitializer.addUpdaters(model);
        final CGraphPanel panel = new CGraphPanel(model);
        navi.addGraph(panel);
        CWindowManager.instance().register(navi);
        // Part of the workaround you can find in WorkaroundListener in CGraphWindow
        navi.setSize(Toolkit.getDefaultToolkit().getScreenSize());
        navi.setVisible(true);
        GuiHelper.applyWindowFix(navi);
        navi.setExtendedState(Frame.MAXIMIZED_BOTH);
        workArounds(panel);
        graphModel = model;
    } else {
        final CGraphModel model = new CGraphModel(window, container.getDatabase(), container, graph);
        CNodeUpdaterInitializer.addUpdaters(model);
        final CGraphPanel panel = new CGraphPanel(model);
        // If a parent window is given, the graph is added to this window.
        window.addGraph(panel);
        workArounds(panel);
        window.toFront();
        graphModel = model;
    }
}
Also used : CGraphWindow(com.google.security.zynamics.binnavi.Gui.GraphWindows.CGraphWindow) CGraphPanel(com.google.security.zynamics.binnavi.Gui.GraphWindows.CGraphPanel) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.CGraphModel) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer)

Example 14 with CModuleContainer

use of com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer 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 15 with CModuleContainer

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

the class CModuleNodeTest method testUnloadedClosed.

@Test
public void testUnloadedClosed() throws CouldntLoadDataException, CouldntDeleteException, LoadCancelledException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final CModuleNode node = new CModuleNode(m_tree, new DefaultMutableTreeNode(), m_database, m_module, new CModuleContainer(m_database, m_module));
    assertEquals("Name (55/66)", node.toString());
    m_module.load();
    assertEquals("Name (1/0)", node.toString());
    final CView view = m_module.getContent().getViewContainer().createView("Foo", "Bar");
    assertEquals("Name (1/1)", node.toString());
    m_module.getContent().getViewContainer().deleteView(view);
    assertEquals("Name (1/0)", node.toString());
    m_module.close();
    node.dispose();
    assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")) == null);
    assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_module, "m_listeners"), "m_listeners")).isEmpty());
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) CModuleNode(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Module.CModuleNode) Test(org.junit.Test)

Aggregations

CModuleContainer (com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer)16 Test (org.junit.Test)7 CModuleNode (com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Module.CModuleNode)5 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)5 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)5 ZyGraph (com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)4 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)3 Project (com.google.security.zynamics.binnavi.API.disassembly.Project)3 ViewContainer (com.google.security.zynamics.binnavi.API.disassembly.ViewContainer)3 CProjectContainer (com.google.security.zynamics.binnavi.disassembly.CProjectContainer)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)3 IViewContainer (com.google.security.zynamics.binnavi.disassembly.views.IViewContainer)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)2 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)2 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)2 Date (java.util.Date)2