use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class PostgreSQLNotificationParserTest method testGlobalEdgeCommentParsingDeleteLastComment.
@Test
public void testGlobalEdgeCommentParsingDeleteLastComment() {
new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
MockPGNotification notification = new MockPGNotification("comment_changes", "bn_global_edge_comments DELETE 1 1 4608 4614");
Collection<CommentNotification> result = PostgreSQLCommentNotificationParser.processEdgeGlobalCommentNotification(notification, provider);
assertEquals(1, result.size());
final EdgeCommentNotificationContainer container = (EdgeCommentNotificationContainer) Iterables.getFirst(result, null);
final INaviEdge edge = container.getEdge();
assertEquals(1111, edge.getId());
assertEquals(CommentOperation.DELETE, container.getOperation());
assertNull(container.getCommentId());
assertEquals(CommentScope.GLOBAL, container.getScope());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class PostgreSQLNotificationParserTest method testLocalEdgeCommentParsingAppend.
@Test
public void testLocalEdgeCommentParsingAppend() {
new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
MockPGNotification notification = new MockPGNotification("comment_changes", "bn_edges UPDATE 4444 3333");
final CommentNotification result = PostgreSQLCommentNotificationParser.processEdgeLocalCommentNotification(notification, provider);
assertNotNull(result);
final EdgeCommentNotificationContainer container = (EdgeCommentNotificationContainer) result;
final INaviEdge edge = container.getEdge();
assertEquals(4444, edge.getId());
assertEquals(CommentOperation.APPEND, container.getOperation());
assertEquals(new Integer(3333), container.getCommentId());
assertEquals(CommentScope.LOCAL, container.getScope());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class PostgreSQLNotificationParserTest method testGlobalEdgeCommentParsingAppendFirstComment.
@Test
public void testGlobalEdgeCommentParsingAppendFirstComment() {
new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
MockPGNotification notification = new MockPGNotification("comment_changes", "bn_global_edge_comments INSERT 1 1 4608 4614 3333");
final Collection<CommentNotification> result = PostgreSQLCommentNotificationParser.processEdgeGlobalCommentNotification(notification, provider);
assertEquals(1, result.size());
final EdgeCommentNotificationContainer container = (EdgeCommentNotificationContainer) Iterables.getFirst(result, null);
final INaviEdge edge = container.getEdge();
assertEquals(1111, edge.getId());
assertEquals(CommentOperation.APPEND, container.getOperation());
assertEquals(new Integer(3333), container.getCommentId());
assertEquals(CommentScope.GLOBAL, container.getScope());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class View method convertData.
/**
* Converts internal view data to API view data.
*/
private void convertData() {
final IDirectedGraph<INaviViewNode, INaviEdge> graph = naviView.getGraph();
final List<ViewNode> blocks = new ArrayList<ViewNode>();
final List<ViewEdge> edges = new ArrayList<ViewEdge>();
for (final INaviViewNode block : graph.getNodes()) {
// ESCA-JAVA0177:
final ViewNode newBlock = convert(block);
cachedNodes.put(block, newBlock);
blocks.add(newBlock);
}
for (final INaviViewNode block : graph.getNodes()) {
if (block.getParentGroup() != null) {
((GroupNode) cachedNodes.get(block.getParentGroup())).addNode(cachedNodes.get(block));
}
}
for (final INaviEdge edge : graph.getEdges()) {
final ViewNode source = cachedNodes.get(edge.getSource());
final ViewNode target = cachedNodes.get(edge.getTarget());
final ViewEdge viewEdge = new ViewEdge(edge, source, target);
edges.add(viewEdge);
cachedEdges.put(edge, viewEdge);
}
viewGraph = new ViewGraph(blocks, edges);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CNodeFunctions method splitAfter.
/**
* Splits a node.
*
* @param view View the node belongs to.
* @param originalNode Node to split.
* @param instruction Instruction after which the node is split.
*/
public static void splitAfter(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction instruction) {
final Iterable<INaviInstruction> oldInstructions = originalNode.getInstructions();
if (instruction == Iterables.getLast(oldInstructions)) {
return;
}
// Step I: Find out what instructions belong to the new upper block and what
// instructions belong to the new lower block.
final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
List<INaviInstruction> currentInstructions = upperInstructions;
for (final INaviInstruction oldInstruction : oldInstructions) {
currentInstructions.add(oldInstruction);
if (oldInstruction == instruction) {
currentInstructions = lowerInstructions;
}
}
// Step II: Create the two new code nodes.
INaviFunction parentFunction = null;
try {
parentFunction = originalNode.getParentFunction();
} catch (final MaybeNullException e) {
// No parent function
}
final INaviCodeNode newNode1 = view.getContent().createCodeNode(parentFunction, upperInstructions);
final INaviCodeNode newNode2 = view.getContent().createCodeNode(parentFunction, lowerInstructions);
newNode1.setColor(originalNode.getColor());
newNode1.setBorderColor(originalNode.getBorderColor());
newNode2.setColor(originalNode.getColor());
// Step III: Transfer node comments and instruction comments from the old node
// to the new nodes.
transferLocalCodeNodeComments(originalNode, newNode1, newNode2);
// Step IV: Connect the two new nodes.
view.getContent().createEdge(newNode1, newNode2, EdgeType.JUMP_UNCONDITIONAL);
for (final INaviEdge incomingEdge : originalNode.getIncomingEdges()) {
view.getContent().createEdge(incomingEdge.getSource(), newNode1, incomingEdge.getType());
}
for (final INaviEdge outgoingEdge : originalNode.getOutgoingEdges()) {
view.getContent().createEdge(newNode2, outgoingEdge.getTarget(), outgoingEdge.getType());
}
// Step VI: Get rid of the old node.
view.getContent().deleteNode(originalNode);
}
Aggregations