use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLModuleFlowgraphsLoader method loadFlowGraphInformation.
public static ImmutableNaviViewConfiguration loadFlowGraphInformation(final SQLProvider provider, final INaviModule module, final Integer viewId) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02275: provider argument can not be null");
Preconditions.checkNotNull(module, "IE02394: module argument can not be null");
Preconditions.checkNotNull(viewId, "IE02419: viewId argument can not be null");
final CConnection connection = provider.getConnection();
final String query = " SELECT * FROM load_module_flowgraph_information(?,?) ";
try {
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
statement.setInt(2, viewId);
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
final int databaseViewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final ViewType viewType = resultSet.getString("type").equalsIgnoreCase("native") ? ViewType.Native : ViewType.NonNative;
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean isStared = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final ImmutableNaviViewConfiguration viewConfiguration = new ImmutableNaviViewConfiguration(databaseViewId, name, description, viewType, creationDate, modificationDate, isStared, nodeCount, edgeCount);
return viewConfiguration;
}
return null;
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class PostgreSQLModuleMixedGraphsLoader method loadMixedgraphs.
/**
* Loads the mixed-graph views of a module. These mixed graph views are necessarily non-native
* because there are no native mixed graph views.
*
* The module, the view tag manager, and the node tag manager must be stored in the database
* connected to by the provider argument.
*
* @param provider The SQL provider that provides the connection.
* @param module The module from where the views are loaded.
* @param viewTagManager View tag manager that contains all view tags of the database.
* @param nodeTagManager The tag manager responsible for tagging view nodes.
*
* @return A list of non-native mixed-graph views.
*
* @throws CouldntLoadDataException Thrown if the views could not be loaded.
*/
public static IFilledList<INaviView> loadMixedgraphs(final AbstractSQLProvider provider, final CModule module, final CTagManager viewTagManager, final CTagManager nodeTagManager) throws CouldntLoadDataException {
checkArguments(provider, module, viewTagManager);
final String query = "SELECT * FROM load_module_mixed_graph(?)";
try {
final CConnection connection = provider.getConnection();
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
final ResultSet resultSet = statement.executeQuery();
final Map<Integer, Set<CTag>> tags = loadTags(connection, module, viewTagManager);
return new FilledList<INaviView>(processQueryResults(resultSet, module, tags, nodeTagManager, provider, new ArrayList<CView>(), ViewType.NonNative, GraphType.MIXED_GRAPH));
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class CGraphGrouper method groupNodes.
/**
* Creates a new group node from a list of nodes.
*
* @param graph The graph where the group node is created.
* @param nodes The nodes to be grouped.
*/
private static void groupNodes(final ZyGraph graph, final List<NaviNode> nodes) {
final StringBuilder stringBuilder = new StringBuilder();
final List<INaviViewNode> rawNodes = new ArrayList<INaviViewNode>();
// ATTENTION: DO NOT MOVE THIS LINE BELOW THE REMOVEELEMENT LINE
final INaviGroupNode commonParent = getCommonParent(nodes);
for (final NaviNode node : nodes) {
if (node.getRawNode().getParentGroup() != null) {
node.getRawNode().getParentGroup().removeElement(node.getRawNode());
}
rawNodes.add(node.getRawNode());
stringBuilder.append(determineNodeText(node));
stringBuilder.append('\n');
}
final CGroupNode groupNode = graph.getRawView().getContent().createGroupNode(rawNodes);
if (commonParent != null) {
commonParent.addElement(groupNode);
}
try {
groupNode.appendComment(stringBuilder.toString());
} catch (CouldntSaveDataException | CouldntLoadDataException exception) {
CUtilityFunctions.logException(exception);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class CGraphInliner method getFunctionToInline.
/**
* Determines the function to inline with consideration of function forwarding.
*
* @param parent Parent window used for dialogs.
* @param viewContainer Contains the function to inline.
* @param function The function to be inlined.
* @param forwarderModuleId Module ID of the module the function is forwarded to.
* @param forwarderAddress Address of the function the function is forwarded to. This argument can
* be null.
*
* @return The function to be inlined.
*/
private static INaviFunction getFunctionToInline(final JFrame parent, final IViewContainer viewContainer, final INaviFunction function, final int forwarderModuleId, final IAddress forwarderAddress) {
if (forwarderAddress == null) {
return function;
} else {
final IDatabase database = viewContainer.getDatabase();
final INaviModule module = database.getContent().getModule(forwarderModuleId);
if (!viewContainer.containsModule(module)) {
CMessageBox.showInformation(parent, String.format("You are trying to inline an external function into a module view. " + "This is not possible.\n" + "To inline external functions it is necessary to create projects."));
return null;
}
if (!module.isLoaded()) {
try {
module.load();
} catch (final CouldntLoadDataException | LoadCancelledException e) {
CUtilityFunctions.logException(e);
return null;
}
}
return module.getContent().getFunctionContainer().getFunction(forwarderAddress);
}
}
use of com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException in project binnavi by google.
the class CProject method load.
@Override
public void load() throws CouldntLoadDataException, LoadCancelledException {
synchronized (m_loadReporter) {
if (isLoaded()) {
return;
}
m_isLoading = true;
try {
if (!m_loadReporter.report(ProjectLoadEvents.Starting)) {
throw new LoadCancelledException();
}
if (!m_loadReporter.report(ProjectLoadEvents.LoadingAddressSpaces)) {
throw new LoadCancelledException();
}
final List<CAddressSpace> addressSpaces = m_provider.loadAddressSpaces(this);
for (final CAddressSpace space : addressSpaces) {
space.load();
}
if (!m_loadReporter.report(ProjectLoadEvents.LoadingCallgraphViews)) {
throw new LoadCancelledException();
}
final List<ICallgraphView> userCallgraphs = m_provider.loadCallgraphViews(this);
if (!m_loadReporter.report(ProjectLoadEvents.LoadingFlowgraphViews)) {
throw new LoadCancelledException();
}
final List<IFlowgraphView> userFlowgraphs = m_provider.loadFlowgraphs(this);
if (!m_loadReporter.report(ProjectLoadEvents.LoadingMixedgraphViews)) {
throw new LoadCancelledException();
}
final List<INaviView> userMixedgraphs = m_provider.loadMixedgraphs(this);
if (!m_loadReporter.report(ProjectLoadEvents.LoadingTraces)) {
throw new LoadCancelledException();
}
final List<TraceList> traces = m_provider.loadTraces(this);
final ArrayList<INaviView> views = new ArrayList<INaviView>(userCallgraphs);
views.addAll(userFlowgraphs);
views.addAll(userMixedgraphs);
m_content = new CProjectContent(this, m_listeners, m_provider, addressSpaces, views, new FilledList<TraceList>(traces));
} catch (CouldntLoadDataException | LoadCancelledException e) {
m_isLoading = false;
throw e;
} finally {
m_loadReporter.report(ProjectLoadEvents.Finished);
}
for (final IProjectListener listener : m_listeners) {
try {
listener.loadedProject(this);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
m_isLoading = false;
}
}
Aggregations