Search in sources :

Example 1 with CRawModule

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

the class PostgreSQLDatabaseFunctions method loadRawModules.

/**
   * Loads the raw modules of a database.
   * 
   * @param provider The SQL provider that provides the connection.
   * 
   * @return A list of raw modules that contains the raw modules stored in the database.
   * 
   * @throws CouldntLoadDataException Thrown if the raw modules could not be loaded from the
   *         database.
   */
public static final List<INaviRawModule> loadRawModules(final AbstractSQLProvider provider) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE00416: Provider argument can not be null");
    final CConnection connection = provider.getConnection();
    final List<INaviRawModule> modules = new ArrayList<INaviRawModule>();
    if (!PostgreSQLHelpers.hasTable(connection, CTableNames.RAW_MODULES_TABLE)) {
        return modules;
    }
    final String query = "SELECT id, name FROM " + CTableNames.RAW_MODULES_TABLE + " ORDER BY id";
    try (ResultSet resultSet = connection.executeQuery(query, true)) {
        while (resultSet.next()) {
            final int rawModuleId = resultSet.getInt("id");
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final boolean isComplete = PostgreSQLDatabaseFunctions.checkRawModulesTables(provider.getConnection(), PostgreSQLHelpers.getDatabaseName(provider.getConnection()), rawModuleId);
            final int functionCount = isComplete ? PostgreSQLDatabaseFunctions.getRawModuleFunctionCount(connection, rawModuleId) : 0;
            final CRawModule module = new CRawModule(rawModuleId, name, functionCount, isComplete, provider);
            modules.add(module);
        }
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
    return modules;
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) INaviRawModule(com.google.security.zynamics.binnavi.disassembly.INaviRawModule) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) CRawModule(com.google.security.zynamics.binnavi.disassembly.CRawModule)

Example 2 with CRawModule

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

the class CModuleNodeTest method setUp.

@Before
public void setUp() throws IllegalArgumentException, SecurityException, FileReadException {
    ConfigManager.instance().read();
    m_database = new MockDatabase(m_provider);
    final CRawModule rawModule = new CRawModule(1, "", 0, false, m_provider);
    m_module = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, m_provider), rawModule, Integer.MAX_VALUE, false, m_provider);
    final CProjectTreeModel model = new CProjectTreeModel(m_tree);
    model.setRoot(new DefaultMutableTreeNode());
    m_tree.setModel(model);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CProjectTreeModel(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.CProjectTreeModel) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CRawModule(com.google.security.zynamics.binnavi.disassembly.CRawModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Before(org.junit.Before)

Example 3 with CRawModule

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

the class CModuleContainerNodeTest method testUnloaded.

@Test
public void testUnloaded() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final CRawModule rawModule = new CRawModule(1, "", 0, false, m_provider);
    final CModule module1 = new CModule(123, "Module 1", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, m_provider), rawModule, Integer.MAX_VALUE, false, m_provider);
    final CModule module2 = new CModule(123, "Module 2", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, m_provider), rawModule, Integer.MAX_VALUE, false, m_provider);
    final CModuleContainerNode node = new CModuleContainerNode(m_tree, m_database);
    assertEquals("Modules (0)", node.toString());
    assertEquals(0, node.getChildCount());
    m_database.getContent().addModule(module1);
    m_database.getContent().addModule(module2);
    assertEquals("Modules (2)", node.toString());
    assertEquals(2, node.getChildCount());
    assertEquals("Module 1 (55/66)", node.getChildAt(0).toString());
    assertEquals("Module 2 (55/66)", node.getChildAt(1).toString());
    m_database.getContent().delete(module1);
    assertEquals("Modules (1)", node.toString());
    assertEquals(1, node.getChildCount());
    assertEquals("Module 2 (55/66)", node.getChildAt(0).toString());
    node.dispose();
    assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")).isEmpty());
    assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database.getContent().getDebuggerTemplateManager(), "listeners"), "m_listeners")) == null);
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CRawModule(com.google.security.zynamics.binnavi.disassembly.CRawModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 4 with CRawModule

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

the class CRawModuleTest method testCRawModule_1.

@Test
public void testCRawModule_1() {
    final MockSqlProvider sqlProvider = new MockSqlProvider();
    final MockDatabase mockDatabase = new MockDatabase(sqlProvider);
    try {
        @SuppressWarnings("unused") final CRawModule rawModule = new CRawModule(0, null, 0, false, null);
        fail();
    } catch (final IllegalArgumentException e) {
    }
    try {
        @SuppressWarnings("unused") final CRawModule rawModule = new CRawModule(23, null, 0, false, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CRawModule rawModule = new CRawModule(23, "rawModule", 0, false, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CRawModule rawModule = new CRawModule(23, "rawModule", 1, false, null);
        fail();
    } catch (final NullPointerException e) {
    }
    final CRawModule rawModule = new CRawModule(23, "rawModule", 1, false, sqlProvider);
    @SuppressWarnings("unused") final IRawModuleListener listener;
    assertEquals(1, rawModule.getFunctionCount());
    assertEquals(23, rawModule.getId());
    assertEquals("rawModule", rawModule.getName());
    assertTrue(rawModule.inSameDatabase(sqlProvider));
    assertTrue(rawModule.inSameDatabase(mockDatabase));
    assertFalse(rawModule.isComplete());
}
Also used : MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) IRawModuleListener(com.google.security.zynamics.binnavi.disassembly.IRawModuleListener) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CRawModule(com.google.security.zynamics.binnavi.disassembly.CRawModule) Test(org.junit.Test)

Example 5 with CRawModule

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

the class CModuleContainerNodeTest method testLoaded.

@Test
public void testLoaded() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final CRawModule rawModule = new CRawModule(1, "", 0, false, m_provider);
    final CModule module1 = new CModule(123, "Module 1", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, m_provider), rawModule, Integer.MAX_VALUE, false, m_provider);
    final CModule module2 = new CModule(123, "Module 2", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, m_provider), rawModule, Integer.MAX_VALUE, false, m_provider);
    m_database.getContent().addModule(module1);
    m_database.getContent().addModule(module2);
    final CModuleContainerNode node = new CModuleContainerNode(m_tree, m_database);
    assertEquals("Modules (2)", node.toString());
    assertEquals(2, node.getChildCount());
    assertEquals("Module 1 (55/66)", node.getChildAt(0).toString());
    assertEquals("Module 2 (55/66)", node.getChildAt(1).toString());
    node.dispose();
    assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")).isEmpty());
    assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database.getContent().getDebuggerTemplateManager(), "listeners"), "m_listeners")) == null);
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CRawModule(com.google.security.zynamics.binnavi.disassembly.CRawModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

CRawModule (com.google.security.zynamics.binnavi.disassembly.CRawModule)5 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)3 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)3 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)3 Date (java.util.Date)3 Test (org.junit.Test)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)1 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 CProjectTreeModel (com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.CProjectTreeModel)1 INaviRawModule (com.google.security.zynamics.binnavi.disassembly.INaviRawModule)1 IRawModuleListener (com.google.security.zynamics.binnavi.disassembly.IRawModuleListener)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 Before (org.junit.Before)1