use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class PostgreSQLTypeFunctions method loadRawTypeInstanceReferences.
public static List<RawTypeInstanceReference> loadRawTypeInstanceReferences(final Connection connection, final INaviModule module) throws CouldntLoadDataException {
final ArrayList<RawTypeInstanceReference> rawReferences = Lists.newArrayList();
final String query = " SELECT * FROM load_expression_type_instances(?) ";
try {
final PreparedStatement statement = connection.prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
try {
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final int moduleId = resultSet.getInt("module_id");
final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
final int position = resultSet.getInt("position");
final int expressionId = resultSet.getInt("expression_id");
final int typeInstanceId = resultSet.getInt("type_instance_id");
rawReferences.add(new RawTypeInstanceReference(moduleId, viewId, address, position, expressionId, typeInstanceId));
}
} finally {
statement.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return rawReferences;
}
use of com.google.security.zynamics.zylib.disassembly.IAddress 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);
}
use of com.google.security.zynamics.zylib.disassembly.IAddress 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.zylib.disassembly.IAddress in project binnavi by google.
the class PostgreSQLAddressSpaceLoader method loadImageBases.
/**
* Loads the image bases of the given modules within the given address space.
*
* The address space ID and the modules in the module list must all reference items that are
* stored in the database connected to by connection argument.
*
* @param connection Connection to the database.
* @param addressSpaceId ID of the address space.
* @param list Modules whose image bases are loaded.
*
* @return A mapping of modules -> image bases for all modules in the address space.
*
* @throws CouldntLoadDataException Thrown if the image bases could not be loaded.
*/
private static Map<INaviModule, IAddress> loadImageBases(final CConnection connection, final int addressSpaceId, final List<INaviModule> list) throws CouldntLoadDataException {
final HashMap<INaviModule, IAddress> imageBases = new HashMap<INaviModule, IAddress>();
final String query = "SELECT module_id, image_base FROM " + CTableNames.SPACE_MODULES_TABLE + " WHERE address_space_id = " + addressSpaceId;
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
try {
final INaviModule module = findModule(list, resultSet.getInt("module_id"));
imageBases.put(module, PostgreSQLHelpers.loadAddress(resultSet, "image_base"));
} catch (final MaybeNullException exception) {
// I can not think of a scenario where this can happen.
CUtilityFunctions.logException(exception);
}
}
} finally {
resultSet.close();
}
return imageBases;
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class PostgreSQLFunctionFunctions method setDescription.
/**
* Changes the description of a function.
*
* The function must be stored in the database connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param function The function whose description is changed.
* @param description The new description of the function.
*
* @throws CouldntSaveDataException Thrown if the new description could not be saved to the
* database.
*/
public static void setDescription(final AbstractSQLProvider provider, final INaviFunction function, final String description) throws CouldntSaveDataException {
Preconditions.checkNotNull(provider, "IE00448: Provider argument can not be null");
Preconditions.checkNotNull(function, "IE00449: Function argument can not be null");
Preconditions.checkNotNull(description, "IE00450: Comment argument can not be null");
Preconditions.checkArgument(function.inSameDatabase(provider), "IE00451: Function is not part of this database");
final CConnection connection = provider.getConnection();
final int module = function.getModule().getConfiguration().getId();
final IAddress address = function.getAddress();
final String query = "UPDATE " + CTableNames.FUNCTIONS_TABLE + " SET description = ? WHERE module_id = ? AND address = ?";
try (PreparedStatement statement = connection.getConnection().prepareStatement(query)) {
statement.setString(1, description);
statement.setInt(2, module);
statement.setObject(3, address.toBigInteger(), Types.BIGINT);
statement.executeUpdate();
} catch (final SQLException exception) {
throw new CouldntSaveDataException(exception);
}
}
Aggregations