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;
}
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);
}
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);
}
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());
}
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);
}
Aggregations