use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CGraphSynchronizer method updateInstructionMap.
/**
* Updates the cached Address => Instruction map.
*/
private void updateInstructionMap() {
m_instructionMap.clear();
for (final INaviViewNode node : m_graph.getRawView().getGraph()) {
if (node instanceof INaviCodeNode) {
final INaviCodeNode cnode = (INaviCodeNode) node;
for (final INaviInstruction instruction : cnode.getInstructions()) {
final IAddress address = instruction.getAddress();
m_instructionMap.put(address, instruction);
}
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class PostgreSQLCommentNotificationParser method processNodeGlobalCommentNotification.
/**
* Parses the notifications from the database back end for global code node comments by using a
* regular expression. If the regular expression matches the supplied {@link PGNotification}
* notification, it is determined if the code node in the notification is currently loaded, and if
* a {@link CommentNotificationContainer} with the data from the notification is returned.
*
* @param notification The {@link PGNotification} from the PostgreSQL database server.
* @param provider The {@link SQLProvider} which is used to communicate with the database.
*/
static Collection<CommentNotification> processNodeGlobalCommentNotification(final PGNotification notification, final SQLProvider provider) {
final Matcher matcher = NODE_GLOBAL_PATTERN.matcher(notification.getParameter());
if (!matcher.find()) {
return new ArrayList<>();
}
final String databaseOperation = matcher.group(2);
final int moduleId = Integer.parseInt(matcher.group(3));
final IAddress nodeAddress = new CAddress(new BigInteger(matcher.group(4)));
final Integer commentId = matcher.group(6) == null ? null : Integer.parseInt(matcher.group(6));
final INaviModule notificationModule = provider.findModule(moduleId);
if ((notificationModule == null) || !notificationModule.isLoaded()) {
return new ArrayList<>();
}
final ImmutableCollection<INaviViewNode> nodes = NodeCache.get(provider).getNodeByAddress(nodeAddress, moduleId);
if (nodes == null) {
return new ArrayList<>();
}
final CommentOperation operation = databaseOperation.equalsIgnoreCase("DELETE") ? CommentOperation.DELETE : CommentOperation.APPEND;
Collection<CommentNotification> notifications = new ArrayList<>();
for (INaviViewNode node : nodes) {
notifications.add(new CodeNodeCommentNotificationContainer((INaviCodeNode) node, operation, CommentScope.GLOBAL, commentId));
}
return notifications;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class PostgreSQLEdgeLoader method loadEdges.
/**
* Loads the edges of a view.
*
* @param provider The connection to the database.
* @param view The view whose edges are loaded.
* @param nodeLookup Maps between node IDs and their corresponding node objects.
* @param edgeToGlobalCommentMap Maps between edge IDs and their associated comments.
*
* @return The loaded edges.
*
* @throws CouldntLoadDataException
*/
private static List<INaviEdge> loadEdges(final AbstractSQLProvider provider, final INaviView view, final Map<Integer, INaviViewNode> nodeLookup, final Map<Integer, ArrayList<IComment>> edgeToGlobalCommentMap) throws CouldntLoadDataException {
final String query = "SELECT * FROM load_view_edges(" + view.getConfiguration().getId() + ")";
List<CBend> currentPaths = new ArrayList<CBend>();
final Map<Integer, INaviEdge> commentIdToEdge = new HashMap<Integer, INaviEdge>();
final Map<Integer, INaviEdge> edgeIdToEdge = new HashMap<Integer, INaviEdge>();
try {
final CConnection connection = provider.getConnection();
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final int edgeId = resultSet.getInt("id");
if (edgeIdToEdge.containsKey(edgeId)) {
final INaviEdge edge = edgeIdToEdge.get(edgeId);
final double pathX = resultSet.getDouble("x");
final double pathY = resultSet.getDouble("y");
if (!resultSet.wasNull()) {
edge.addBend(pathX, pathY);
}
continue;
}
final int sourceNode = resultSet.getInt("source_node_id");
final int targetNode = resultSet.getInt("target_node_id");
Integer localCommentId = resultSet.getInt("comment_id");
if (resultSet.wasNull()) {
localCommentId = null;
}
final double x1 = resultSet.getDouble("x1");
final double y1 = resultSet.getDouble("y1");
final double x2 = resultSet.getDouble("x2");
final double y2 = resultSet.getDouble("y2");
final EdgeType type = EdgeType.valueOf(resultSet.getString("type").toUpperCase());
final Color color = new Color(resultSet.getInt("color"));
final boolean visible = resultSet.getBoolean("visible");
final boolean selected = resultSet.getBoolean("selected");
final INaviViewNode source = nodeLookup.get(sourceNode);
final INaviViewNode target = nodeLookup.get(targetNode);
final double pathX = resultSet.getDouble("x");
final double pathY = resultSet.getDouble("y");
if (!resultSet.wasNull()) {
currentPaths.add(new CBend(pathX, pathY));
}
final CNaviViewEdge edge = new CNaviViewEdge(edgeId, source, target, type, x1, y1, x2, y2, color, selected, visible, null, currentPaths, provider);
if (localCommentId != null) {
commentIdToEdge.put(localCommentId, edge);
}
final ArrayList<IComment> globalComments = edgeToGlobalCommentMap.containsKey(edgeId) ? edgeToGlobalCommentMap.get(edgeId) : null;
if ((globalComments != null) && (globalComments.size() != 0)) {
initializeGlobalComment(edge, globalComments, provider);
}
source.addOutgoingEdge(edge);
target.addIncomingEdge(edge);
edgeIdToEdge.put(edge.getId(), edge);
currentPaths = new ArrayList<CBend>();
}
if (!commentIdToEdge.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToEdge.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
commentIdToEdge.get(commentIdToComment.getKey()).initializeLocalComment(commentIdToComment.getValue());
}
}
} finally {
resultSet.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException("Error: Loading of view edges failed");
}
return Lists.newArrayList(edgeIdToEdge.values());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class PostgreSQLViewSaver method save.
/**
* Saves a view to the database.
*
* @param provider The SQL provider that provides the connection.
* @param view The view to save to the database.
*
* @throws CouldntSaveDataException Thrown if the view could not be saved to the database.
*/
public static void save(final AbstractSQLProvider provider, final CView view) throws CouldntSaveDataException {
PostgreSQLViewSaver.checkArguments(provider, view);
final CConnection connection = provider.getConnection();
try {
PostgreSQLHelpers.beginTransaction(connection);
final int viewId = view.getConfiguration().getId();
final List<INaviViewNode> nodes = view.getGraph().getNodes();
final List<INaviEdge> edges = view.getGraph().getEdges();
PostgreSQLViewSaver.deleteNodes(connection, viewId);
// Store all nodes
PostgreSQLNodeSaver.writeNodes(provider, viewId, nodes);
// Store all edges
PostgreSQLEdgeSaver.writeEdges(provider, edges);
PostgreSQLHelpers.endTransaction(connection);
} catch (final SQLException exception) {
try {
PostgreSQLHelpers.rollback(connection);
} catch (final SQLException e) {
CUtilityFunctions.logException(e);
}
throw new CouldntSaveDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class NodeCache method addNodes.
public void addNodes(final List<INaviViewNode> nodes) {
nodeByIdCache.putAll(Maps.uniqueIndex(nodes, new Function<INaviViewNode, Integer>() {
@Override
public Integer apply(final INaviViewNode node) {
return node.getId();
}
}));
for (final INaviViewNode node : nodes) {
if (node instanceof INaviCodeNode) {
final IAddress nodeAddress = ((INaviCodeNode) node).getAddress();
Integer moduleId = null;
try {
moduleId = ((INaviCodeNode) node).getParentFunction().getModule().getConfiguration().getId();
} catch (final MaybeNullException e) {
continue;
}
if (moduleId != null) {
UpdateAddressModuleIdCache(nodeAddress, moduleId, node);
}
}
}
}
Aggregations