use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class CViewPruner method convertNodes.
/**
* Converts the nodes from the original view to the pruned view.
*
* @param view The original view.
* @param prunedView The pruned view.
* @param keptInstructions Instructions to add to the new view.
*
* @return A mapping between nodes of the original view and nodes of the pruned view.
*/
private static Map<INaviViewNode, INaviViewNode> convertNodes(final INaviView view, final INaviView prunedView, final List<INaviInstruction> keptInstructions) {
final Map<INaviViewNode, INaviViewNode> nodeMap = new HashMap<INaviViewNode, INaviViewNode>();
for (final INaviViewNode node : view.getGraph().getNodes()) {
if (node instanceof INaviCodeNode) {
final INaviCodeNode cnode = (INaviCodeNode) node;
final ArrayList<INaviInstruction> newInstructions = Lists.newArrayList(cnode.getInstructions());
newInstructions.retainAll(keptInstructions);
if (!newInstructions.isEmpty()) {
CCodeNode newNode;
try {
newNode = prunedView.getContent().createCodeNode(cnode.getParentFunction(), newInstructions);
} catch (final MaybeNullException e) {
newNode = prunedView.getContent().createCodeNode(null, newInstructions);
}
newNode.setBorderColor(node.getBorderColor());
newNode.setColor(node.getColor());
nodeMap.put(node, newNode);
}
} else if (node instanceof INaviFunctionNode) {
final INaviFunction function = ((INaviFunctionNode) node).getFunction();
final CFunctionNode newNode = prunedView.getContent().createFunctionNode(function);
nodeMap.put(node, newNode);
}
}
return nodeMap;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class CGlobalEdgeCommentSynchronizer method getModules.
/**
* Returns the modules the nodes of the edge belong to.
*
* @param edge The edge to check.
*
* @return Source module and target module of the edge.
*
* @throws MaybeNullException Thrown if the edge does not have source module or target module.
*/
private static Pair<INaviModule, INaviModule> getModules(final INaviEdge edge) throws MaybeNullException {
INaviModule srcModule = null;
INaviModule tarModule = null;
if (edge.getSource() instanceof INaviCodeNode) {
srcModule = ((INaviCodeNode) edge.getSource()).getParentFunction().getModule();
} else if (edge.getSource() instanceof INaviFunctionNode) {
srcModule = ((INaviFunctionNode) edge.getSource()).getFunction().getModule();
}
if (edge.getTarget() instanceof INaviCodeNode) {
tarModule = ((INaviCodeNode) edge.getTarget()).getParentFunction().getModule();
} else if (edge.getTarget() instanceof INaviFunctionNode) {
tarModule = ((INaviFunctionNode) edge.getTarget()).getFunction().getModule();
}
return new Pair<INaviModule, INaviModule>(srcModule, tarModule);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode in project binnavi by google.
the class CSteppingHelper method getAddress.
/**
* Determines the start address of a node.
*
* @param node Node whose address is determined.
*
* @return The start address of the given node or null if the node does not have an address.
*/
private static BreakpointAddress getAddress(final INaviViewNode node) {
if (node instanceof INaviCodeNode) {
final INaviCodeNode ccnode = (INaviCodeNode) node;
final INaviInstruction instruction = Iterables.getFirst(ccnode.getInstructions(), null);
return new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
} else if (node instanceof INaviFunctionNode) {
final INaviFunction function = ((INaviFunctionNode) node).getFunction();
final INaviModule module = function.getModule();
return new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress()));
} else {
// Node types we can not step to
return null;
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode 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.INaviFunctionNode in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testDeleteFunctionNodeCommentSync.
@Test
public void testDeleteFunctionNodeCommentSync() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, CouldntSaveDataException, InterruptedException, CouldntDeleteException {
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);
final List<IComment> comments = 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);
final int oneTwoSize = oneAfter.size();
final int twoTwoSize = twoAfter.size();
databaseOneFunctionNode.deleteLocalFunctionComment(Iterables.getLast(comments));
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneThree = databaseOneFunctionNode.getLocalFunctionComment();
final List<IComment> twoThree = databaseTwoFunctionNode.getLocalFunctionComment();
assertEquals(oneTwoSize - 1, oneThree.size());
assertEquals(twoTwoSize - 1, twoThree.size());
assertEquals(oneThree, twoThree);
}
Aggregations