use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class CGraphGrouper method determineNodeText.
/**
* Determines the text to be displayed in a group node, if the given node is inside a collapsed
* group node.
*
* @param node The node whose text is determined.
*
* @return The string to be displayed for the given node.
*/
private static String determineNodeText(final NaviNode node) {
if (node.getRawNode() instanceof INaviCodeNode) {
final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
return String.format("Basic Block: %s", cnode.getAddress().toHexString());
} else if (node.getRawNode() instanceof INaviFunctionNode) {
final INaviFunctionNode fnode = (INaviFunctionNode) node.getRawNode();
return String.format("Function: %s (%s)", fnode.getFunction().getName(), fnode.getFunction().getAddress().toHexString());
} else if (node.getRawNode() instanceof INaviTextNode) {
// Display up to 15 characters of the first line of
// the comment for comment nodes.
final INaviTextNode tnode = (INaviTextNode) node.getRawNode();
final List<IComment> comment = tnode.getComments();
final String firstLine = (comment.isEmpty()) ? "" : comment.get(1).getComment();
final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
return String.format("Text: %s", firstLine.substring(0, toDisplay));
} else if (node.getRawNode() instanceof INaviGroupNode) {
// Display up to 15 characters of the first line of
// the comment for group nodes.
final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
final List<IComment> comment = gnode.getComments();
final String firstLine = (comment.isEmpty()) ? "" : comment.get(0).getComment();
final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
return String.format("Group: %s", firstLine.substring(0, toDisplay));
} else {
throw new IllegalStateException("IE01150: Unknown node type");
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class PostgreSQLNodeSaver method saveFunctionNodes.
/**
* Saves the function nodes to the database.
*
* @param provider The connection to the database.
* @param nodes The nodes to save.
* @param firstNode The database index of the first node.
* @param functionNodeIndices Index into the nodes list that identifies the function nodes.
*
* @throws SQLException Thrown if saving the function nodes failed.
*/
protected static void saveFunctionNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> functionNodeIndices) throws SQLException {
if (functionNodeIndices.isEmpty()) {
return;
}
final String query = "INSERT INTO " + CTableNames.FUNCTION_NODES_TABLE + "(module_id, node_id, function, comment_id) VALUES (?, ?, ?, ?)";
final ArrayList<INaviFunctionNode> functionNodesWithUnsavedComments = new ArrayList<INaviFunctionNode>();
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
try {
for (final int index : functionNodeIndices) {
final CFunctionNode node = (CFunctionNode) nodes.get(index);
final INaviFunction function = node.getFunction();
final List<IComment> comments = node.getLocalFunctionComment();
final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
functionNodesWithUnsavedComments.add(node);
}
preparedStatement.setInt(1, function.getModule().getConfiguration().getId());
preparedStatement.setInt(2, firstNode + index);
preparedStatement.setObject(3, function.getAddress().toBigInteger(), Types.BIGINT);
if (commentId == null) {
preparedStatement.setNull(4, Types.INTEGER);
} else {
preparedStatement.setInt(4, commentId);
}
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
} finally {
preparedStatement.close();
}
for (final INaviFunctionNode functionNode : functionNodesWithUnsavedComments) {
final ArrayList<IComment> functionNodeComments = new ArrayList<IComment>();
for (final IComment comment : functionNode.getLocalFunctionComment()) {
try {
final Integer commentId = provider.appendFunctionNodeComment(functionNode, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
functionNodeComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
functionNode.initializeLocalFunctionComment(functionNodeComments);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class InternalNodeCallBack method zoomToAddress.
/**
* Zooms to the first occurrence of an address in a graph.
*
* @param graph The graph where the zoom operation takes place.
* @param address The address to zoom to.
*/
public static void zoomToAddress(final ZyGraph graph, final IAddress address) {
graph.iterate(new INodeCallback<NaviNode>() {
@Override
public IterationMode next(final NaviNode node) {
if (node.getRawNode() instanceof INaviCodeNode) {
final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
for (final INaviInstruction instruction : codeNode.getInstructions()) {
if (instruction.getAddress().equals(address)) {
uncollapseParents(codeNode);
graph.showNode(node, true);
ZoomFunctions.zoomToNode(graph, node);
return IterationMode.STOP;
}
}
} else if (node.getRawNode() instanceof INaviFunctionNode) {
final INaviFunctionNode functionNode = (INaviFunctionNode) node.getRawNode();
if (functionNode.getFunction().getAddress().equals(address)) {
uncollapseParents(functionNode);
graph.showNode(node, true);
ZoomFunctions.zoomToNode(graph, node);
return IterationMode.STOP;
}
}
return IterationMode.CONTINUE;
}
});
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class CDebuggerPainter method updateDebuggerHighlighting.
/**
* Updates the program counter highlighting in a whole graph.
*
* @param graph The graph where the highlighting is updated.
* @param address The address of the program counter to be highlighted.
* @param module The module in which the address is located.
*/
public static void updateDebuggerHighlighting(final ZyGraph graph, final UnrelocatedAddress address, final INaviModule module) {
Preconditions.checkNotNull(graph, "IE02187: Graph argument can not be null");
Preconditions.checkNotNull(address, "IE02188: Address argument can not be null");
graph.iterate(new INodeCallback<NaviNode>() {
@Override
public IterationMode next(final NaviNode node) {
final INaviViewNode rawNode = node.getRawNode();
if (rawNode instanceof ICodeNode) {
final INaviCodeNode codeNode = (INaviCodeNode) rawNode;
try {
if (module.equals(codeNode.getParentFunction().getModule())) {
updateDebuggerHighlighting(graph, address, node, codeNode);
}
} catch (final MaybeNullException exception) {
CUtilityFunctions.logException(exception);
}
} else if (rawNode instanceof INaviFunctionNode) {
final INaviFunctionNode functionNode = (INaviFunctionNode) rawNode;
if (module.equals(functionNode.getFunction().getModule())) {
updateDebuggerHighlighting(address, node, functionNode);
}
}
return IterationMode.CONTINUE;
}
});
ZyZoomHelpers.zoomToAddress(graph, address.getAddress(), module, false);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testAppendFunctionNodeCommentSync.
@Test
public void testAppendFunctionNodeCommentSync() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, CouldntSaveDataException, InterruptedException {
databaseOneCallGraph = databaseOneModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
databaseOneCallGraph.load();
final INaviFunctionNode databaseOneFunctionNode = (INaviFunctionNode) databaseOneCallGraph.getGraph().getNodes().get(1);
databaseTwoCallGraph = databaseTwoModuleTwo.getContent().getViewContainer().getNativeCallgraphView();
databaseTwoCallGraph.load();
final INaviFunctionNode databaseTwoFunctionNode = (INaviFunctionNode) databaseTwoCallGraph.getGraph().getNodes().get(1);
final List<IComment> oneBefore = databaseOneFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseOneFunctionNode.getLocalFunctionComment();
final List<IComment> twoBefore = databaseTwoFunctionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : databaseTwoFunctionNode.getLocalFunctionComment();
assertEquals(oneBefore, twoBefore);
databaseOneFunctionNode.appendLocalFunctionComment(" TEST NOTIFICATION PROVIDER TESTS (LOCAL FUNCTION NODE COMMENT) ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOneFunctionNode.getLocalFunctionComment();
final List<IComment> twoAfter = databaseTwoFunctionNode.getLocalFunctionComment();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
}
Aggregations