Search in sources :

Example 61 with INaviView

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

the class PostgreSQLViewNotificationParser method parseProjectViewNotification.

/**
   * Parser for the bn_project_views notification. The function uses the
   * projectViewNotificationPattern to parse the incoming {@link PGNotification} into a
   * {@link ViewNotificationContainer}
   *
   * @param notification The {@link PGNotification} to parse.
   * @param provider The {@link SQLProvider} to access the database.
   */
private ViewNotificationContainer parseProjectViewNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = projectViewNotificationPattern.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("IE02744: compiled pattern: " + projectViewNotificationPattern.toString() + " did not match notification: " + notification.getParameter());
    }
    final Integer viewId = Integer.parseInt(matcher.group(3));
    final Optional<INaviView> view = Optional.fromNullable(ViewManager.get(provider).getView(viewId));
    final Optional<Integer> projectId = Optional.fromNullable(Integer.parseInt(matcher.group(4)));
    final Optional<INaviProject> project = Optional.fromNullable(provider.findProject(projectId.get()));
    final String databaseOperation = matcher.group(2);
    return new ViewNotificationContainer(viewId, view, projectId, Optional.<INaviModule>absent(), project, databaseOperation);
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) Matcher(java.util.regex.Matcher) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)

Example 62 with INaviView

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

the class PostgreSQLHelpers method getViewsWithAddress.

/**
   * Searches for the views with a given address.
   *
   * @param connection Connection to a SQL database.
   * @param query SQL query to issue for the search.
   * @param columnName Name of the column from which the container ID is read.
   * @param finder Finder object that is used to find the view object from a view ID.
   *
   * @return A list of views that was found by the query.
   *
   * @throws CouldntLoadDataException Thrown if the search failed with an error.
   */
// TODO (timkornau): find out if there is a better way to have the sql query build in here rather
// then in the caller.
// It just seems to be wrong like this.
public static IFilledList<INaviView> getViewsWithAddress(final CConnection connection, final String query, final String columnName, final ContainerFinder finder) throws CouldntLoadDataException {
    Preconditions.checkNotNull(finder, "IE00607: Finder argument can not be null");
    Preconditions.checkNotNull(columnName, "IE00608: Column name argument can not be null");
    Preconditions.checkNotNull(query, "IE00627: Query argument can not be null");
    Preconditions.checkNotNull(connection, "IE00628: Connection argument can not be null");
    final IFilledList<INaviView> views = new FilledList<INaviView>();
    try (ResultSet resultSet = connection.executeQuery(query, true)) {
        while (resultSet.next()) {
            final int containerId = resultSet.getInt(columnName);
            final int viewId = resultSet.getInt("view_id");
            final INaviView view = finder.findView(containerId, viewId);
            views.add(view);
        }
        return views;
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet)

Example 63 with INaviView

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

the class CGraphOpener method showFunction.

/**
   * Opens a function in a new graph window.
   *
   * @param parent The window where the new graph is shown.
   * @param container The container the new graph belongs to.
   * @param function The function to be shown.
   */
public static void showFunction(final CGraphWindow parent, final IViewContainer container, final INaviFunction function) {
    final INaviModule module = function.getModule();
    final INaviView view = module.getContent().getViewContainer().getView(function);
    CViewOpener.showView(parent, container, view, parent);
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule)

Example 64 with INaviView

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

the class CGraphSaver method saveAs.

/**
   * Prompts the user for a new graph description and stores a copy of the graph in the database.
   *
   * @param parent Parent window used to display dialogs.
   * @param graph Graph to be written to the database.
   * @param container View container the graph is written to.
   *
   * @return Information about the save progress.
   */
public static CSaveProgress saveAs(final Window parent, final ZyGraph graph, final IViewContainer container) {
    Preconditions.checkNotNull(parent, "IE01754: Parent argument can not be null");
    Preconditions.checkNotNull(graph, "IE01755: Graph argument can not be null");
    final INaviView view = graph.getRawView();
    final CViewCommentDialog dlg = new CViewCommentDialog(parent, "Save", view.getName(), view.getConfiguration().getDescription());
    dlg.setVisible(true);
    if (dlg.wasCancelled()) {
        return new CSaveProgress(true);
    }
    final String newName = dlg.getName();
    final String newDescription = dlg.getComment();
    final CSaveProgress progress = new CSaveProgress(false);
    new Thread() {

        @Override
        public void run() {
            final CViewSaverOperation operation = new CViewSaverOperation(String.format("Saving view '%s'", newName));
            try {
                if (graph.saveAs(container, newName, newDescription) == null) {
                    throw new CouldntSaveDataException("Failure saving the view.");
                }
            } catch (final CouldntSaveDataException e) {
                CUtilityFunctions.logException(e);
                final String innerMessage = "E00121: " + "Could not save graph";
                final String innerDescription = CUtilityFunctions.createDescription(String.format("The view '%s' could not be saved.", newName), new String[] { "There was a problem with the database connection." }, new String[] { "The new view was not created." });
                NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
            } finally {
                operation.stop();
                progress.setDone();
            }
        }
    }.start();
    return progress;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CViewCommentDialog(com.google.security.zynamics.binnavi.Gui.GraphWindows.CViewCommentDialog) CEndlessHelperThread(com.google.security.zynamics.zylib.gui.ProgressDialogs.CEndlessHelperThread)

Example 65 with INaviView

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

the class CGraphFunctions method showDataflowGraph.

/**
   * Creates a new view that shows the data flow graph of a view.
   * 
   * @param parent Window where the new view is shown.
   * @param container Container where the new view is created.
   * @param view The view whose data flow graph is created.
   */
public static void showDataflowGraph(final CGraphWindow parent, final IViewContainer container, final INaviView view) {
    try {
        final INaviView dataflowView = CDataflowViewCreator.create(container, view);
        CViewOpener.showView(parent, container, dataflowView, parent);
    } catch (final InternalTranslationException e) {
        CUtilityFunctions.logException(e);
        final String innerMessage = "E00110: " + "Could not create dataflow graph";
        final String innerDescription = CUtilityFunctions.createDescription(String.format("BinNavi could not create the data flow graph of view '%s'.", view.getName()), new String[] { "An error occurred in the REIL translator code." }, new String[] { "This is an internal error which you can not fix yourself. " + "Please report the bug to the zynamics support team." });
        NaviErrorDialog.show(parent, innerMessage, innerDescription);
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException)

Aggregations

INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)121 Test (org.junit.Test)54 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)29 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)26 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)18 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)11 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)10 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)10 ArrayList (java.util.ArrayList)10 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)9 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 HashMap (java.util.HashMap)8 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)7 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)7 CProjectContainer (com.google.security.zynamics.binnavi.disassembly.CProjectContainer)7 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)7 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)7 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)6