use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class ZyGraphBuilder method convertEdges.
/**
* Converts the edges of a view into Graph2D edges.
*
* @param edges The edges to convert.
* @param graph2D The graph where the edges are inserted.
* @param rawNodeToNodeMap Keeps track of view node => graph node mappings.
* @param adjustColors
*/
private void convertEdges(final Collection<INaviEdge> edges, final Graph2D graph2D, final Map<INaviViewNode, Node> rawNodeToNodeMap, final boolean adjustColors) {
for (final INaviEdge edge : edges) {
// Get the nodes connected by the edge
final NaviNode sourceNode = m_ynodeToNodeMap.get(rawNodeToNodeMap.get(edge.getSource()));
final NaviNode targetNode = m_ynodeToNodeMap.get(rawNodeToNodeMap.get(edge.getTarget()));
final Pair<Edge, NaviEdge> result = ZyEdgeBuilder.convertEdge(edge, sourceNode, targetNode, graph2D, adjustColors);
m_yedgeToEdgeMap.put(result.first(), result.second());
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class ViewGraphHelpersTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, PartialLoadException {
final MockSqlProvider provider = new MockSqlProvider();
final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
final Database database = new Database(new MockDatabase());
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
internalModule.load();
final Module module = new Module(database, internalModule, tagManager, viewTagManager);
final CModuleViewGenerator generator = new CModuleViewGenerator(provider, internalModule);
final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 1, 2, new HashSet<CTag>(), new HashSet<CTag>(), false);
m_view = new View(module, internalView, tagManager, viewTagManager);
m_view.load();
final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
instructions.add(new CInstruction(false, internalModule, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
instructions.add(new CInstruction(false, internalModule, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
instructions.add(new CInstruction(false, internalModule, new CAddress(0x125), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
final INaviCodeNode codeNode = internalView.getContent().createCodeNode(null, instructions);
final List<INaviViewNode> nodes1 = new ArrayList<INaviViewNode>();
nodes1.add(codeNode);
final List<INaviEdge> edges1 = new ArrayList<INaviEdge>();
final CFunction internalFunction = new CFunction(internalModule, new MockView(nodes1, edges1, provider), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
internalFunction.load();
final Function function = new Function(module, internalFunction);
final CFunctionNode functionNode = new CFunctionNode(0, internalFunction, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), provider);
m_codeNode = new CodeNode(m_view, codeNode, tagManager);
m_functionNode = new FunctionNode(m_view, functionNode, function, tagManager);
m_textNode = new TextNode(m_view, new MockTextNode(), tagManager);
final List<ViewNode> nodes = Lists.newArrayList(m_codeNode, m_functionNode, m_textNode);
final List<ViewEdge> edges = Lists.newArrayList(new ViewEdge(new MockEdge(1, provider), nodes.get(0), nodes.get(0)));
m_graph = new ViewGraph(nodes, edges);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class ViewTest method testGraph.
@Test
public void testGraph() {
final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
final List<INaviEdge> edges = new ArrayList<INaviEdge>();
final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
final int viewId = new BigInteger(31, new SecureRandom()).intValue();
final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
@SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
@SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
final MockViewListener listener = new MockViewListener();
final View view = new View(module, internalView, tagManager, m_viewTagManager);
view.addListener(listener);
assertEquals(4, view.getGraph().getNodes().size());
assertEquals(1, view.getGraph().getEdges().size());
internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CSteppingHelper method getSuccessors.
/**
* Determines the addresses of the successor blocks of a node.
*
* @param node Node whose successor addresses are added to the list.
*
* @return The list of addresses of the successor nodes.
*/
public static Set<BreakpointAddress> getSuccessors(final INaviViewNode node) {
final Set<BreakpointAddress> addresses = new HashSet<BreakpointAddress>();
final List<INaviEdge> edges = node.getOutgoingEdges();
for (final INaviEdge edge : edges) {
final BreakpointAddress childAddress = CSteppingHelper.getAddress(edge.getTarget());
if (childAddress != null) {
addresses.add(childAddress);
}
}
return addresses;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CViewPruner method getSources.
/**
* Collects edge information about outgoing edges.
*
* @param edge The edge whose information is collected.
* @param nodeMap Maps between nodes of the old view and nodes of the new view.
* @param visited Already visited edges.
*
* @return The collected edge information.
*/
private static Set<EdgeResult> getSources(final INaviEdge edge, final Map<INaviViewNode, INaviViewNode> nodeMap, final Set<INaviEdge> visited) {
final INaviViewNode source = edge.getSource();
visited.add(edge);
final Set<EdgeResult> sources = new HashSet<EdgeResult>();
if (nodeMap.containsKey(source)) {
sources.add(new EdgeResult(nodeMap.get(source), edge.getType()));
} else {
for (final INaviEdge incomingEdge : source.getIncomingEdges()) {
if (!visited.contains(incomingEdge)) {
sources.addAll(getSources(incomingEdge, nodeMap, visited));
}
}
}
return sources;
}
Aggregations