use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class OpenInLastWindowAndZoomToAddressAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent event) {
final FutureCallback<Boolean> callBack = new FutureCallback<Boolean>() {
@Override
public void onFailure(final Throwable t) {
CUtilityFunctions.logException(t);
}
@Override
public void onSuccess(final Boolean result) {
ZyGraph graph = null;
final List<CGraphWindow> windows = CWindowManager.instance().getOpenWindows();
for (final CGraphWindow graphContainer : windows) {
for (final IGraphPanel window : graphContainer) {
if (reference.getView().equals(window.getModel().getGraph().getRawView())) {
graph = window.getModel().getGraph();
}
}
}
for (final NaviNode node : graph.getNodes()) {
if (node.getRawNode() instanceof INaviCodeNode) {
final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
for (final INaviInstruction instruction : codeNode.getInstructions()) {
if (instruction.getAddress().equals(reference.getAddress())) {
ZyZoomHelpers.zoomToAddress(graph, reference.getAddress());
CrossReferencePainter.paintCrossReference(node, codeNode, reference, instruction);
}
}
}
}
}
};
CShowViewFunctions.showViewsAndPerformCallBack(m_parent, m_container, m_views, CWindowManager.instance().getLastWindow(), callBack);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CViewContent method updateGraphType.
/**
* Calculates the new graph type of the view from the current state of the view graph.
*/
private void updateGraphType() {
boolean hasCodeNode = false;
boolean hasFunctionNode = false;
for (final INaviViewNode node : graph.getNodes()) {
if (node instanceof INaviFunctionNode) {
hasFunctionNode = true;
if (hasCodeNode) {
setGraphType(GraphType.MIXED_GRAPH);
return;
}
} else if (node instanceof INaviCodeNode) {
hasCodeNode = true;
if (hasFunctionNode) {
setGraphType(GraphType.MIXED_GRAPH);
return;
}
}
}
if (hasCodeNode) {
setGraphType(GraphType.FLOWGRAPH);
} else if (hasFunctionNode) {
setGraphType(GraphType.CALLGRAPH);
} else {
setGraphType(GraphType.MIXED_GRAPH);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CDataflowViewCreator method create.
/**
* Creates a new dataflow view.
*
* @param container The container in which the dataflow view is created.
* @param view The normal view that provides the control-flow information.
*
* @return The created dataflow view.
*
* @throws InternalTranslationException Thrown if the input view could not be translated to REIL.
*/
public static INaviView create(final IViewContainer container, final INaviView view) throws InternalTranslationException {
Preconditions.checkNotNull(container, "IE00411: Module argument can not be null");
Preconditions.checkNotNull(view, "IE00414: View argument can not be null");
final Map<IAddress, INaviInstruction> instructions = new HashMap<IAddress, INaviInstruction>();
for (final CCodeNode codeNode : view.getBasicBlocks()) {
for (final INaviInstruction instruction : codeNode.getInstructions()) {
instructions.put(instruction.getAddress(), instruction);
}
}
final ReilFunction function = view.getContent().getReilCode();
final OperandGraph operandGraph = OperandGraph.create(function.getGraph());
final INaviView dfView = container.createView(String.format("Data flow view of '%s'", view.getName()), "");
final Map<OperandGraphNode, INaviCodeNode> nodeMap = new HashMap<OperandGraphNode, INaviCodeNode>();
final Map<INaviInstruction, CCodeNode> instructionMap = new HashMap<INaviInstruction, CCodeNode>();
for (final OperandGraphNode operandGraphNode : operandGraph) {
final ReilInstruction reilInstruction = operandGraphNode.getInstruction();
final INaviInstruction instruction = instructions.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
if (instructionMap.containsKey(instruction)) {
nodeMap.put(operandGraphNode, instructionMap.get(instruction));
continue;
}
final CCodeNode codeNode = dfView.getContent().createCodeNode(null, Lists.newArrayList(instruction));
codeNode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
nodeMap.put(operandGraphNode, codeNode);
instructionMap.put(instruction, codeNode);
}
for (final OperandGraphEdge edge : operandGraph.getEdges()) {
final INaviCodeNode source = nodeMap.get(edge.getSource());
final INaviCodeNode target = nodeMap.get(edge.getTarget());
if (source.equals(target)) {
continue;
}
dfView.getContent().createEdge(source, target, EdgeType.JUMP_UNCONDITIONAL);
}
return dfView;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CUnInliner method getInlinedNodes.
/**
* Determines inlining information starting with a given node.
* TODO(thomasdullien): This code is pretty thoroughly broken for any form of
* nested inlining and needs to be rewritten.
*
* @param node The start node.
*
* @return Information about the inlining boundaries.
*/
public static CInlinedNodes getInlinedNodes(final INaviCodeNode node) {
Preconditions.checkNotNull(node, "IE02750: node argument can not be null");
// Performs a recursive backward search upward in the graph until it finds
// an 'enter inlined function' edge, then returns it's source node. This
// will usually be "a function layer up" from the function that is about to
// be uninlined. Please note that if, while searching up, it enters a
// different inlined subfunction, this function will return a wrong node.
final INaviCodeNode startNode = searchForSourceNodeOfEnterInlinedEdge(node);
// Performs a recursive forward search downward in the graph until it finds
// a 'leave inlined function' edge whose source node is in the same function
// as 'node'. Returns the target of this edge. Please note that if, while
// searching down a second nested inlined version of the current function is
// found, this code will return the wrong node.
final INaviCodeNode endNode = getEndNode(node);
if (startNode == null || endNode == null) {
return null;
}
// to simply carry on for now until the above functions can be fixed.
if (hasDifferentParentFunctions(startNode, endNode)) {
NaviLogger.info("Uninlining yielded almost certainly incorrect results.");
}
final Set<INaviViewNode> preds = GraphAlgorithms.getPredecessorsUpToNode(endNode, startNode);
final Set<INaviViewNode> succs = GraphAlgorithms.getSuccessorsDownToNode(startNode, endNode);
preds.retainAll(succs);
return new CInlinedNodes(startNode, endNode, ImmutableList.copyOf(preds));
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CViewInserter method insertCodeNode.
/**
* Clones a source node and inserts the cloned node into the target view.
*
* @param target The target view where the node is inserted.
* @param node Node from the source view that is cloned.
*
* @return The cloned code node.
*/
private static INaviCodeNode insertCodeNode(final INaviView target, final INaviCodeNode node) {
// TODO: cloning the node is a bad solution since this just fixes the symptoms: instructions are
// closed two times
final INaviCodeNode sourceNode = (INaviCodeNode) node.cloneNode();
final Iterable<INaviInstruction> instructions = sourceNode.getInstructions();
final ArrayList<INaviInstruction> instructionList = Lists.newArrayList(instructions);
CCodeNode codeNode;
try {
codeNode = target.getContent().createCodeNode(sourceNode.getParentFunction(), instructionList);
} catch (final MaybeNullException e) {
codeNode = target.getContent().createCodeNode(null, instructionList);
}
if (sourceNode.getComments().getGlobalCodeNodeComment() != null) {
codeNode.getComments().initializeGlobalCodeNodeComment(sourceNode.getComments().getGlobalCodeNodeComment());
}
if (sourceNode.getComments().getLocalCodeNodeComment() != null) {
codeNode.getComments().initializeLocalCodeNodeComment(sourceNode.getComments().getLocalCodeNodeComment());
}
final Iterable<INaviInstruction> newInstructions = codeNode.getInstructions();
for (int i = 0; i < Iterables.size(instructions); i++) {
codeNode.getComments().initializeLocalInstructionComment(Iterables.get(newInstructions, i), sourceNode.getComments().getLocalInstructionComment(Iterables.get(instructions, i)));
}
return codeNode;
}
Aggregations