Search in sources :

Example 51 with DebuggerTemplate

use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.

the class PostgreSQLProjectCreator method loadProject.

/**
   * Loads a project from the database.
   * 
   * @param provider The connection to the database.
   * @param projectId The ID of the project to load.
   * 
   * @return The loaded project.
   * 
   * @throws SQLException Thrown if the project could not be loaded.
   */
protected static CProject loadProject(final AbstractSQLProvider provider, final int projectId) throws SQLException {
    final String query = "select id, name, description, creation_date, modification_date from " + CTableNames.PROJECTS_TABLE + " where id = " + projectId;
    try (ResultSet resultSet = provider.getConnection().executeQuery(query, true)) {
        while (resultSet.next()) {
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final String description = PostgreSQLHelpers.readString(resultSet, "description");
            final int addressSpaceCount = 0;
            final Timestamp creationDate = resultSet.getTimestamp("creation_date");
            final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
            return new CProject(projectId, name, description, creationDate, modificationDate, addressSpaceCount, new ArrayList<DebuggerTemplate>(), provider);
        }
    }
    return null;
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) ResultSet(java.sql.ResultSet) Timestamp(java.sql.Timestamp)

Example 52 with DebuggerTemplate

use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.

the class PostgreSQLDatabaseFunctions method getAssignedDebuggers.

/**
   * Determines the debuggers that are assigned to a project.
   * 
   * @param connection Connection to the SQL database where the information is stored.
   * @param projectId ID of the project in question.
   * @param debuggerManager Debugger manager object that belongs to the given database.
   * @return A list that contains the debugger templates assigned to the given project.
   * @throws CouldntLoadDataException Thrown if the debugger templates could not be loaded.
   */
protected static List<DebuggerTemplate> getAssignedDebuggers(final CConnection connection, final int projectId, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
    Preconditions.checkNotNull(connection, "IE02264: Connection argument can not be null");
    Preconditions.checkArgument(projectId > 0, "Project id %s must be a positive integer.", projectId);
    Preconditions.checkNotNull(debuggerManager, "IE02265: debugger manager argument can not be null");
    final List<DebuggerTemplate> debuggerIds = new ArrayList<>();
    final String query = String.format("SELECT debugger_id FROM %s WHERE project_id = %d", CTableNames.PROJECT_DEBUGGERS_TABLE, projectId);
    try (ResultSet resultSet = connection.executeQuery(query, true)) {
        while (resultSet.next()) {
            debuggerIds.add(debuggerManager.findDebugger(resultSet.getInt("debugger_id")));
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return debuggerIds;
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 53 with DebuggerTemplate

use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.

the class CDebuggerComboModel method updateElements.

/**
   * Updates the elements of the combobox after relevant changes to the debugger container.
   */
private void updateElements() {
    comboboxElements.clear();
    comboboxElements.add(new CDebuggerTemplateWrapper(null));
    for (final DebuggerTemplate template : debuggerContainer.getDebuggers()) {
        comboboxElements.add(new CDebuggerTemplateWrapper(template));
    }
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)

Example 54 with DebuggerTemplate

use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.

the class CProjectNodeComponent method saveDebuggers.

/**
   * Saves the configured project debuggers to the database.
   */
private void saveDebuggers() {
    try {
        final ListModel<DebuggerTemplate> model = m_checkedList.getModel();
        final List<DebuggerTemplate> oldDebuggers = m_project.getConfiguration().getDebuggers();
        for (int i = 0; i < model.getSize(); ++i) {
            final DebuggerTemplate debugger = model.getElementAt(i);
            if (m_checkedList.isChecked(i) && !oldDebuggers.contains(debugger)) {
                m_project.getConfiguration().addDebugger(debugger);
            } else if (!m_checkedList.isChecked(i) && oldDebuggers.contains(debugger)) {
                m_project.getConfiguration().removeDebugger(model.getElementAt(i));
            }
        }
    } catch (final CouldntSaveDataException e) {
        CUtilityFunctions.logException(e);
        final String innerMessage = "E00173: " + "Could not save project debuggers";
        final String innerDescription = CUtilityFunctions.createDescription(String.format("The new debuggers of the project '%s' could not be saved.", m_project.getConfiguration().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The project keeps its old debuggers." });
        NaviErrorDialog.show(SwingUtilities.getWindowAncestor(CProjectNodeComponent.this), innerMessage, innerDescription, e);
    }
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 55 with DebuggerTemplate

use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.

the class CProjectNodeComponent method updateCheckedListPanel.

/**
   * Because the checked list box can not yet deal with growing or shrinking models, the checked
   * list box is recreated by this function if necessary.
   */
private void updateCheckedListPanel() {
    m_checkedList.removeListSelectionListener(m_updateListener);
    m_checkedListPanel.removeAll();
    m_checkedList = new JCheckedListbox<>(getDebuggerVector(), false);
    m_checkedList.addListSelectionListener(m_updateListener);
    final JScrollPane debuggerScrollPane = new JScrollPane(m_checkedList);
    m_checkedListPanel.add(debuggerScrollPane);
    final Collection<DebuggerTemplate> debuggers = m_project.getConfiguration().getDebuggers();
    final ListModel<DebuggerTemplate> model = m_checkedList.getModel();
    for (int i = 0; i < model.getSize(); ++i) {
        final DebuggerTemplate debuggerId = model.getElementAt(i);
        m_checkedList.setChecked(i, debuggers.contains(debuggerId));
    }
    m_checkedList.updateUI();
    updateUI();
}
Also used : JScrollPane(javax.swing.JScrollPane) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)

Aggregations

DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)55 Test (org.junit.Test)29 Date (java.util.Date)20 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)16 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)16 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)12 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)11 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)11 CProject (com.google.security.zynamics.binnavi.disassembly.CProject)8 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 ResultSet (java.sql.ResultSet)7 SQLException (java.sql.SQLException)6 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)5 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)5 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)5 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)5 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)4 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)4 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)4