use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.
the class CModuleTest method test_C_Constructors.
@Test
public void test_C_Constructors() {
try {
new CModule(0, "Name", "Comment", new Date(), new Date(), md5, sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final IllegalArgumentException exception) {
}
try {
new CModule(1, null, "Comment", new Date(), new Date(), md5, sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", null, new Date(), new Date(), md5, sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", "Comment", null, new Date(), md5, sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), null, md5, sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), null, sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), "123456781234567812345678123456789", sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final IllegalArgumentException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), md5, null, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), md5, "12345678123456781234567812345678123456789", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final IllegalArgumentException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), md5, sha1, -1, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final IllegalArgumentException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), md5, sha1, 0, -1, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final IllegalArgumentException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), md5, sha1, 0, 0, null, new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), md5, sha1, 0, 0, new CAddress(0), null, null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
fail();
} catch (final NullPointerException exception) {
}
try {
new CModule(1, "Name", "Comment", new Date(), new Date(), md5, sha1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, null);
fail();
} catch (final NullPointerException exception) {
}
final MockSqlProvider sql = new MockSqlProvider();
final CModule module = new CModule(123, "Name", "Comment", new Date(), new Date(), md5, sha1, 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, sql), null, Integer.MAX_VALUE, false, sql);
assertEquals(123, module.getConfiguration().getId());
assertEquals("Name", module.getConfiguration().getName());
assertEquals("Comment", module.getConfiguration().getDescription());
assertEquals(md5, module.getConfiguration().getMD5());
assertEquals(sha1, module.getConfiguration().getSha1());
assertEquals(55, module.getFunctionCount());
assertEquals(66, module.getCustomViewCount());
assertEquals("00000555", module.getConfiguration().getFileBase().toHexString());
assertEquals("00000666", module.getConfiguration().getImageBase().toHexString());
assertEquals("Mock Debugger", module.getConfiguration().getDebuggerTemplate().getName());
assertNotNull(module.getConfiguration().getDebugger());
assertTrue(module.inSameDatabase(sql));
}
use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.
the class PostgreSQLAddressSpaceLoader method loadAddressSpaces.
/**
* Loads the address spaces of a project.
*
* The project, the debugger manager, and all modules in the module list must be stored in the
* database connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param project The parent project of the address spaces to load.
* @param debuggerManager Debugger manager of the database.
* @param list A list of all modules that belong to the database.
*
* @return A list that contains the address spaces of the project.
*
* @throws CouldntLoadDataException Thrown if the address spaces could not be loaded.
*/
public static List<CAddressSpace> loadAddressSpaces(final AbstractSQLProvider provider, final INaviProject project, final DebuggerTemplateManager debuggerManager, final List<INaviModule> list) throws CouldntLoadDataException {
checkArguments(provider, project);
Preconditions.checkNotNull(debuggerManager, "IE01543: Debugger provider argument can not be null");
Preconditions.checkNotNull(list, "IE01545: Modules argument can not be null");
NaviLogger.info("Loading address spaces of project %s", project.getConfiguration().getName());
final CConnection connection = provider.getConnection();
final List<CAddressSpace> addressSpaces = new ArrayList<CAddressSpace>();
final String query = "SELECT id, name, description, creation_date, modification_date, debugger_id " + " FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + project.getConfiguration().getId();
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final int addressSpaceId = resultSet.getInt("id");
final Map<INaviModule, IAddress> imageBases = loadImageBases(connection, addressSpaceId, list);
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final DebuggerTemplate debuggerDescription = debuggerManager.findDebugger(resultSet.getInt("debugger_id"));
addressSpaces.add(new CAddressSpace(addressSpaceId, name, description, creationDate, modificationDate, imageBases, debuggerDescription, provider, project));
}
return addressSpaces;
} finally {
resultSet.close();
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
}
use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.
the class PostgresSQLDebuggerFunctions method createDebuggerTemplate.
/**
* Creates a new debugger template in the database.
*
* @param provider SQL provider of the new debugger template.
* @param name Name of the new debugger template. This argument must be non-empty.
* @param host Host of the new debugger template. This argument must be non-empty.
* @param port Port of the new debugger template. This argument must be a valid port number.
*
* @return The new debugger template.
*
* @throws CouldntSaveDataException Thrown if the new debugger template could not be written to
* the database.
*/
public static DebuggerTemplate createDebuggerTemplate(final AbstractSQLProvider provider, final String name, final String host, final int port) throws CouldntSaveDataException {
Preconditions.checkNotNull(name, "IE00417: Debugger names can not be null");
Preconditions.checkArgument(!name.isEmpty(), "IE00418: Debugger names can not be empty");
Preconditions.checkNotNull(host, "IE00419: Debugger host can not be null");
Preconditions.checkArgument(!host.isEmpty(), "IE00418: Debugger host can not be empty");
Preconditions.checkArgument((port > 0) && (port <= 65535), "IE00421: Debugger port is out of bounds");
NaviLogger.info("Creating new debugger %s (%s:%d)", name, host, port);
final CConnection connection = provider.getConnection();
final String query = "INSERT INTO " + CTableNames.DEBUGGERS_TABLE + "(name, host, port) VALUES(?, ?, ?) RETURNING id";
try (PreparedStatement statement = connection.getConnection().prepareStatement(query)) {
statement.setString(1, name);
statement.setString(2, host);
statement.setInt(3, port);
int id = -1;
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
id = resultSet.getInt("id");
}
}
return new DebuggerTemplate(id, name, host, port, provider);
} catch (final SQLException e) {
throw new CouldntSaveDataException(e);
}
}
use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.
the class PostgreSQLDatabaseFunctions method loadProjects.
/**
* Loads the projects of a database.
*
* @param provider The SQL provider that provides the connection.
* @param debuggerManager Debugger manager object that belongs to the given database.
*
* @return A list of projects that contains the projects stored in the database.
*
* @throws CouldntLoadDataException Thrown if the projects could not be loaded from the database.
*/
public static List<INaviProject> loadProjects(final AbstractSQLProvider provider, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
PostgreSQLDatabaseFunctions.checkArguments(provider, debuggerManager);
final CConnection connection = provider.getConnection();
final List<INaviProject> projects = new ArrayList<>();
if (!PostgreSQLHelpers.hasTable(connection, CTableNames.PROJECTS_TABLE)) {
return projects;
}
String query = "SELECT id, name, description, creation_date, modification_date, " + " (SELECT count(*) FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + CTableNames.PROJECTS_TABLE + ".id) " + " AS addressspace_count FROM " + CTableNames.PROJECTS_TABLE;
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int projectId = resultSet.getInt("id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final int addressSpaceCount = resultSet.getInt("addressspace_count");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final List<DebuggerTemplate> debuggers = PostgreSQLDatabaseFunctions.getAssignedDebuggers(connection, projectId, debuggerManager);
projects.add(new CProject(projectId, name, description == null ? "" : description, creationDate, modificationDate, addressSpaceCount, debuggers, provider));
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
return new ArrayList<INaviProject>(projects);
}
use of com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate in project binnavi by google.
the class PostgreSQLDatabaseFunctions method loadModules.
/**
* Loads the modules of a database.
*
* @param provider The SQL provider that provides the connection.
* @param rawModules Previously loaded raw module objects.
* @param debuggerManager Debugger manager object that belongs to the given database.
*
* @return A list of modules that contains the modules stored in the database.
*
* @throws CouldntLoadDataException Thrown if the modules could not be loaded from the database.
*/
public static List<INaviModule> loadModules(final AbstractSQLProvider provider, final List<INaviRawModule> rawModules, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
Preconditions.checkNotNull(rawModules, "IE02043: rawModules argument can not be null");
PostgreSQLDatabaseFunctions.checkArguments(provider, debuggerManager);
final List<CModule> modules = new ArrayList<>();
final CConnection connection = provider.getConnection();
if (!PostgreSQLHelpers.hasTable(connection, CTableNames.MODULES_TABLE)) {
return new ArrayList<INaviModule>(modules);
}
final String query = "SELECT id, raw_module_id, " + CTableNames.MODULES_TABLE + ".name, " + " md5, sha1, description, import_time, modification_date, file_base, image_base, stared, " + " initialization_state, debugger_id, " + " (SELECT count(*) FROM " + CTableNames.FUNCTIONS_TABLE + " " + " WHERE id = " + CTableNames.FUNCTIONS_TABLE + ".module_id) " + " AS function_count, " + " (SELECT count(*) FROM " + CTableNames.MODULE_VIEWS_TABLE + " JOIN " + CTableNames.VIEWS_TABLE + " ON view_id = id " + " WHERE type = 'non-native' and module_id = " + CTableNames.MODULES_TABLE + ".id) " + " AS view_count FROM " + CTableNames.MODULES_TABLE + " " + " WHERE raw_module_id IS NOT NULL ORDER BY id";
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int moduleId = resultSet.getInt("id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String md5 = PostgreSQLHelpers.readString(resultSet, "md5");
final String sha1 = PostgreSQLHelpers.readString(resultSet, "sha1");
final String comment = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp timestamp = resultSet.getTimestamp("import_time");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
int functionCount = resultSet.getInt("function_count");
final int viewCount = resultSet.getInt("view_count");
final IAddress imageBase = PostgreSQLHelpers.loadAddress(resultSet, "image_base");
final IAddress fileBase = PostgreSQLHelpers.loadAddress(resultSet, "file_base");
final int debuggerId = resultSet.getInt("debugger_id");
final boolean isStared = resultSet.getBoolean("stared");
final int initializationState = resultSet.getInt("initialization_state");
final DebuggerTemplate description = debuggerManager.findDebugger(debuggerId);
final int rawModuleId = resultSet.getInt("raw_module_id");
final INaviRawModule rawModule = PostgreSQLDatabaseFunctions.findRawModule(rawModuleId, rawModules);
if ((functionCount == 0) && (rawModule != null)) {
functionCount = rawModule.getFunctionCount();
}
modules.add(new CModule(moduleId, name, comment, timestamp, modificationDate, md5, sha1, functionCount, viewCount, fileBase, imageBase, description, rawModule, initializationState, isStared, provider));
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
return new ArrayList<INaviModule>(modules);
}
Aggregations