use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CCodeNodeParser method extractNode.
/**
* Builds individual nodes from the given dataset.
*
* @param dataset The dataset that provides information about nodes and instructions.
* @return The node generated by that iteration.
*
* @throws ParserException Thrown if the node data could not be read.
* @throws CPartialLoadException Thrown if not all required modules are loaded.
*/
private CCodeNode extractNode(final ICodeNodeProvider dataset) throws ParserException, CPartialLoadException {
// Create the first node if necessary.
if (currentNode == null) {
currentNode = createCurrentNode(dataset);
}
final CCodeNode nodeInProcess = currentNode;
// We have to get all instructions that belong to the node.
while ((currentLine = extractLine(dataset)) != null) {
if (currentLine.getBasicBlock() == currentNode.getId()) {
// The instruction belongs to the current block => just add it.
addInstruction(currentNode, currentLine);
} else {
// We found an instruction that belongs to the next block
// => Create a new block and add the instruction there.
currentNode = new CCodeNode(currentLine.getBasicBlock(), currentLine.getX(), currentLine.getY(), currentLine.getWidth(), currentLine.getHeight(), currentLine.getColor(), currentLine.getBorderColor(), currentLine.isSelected(), currentLine.isVisible(), null, currentLine.getParentFunction(), new HashSet<CTag>(), sqlProvider);
addInstruction(currentNode, currentLine);
return nodeInProcess;
}
}
// We have reached the end of the data set.
currentNode = null;
return nodeInProcess;
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode 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.CCodeNode in project binnavi by google.
the class CViewContent method createCodeNode.
@Override
public CCodeNode createCodeNode(final INaviFunction parentFunction, final List<? extends INaviInstruction> instructions) {
Preconditions.checkNotNull(instructions, "IE00286: Instructions argument can not be null");
if ((parentFunction != null) && !parentFunction.inSameDatabase(provider)) {
throw new IllegalArgumentException("IE00287: Parent function and view are not in the same database");
}
for (final INaviInstruction instruction : instructions) {
Preconditions.checkNotNull(instruction, "IE00288: Instruction list contains a null-instruction");
Preconditions.checkArgument(instruction.inSameDatabase(provider), "IE00289: Instruction and view are not in the same database");
}
final CCodeNode codeNode = new CCodeNode(-1, 0, 0, 0, 0, Color.WHITE, Color.BLACK, false, true, null, parentFunction, new HashSet<CTag>(), provider);
for (final INaviInstruction instruction : instructions) {
codeNode.addInstruction(instruction, null);
}
addNode(codeNode);
updateGraphType(codeNode);
codeNode.addListener(m_internalNodeListener);
m_reilFunction = null;
return codeNode;
}
Aggregations