use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CUnInliner method unInline.
/**
* Uninlines the inlined function a given node belongs to.
*
* @param view The view where the uninline operation takes place.
* @param node The start node.
*
* @return True, if the operation was successful. False, if it was not.
*/
public static boolean unInline(final INaviView view, final INaviCodeNode node) {
try {
final CInlinedNodes inlinedNodes = getInlinedNodes(node);
if (inlinedNodes == null) {
return false;
}
final List<INaviInstruction> instructions = Lists.newArrayList(inlinedNodes.getStartNode().getInstructions());
final boolean mergeBlocks = inlinedNodes.getEndNode().getIncomingEdges().size() == 1;
if (mergeBlocks) {
instructions.addAll(Lists.newArrayList(inlinedNodes.getEndNode().getInstructions()));
}
final CCodeNode combinedNode = view.getContent().createCodeNode(getParentFunction(inlinedNodes.getStartNode()), instructions);
combinedNode.setColor(inlinedNodes.getStartNode().getColor());
combinedNode.setBorderColor(inlinedNodes.getStartNode().getBorderColor());
removeTextNodes(view, inlinedNodes.getInlinedNodes());
view.getContent().deleteNodes(inlinedNodes.getInlinedNodes());
for (final INaviEdge incomingEdge : inlinedNodes.getStartNode().getIncomingEdges()) {
view.getContent().createEdge(incomingEdge.getSource(), combinedNode, incomingEdge.getType());
}
if (mergeBlocks) {
for (final INaviEdge outgoingEdge : inlinedNodes.getEndNode().getOutgoingEdges()) {
view.getContent().createEdge(combinedNode, outgoingEdge.getTarget(), outgoingEdge.getType());
}
} else {
view.getContent().createEdge(combinedNode, inlinedNodes.getEndNode(), EdgeType.JUMP_UNCONDITIONAL);
}
view.getContent().deleteNode(inlinedNodes.getStartNode());
if (mergeBlocks) {
view.getContent().deleteNode(inlinedNodes.getEndNode());
}
return true;
} catch (final IllegalStateException exception) {
CUtilityFunctions.logException(exception);
return false;
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CCodeNodeParser method parse.
/**
* Takes the information from the components passed into the constructor and creates a list of
* nodes from that information.
*
* @return The list of nodes created by the parser.
*
* @throws ParserException Thrown if the instruction data could not be loaded.
* @throws CPartialLoadException Thrown if not all necessary modules are loaded.
*/
public List<CCodeNode> parse() throws ParserException, CPartialLoadException {
// it to point to the proper data.
if (!dataProvider.next()) {
return new ArrayList<CCodeNode>();
}
// Generate the nodes from the raw data.
while (true) {
if (dataProvider.isAfterLast()) {
if (currentNode != null) {
nodes.add(currentNode);
}
break;
}
nodes.add(extractNode(dataProvider));
}
final HashSet<Integer> allComments = Sets.newHashSet();
allComments.addAll(localCommentIdToCodeNode.keySet());
allComments.addAll(globalCommentIdToCodeNode.keySet());
allComments.addAll(globalCommentIdToInstruction.keySet());
allComments.addAll(localCommentIdToInstruction.keySet());
try {
final HashMap<Integer, ArrayList<IComment>> commentIdToComments = sqlProvider.loadMultipleCommentsById(allComments);
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
if (localCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
localCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeLocalCodeNodeComment(commentIdToComment.getValue());
}
if (globalCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
globalCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeGlobalCodeNodeComment(commentIdToComment.getValue());
}
if (localCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
final Pair<INaviInstruction, INaviCodeNode> instructionToCodeNode = localCommentIdToInstruction.get(commentIdToComment.getKey());
instructionToCodeNode.second().getComments().initializeLocalInstructionComment(instructionToCodeNode.first(), commentIdToComment.getValue());
}
if (globalCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
globalCommentIdToInstruction.get(commentIdToComment.getKey()).initializeGlobalComment(commentIdToComment.getValue());
}
}
} catch (final CouldntLoadDataException exception) {
throw new CPartialLoadException("Error: Comments could not be loaded.", null);
}
return nodes;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CCodeNodeParser method addInstruction.
/**
* Adds an instruction to a code node.
*
* @param node The code node where the instruction is added.
* @param line The raw instruction data to add.
*/
private void addInstruction(final CCodeNode node, final InstructionLine line) {
final CInstruction instruction = InstructionConverter.createInstruction(line, sqlProvider);
InstructionCache.get(sqlProvider).addInstruction(instruction);
localCommentIdToInstruction.put(line.getLocalInstructionCommentId(), new Pair<INaviInstruction, INaviCodeNode>(instruction, node));
globalCommentIdToInstruction.put(line.getGlobalInstructionComment(), instruction);
localCommentIdToCodeNode.put(line.getLocalNodeCommentId(), node);
globalCommentIdToCodeNode.put(line.getGlobalNodeCommentId(), node);
node.addInstruction(instruction, null);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class View method createNode.
// ! Clones an existing node.
/**
* Creates a new view node by cloning an existing view node.
*
* @param node The node to clone.
*
* @return The cloned node.
*/
public ViewNode createNode(final ViewNode node) {
Preconditions.checkNotNull(node, "Error: Node argument can not be null");
if (node instanceof CodeNode) {
final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
for (final Instruction instruction : ((CodeNode) node).getInstructions()) {
Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
instructionsList.add(instruction.getNative());
}
CCodeNode newNode;
try {
newNode = naviView.getContent().createCodeNode(((INaviCodeNode) node.getNative()).getParentFunction(), instructionsList);
} catch (final MaybeNullException e) {
newNode = naviView.getContent().createCodeNode(null, instructionsList);
}
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof FunctionNode) {
final CFunctionNode newNode = naviView.getContent().createFunctionNode(((INaviFunctionNode) node.getNative()).getFunction());
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof TextNode) {
final CTextNode newNode = naviView.getContent().createTextNode(((TextNode) node).getComments());
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof GroupNode) {
throw new IllegalStateException("Group nodes can not be cloned");
} else {
throw new IllegalStateException("Error: Unknown node type");
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CStepEndHelper method getEndAddresses.
/**
* Returns the addresses of all final instructions of a graph.
*
* @param graph The graph whose final addresses are returned.
*
* @return The final addresses of the graph.
*/
public static Set<BreakpointAddress> getEndAddresses(final ZyGraph graph) {
final Set<BreakpointAddress> instructions = new HashSet<BreakpointAddress>();
graph.iterate(new INodeCallback<NaviNode>() {
@Override
public IterationMode next(final NaviNode node) {
if ((node.getRawNode() instanceof INaviCodeNode) && node.getChildren().isEmpty()) {
final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
final INaviInstruction lastInstruction = Iterables.getLast(cnode.getInstructions());
instructions.add(new BreakpointAddress(lastInstruction.getModule(), new UnrelocatedAddress(lastInstruction.getAddress())));
}
return IterationMode.CONTINUE;
}
});
return instructions;
}
Aggregations