use of com.google.security.zynamics.binnavi.disassembly.INaviGroupNode in project binnavi by google.
the class CNodeClickHandler method nodeClicked.
/**
* Handles clicks on nodes.
*
* @param node The clicked node.
* @param event The click event.
* @param x The x-coordinate of the click.
* @param y The y-coordinate of the click.
* @param extensions List of objects that extend code node context menus.
*/
public void nodeClicked(final NaviNode node, final MouseEvent event, final double x, final double y, final List<ICodeNodeExtension> extensions) {
if (event.getButton() == MouseEvent.BUTTON3) {
handleRightClick(node, event, x, y, extensions);
} else if ((event.getButton() == MouseEvent.BUTTON1) && (event.getClickCount() == 2) && event.isControlDown()) {
final INaviViewNode rawNode = node.getRawNode();
if (rawNode instanceof INaviFunctionNode) {
final INaviFunction function = ((INaviFunctionNode) rawNode).getFunction();
CGraphOpener.showFunction(m_model.getParent(), m_model.getViewContainer(), function);
} else if (rawNode instanceof INaviCodeNode) {
final INaviCodeNode cnode = (INaviCodeNode) rawNode;
final int row = node.positionToRow(y - node.getY());
final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(cnode, row);
if (instruction == null) {
return;
}
final Set<IAddress> references = new HashSet<IAddress>();
for (final INaviOperandTree operand : instruction.getOperands()) {
collectReferences(operand.getRootNode(), references);
}
final List<INaviFunction> functions = m_model.getViewContainer().getFunctions();
for (final INaviFunction function : functions) {
for (final IAddress address : references) {
if (function.getAddress().equals(address)) {
CGraphOpener.showFunction(m_model.getParent(), m_model.getViewContainer(), function);
}
}
}
}
} else if (!m_model.getGraph().getEditMode().getLabelEventHandler().isActive() && (event.getButton() == MouseEvent.BUTTON1) && (event.getClickCount() == 2)) {
if ((node.getRawNode() instanceof INaviGroupNode) && event.isShiftDown()) {
final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
gnode.setCollapsed(!gnode.isCollapsed());
} else {
CGraphZoomer.zoomNode(m_model.getGraph(), node);
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviGroupNode in project binnavi by google.
the class CViewContent method deleteNodes.
@Override
public void deleteNodes(final Collection<INaviViewNode> nodes) {
Preconditions.checkNotNull(nodes, "IE00305: Nodes argument can not be null");
// Make defensive copy in order to evade the concurrent modification exception
final Collection<INaviViewNode> nodesCopy = new ArrayList<INaviViewNode>(nodes);
final List<INaviViewNode> gnodes = graph.getNodes();
for (final INaviViewNode naviViewNode : nodesCopy) {
Preconditions.checkNotNull(naviViewNode, "IE00307: Node list contains a null-node");
Preconditions.checkArgument(gnodes.contains(naviViewNode), "IE00308: Node list contains at least one node that is not part of this view");
}
final List<INaviGroupNode> parentsToDelete = new ArrayList<INaviGroupNode>();
for (final INaviViewNode node : nodesCopy) {
if (node instanceof INaviGroupNode) {
if (((INaviGroupNode) node).getNumberOfElements() != 0) {
deleteGroupNode((INaviGroupNode) node);
}
continue;
}
removeEdges(node);
graph.removeNode(node);
node.removeListener(m_internalNodeListener);
final INaviGroupNode parent = node.getParentGroup();
if (parent != null) {
parent.removeElement(node);
if (parent.getParentGroup() != null) {
parent.getParentGroup().addElement(node);
}
if (parent.getNumberOfElements() == 0) {
parentsToDelete.add(parent);
}
}
}
// We remove group nodes from the list of nodes that are put into the listener notification
// because deletedNode notifications were already sent for group nodes when they lost their last
// member.
final Collection<INaviViewNode> filteredNodes = filterGroupNodes(nodesCopy);
for (final INaviViewListener listener : listeners) {
try {
listener.deletedNodes(view, filteredNodes);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
updateGraphType();
}
use of com.google.security.zynamics.binnavi.disassembly.INaviGroupNode in project binnavi by google.
the class CViewInserter method createGroupNodes.
/**
* Clones the group nodes of the source view and inserts them into the target view.
*
* @param target The target view where the cloned group nodes are inserted.
* @param sourceNodes The nodes of the source view.
* @param nodeMap Maps between the source nodes and their cloned counterparts.
*/
private static void createGroupNodes(final INaviView target, final Collection<INaviViewNode> sourceNodes, final Map<INaviViewNode, INaviViewNode> nodeMap) {
for (final INaviViewNode blockNode : sourceNodes) {
if (blockNode instanceof INaviGroupNode) {
final INaviGroupNode gnode = (INaviGroupNode) blockNode;
final CGroupNode newGroupNode = target.getContent().createGroupNode(getNodes(gnode.getElements(), nodeMap));
newGroupNode.initializeComment(gnode.getComments());
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviGroupNode in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testEditGroupNodeComment.
@Test
public void testEditGroupNodeComment() throws CouldntSaveDataException, CouldntLoadDataException, CPartialLoadException, LoadCancelledException, InterruptedException {
final CView databaseOneGroupNodeView = databaseOneModuleTwo.getContent().getViewContainer().createView(" GROUP NODE TESTING VIEW ", "");
CViewInserter.insertView(databaseOneView, databaseOneGroupNodeView);
final INaviGroupNode databaseOneGroupNode = databaseOneGroupNodeView.getContent().createGroupNode(databaseOneGroupNodeView.getGraph().getNodes());
databaseOneGroupNodeView.save();
databaseTwoModuleTwo.close();
databaseTwoModuleTwo.load();
databaseTwoView.load();
final INaviView databaseTwoGroupNodeView = Iterables.getLast(databaseTwoModuleTwo.getContent().getViewContainer().getUserViews());
INaviGroupNode databaseTwoGroupNode = null;
assertEquals(databaseOneGroupNodeView.getName(), databaseTwoGroupNodeView.getName());
databaseTwoGroupNodeView.load();
for (final INaviViewNode node : databaseTwoGroupNodeView.getContent().getGraph().getNodes()) {
if (node instanceof INaviGroupNode) {
databaseTwoGroupNode = (INaviGroupNode) node;
}
}
assertNotNull(databaseTwoGroupNode);
assertEquals(databaseTwoGroupNode.getId(), databaseOneGroupNode.getId());
final List<IComment> comments = databaseOneGroupNode.appendComment(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) BEFORE ");
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOneGroupNode.getComments();
final List<IComment> twoAfter = databaseTwoGroupNode.getComments();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(1, oneAfter.size());
assertEquals(1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
final int oneTwoSize = oneAfter.size();
final int twoTwoSize = twoAfter.size();
databaseOneGroupNode.editComment(Iterables.getLast(comments), " TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) AFTER ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneThree = databaseOneGroupNode.getComments();
final List<IComment> twoThree = databaseTwoGroupNode.getComments();
assertEquals(oneTwoSize, oneThree.size());
assertEquals(twoTwoSize, twoThree.size());
assertEquals(oneThree, twoThree);
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviGroupNode in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testDeleteGroupNodeComment.
@Test
public void testDeleteGroupNodeComment() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, CPartialLoadException, InterruptedException, CouldntDeleteException {
final CView databaseOneGroupNodeView = databaseOneModuleTwo.getContent().getViewContainer().createView(" GROUP NODE TESTING VIEW ", "");
CViewInserter.insertView(databaseOneView, databaseOneGroupNodeView);
final INaviGroupNode databaseOneGroupNode = databaseOneGroupNodeView.getContent().createGroupNode(databaseOneGroupNodeView.getGraph().getNodes());
databaseOneGroupNodeView.save();
databaseTwoModuleTwo.close();
databaseTwoModuleTwo.load();
databaseTwoView.load();
final INaviView databaseTwoGroupNodeView = Iterables.getLast(databaseTwoModuleTwo.getContent().getViewContainer().getUserViews());
INaviGroupNode databaseTwoGroupNode = null;
assertEquals(databaseOneGroupNodeView.getName(), databaseTwoGroupNodeView.getName());
databaseTwoGroupNodeView.load();
for (final INaviViewNode node : databaseTwoGroupNodeView.getContent().getGraph().getNodes()) {
if (node instanceof INaviGroupNode) {
databaseTwoGroupNode = (INaviGroupNode) node;
}
}
assertNotNull(databaseTwoGroupNode);
assertEquals(databaseTwoGroupNode.getId(), databaseOneGroupNode.getId());
final List<IComment> comments = databaseOneGroupNode.appendComment(" TEST NOTIFICATION PROVIDER TESTS (GROUP NODE COMMENT) ");
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOneGroupNode.getComments();
final List<IComment> twoAfter = databaseTwoGroupNode.getComments();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(1, oneAfter.size());
assertEquals(1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
final int oneTwoSize = oneAfter.size();
final int twoTwoSize = twoAfter.size();
databaseOneGroupNode.deleteComment(Iterables.getLast(comments));
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneThree = databaseOneGroupNode.getComments();
final List<IComment> twoThree = databaseTwoGroupNode.getComments();
assertEquals(oneTwoSize - 1, oneThree.size());
assertEquals(twoTwoSize - 1, twoThree.size());
assertEquals(oneThree, twoThree);
}
Aggregations