use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CVariableHighlighterTest method test1Simple.
@Test
public void test1Simple() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
final ZyGraph graph = ZyGraphFactory.generateTestGraph();
final List<INaviInstruction> mockInstructions = new ArrayList<INaviInstruction>();
final CCodeNode node = graph.getRawView().getBasicBlocks().get(0);
final NaviNode naviNode = graph.getNode(node);
mockInstructions.add(Iterables.get(node.getInstructions(), 0));
final BackEndDebuggerProvider provider = new MockDebuggerProvider();
@SuppressWarnings("unused") final CCodeNodeUpdater updater = new CCodeNodeUpdater(graph, naviNode, node, provider);
assertFalse(naviNode.getRealizer().getNodeContent().getLineContent(0).hasHighlighting(CHighlightLayers.VARIABLE_LAYER));
CVariableHighlighter.highlightInstructions(graph, mockInstructions);
assertTrue(naviNode.getRealizer().getNodeContent().getLineContent(0).hasHighlighting(CHighlightLayers.VARIABLE_LAYER));
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CGraphDebuggerTest method testToggleBreakpoint3.
@Test
public void testToggleBreakpoint3() {
final MockModule module = new MockModule();
module.getConfiguration().setDebugger(m_debugger);
m_debugger.setAddressTranslator(module, m_fileBase, m_imageBase);
final DebugTargetSettings target = new ModuleTargetSettings(module);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
debuggerProvider.addDebugger(m_debugger);
final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
assertEquals(0x124, m_debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, 0).getAddress().getAddress().getAddress().toLong());
assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_debugger.getBreakpointManager().getBreakpointStatus(BreakpointType.REGULAR, 0));
CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CTaggedGraphNodeNodeTest method test1Simple.
@Test
public void test1Simple() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
final ZyGraph graph = ZyGraphFactory.generateTestGraph();
final CCodeNode node = graph.getRawView().getBasicBlocks().get(0);
final NaviNode naviNode = graph.getNode(node);
@SuppressWarnings("unused") final CTaggedGraphNodeNode taggedNode = new CTaggedGraphNodeNode(graph, naviNode);
}
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;
}
}
Aggregations