use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CViewInserter method createNodes.
/**
* Clones a node of the source view and inserts it into the target view.
*
* @param target The target view where the cloned view is inserted.
* @param sourceNode The source node that is cloned and inserted into the target view.
* @param nodeMap Maps nodes of the source view to their cloned counterparts.
*/
private static void createNodes(final INaviView target, final INaviViewNode sourceNode, final Map<INaviViewNode, INaviViewNode> nodeMap) {
final INaviViewNode newNode = CNodeTypeSwitcher.switchNode(sourceNode, new INodeTypeCallback<INaviViewNode>() {
@Override
public INaviViewNode handle(final INaviCodeNode node) {
return insertCodeNode(target, node);
}
@Override
public INaviViewNode handle(final INaviFunctionNode node) {
return insertFunctionNode(target, node);
}
@Override
public INaviViewNode handle(final INaviGroupNode node) {
// Skip now, create later
return null;
}
@Override
public INaviViewNode handle(final INaviTextNode node) {
return insertTextNode(target, node);
}
});
if (newNode != null) {
newNode.setBorderColor(sourceNode.getBorderColor());
newNode.setColor(sourceNode.getColor());
newNode.setHeight(sourceNode.getHeight());
newNode.setSelected(sourceNode.isSelected());
newNode.setVisible(sourceNode.isVisible());
newNode.setWidth(sourceNode.getWidth());
newNode.setX(sourceNode.getX());
newNode.setY(sourceNode.getY());
nodeMap.put(sourceNode, newNode);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode 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.INaviCodeNode 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.INaviCodeNode in project binnavi by google.
the class CGraphInliner method inlineAll.
/**
* Inlines all function calls of a given graph.
*
* @param parent Parent window used for dialogs.
* @param container Contains the functions to be inlined.
* @param graph Graph where the inline operation takes place.
*/
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
final List<INaviViewNode> nodes = mutableGraph.getNodes();
final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
for (final INaviViewNode iNaviViewNode : nodes) {
if (iNaviViewNode instanceof INaviCodeNode) {
instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
}
}
for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
INaviCodeNode updatedNode = null;
for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
if (codeNode.hasInstruction(iNaviInstruction)) {
updatedNode = codeNode;
}
}
if (updatedNode != null) {
inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
} else {
throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CCodeNodeMenu method addOperandTreeNodeMenu.
/**
* Adds menus for the clicked operand.
*
* @param model The graph model that provides information about the graph.
* @param treeNode The clicked operand node.
* @param extensions The extension menu items for the "Operands" menu.
* @param instruction The instruction that was clicked.
* @param node The basic block that contains the clicked instruction.
*/
private void addOperandTreeNodeMenu(final CGraphModel model, final COperandTreeNode treeNode, final NaviNode node, final INaviInstruction instruction, final List<ICodeNodeExtension> extensions) {
final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
final INaviModule module = model.getViewContainer().getModules().get(0);
// We only show the goto address if we have no associated type instance for the given immediate.
if (treeNode.getType() == ExpressionType.IMMEDIATE_INTEGER && treeNode.getTypeInstanceReferences().isEmpty()) {
addImmediateOperandMenu(treeNode, module.getContent().getSections(), module);
}
if (treeNode.getType() == ExpressionType.REGISTER) {
addRegisterOperandMenu(model, treeNode, instruction, extensions, codeNode);
}
final INaviReplacement replacement = treeNode.getReplacement();
// precedence over type instances.
if (!treeNode.getTypeInstanceReferences().isEmpty() && !(replacement instanceof CFunctionReplacement)) {
addInstanceReferenceMenu(model, treeNode);
}
if (replacement instanceof CFunctionReplacement) {
addFunctionOperandMenu(model, replacement);
}
}
Aggregations