use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph in project binnavi by google.
the class CGraphInliner method inlineAll.
/**
* Inlines all function calls of a given graph.
*
* @param parent Parent window used for dialogs.
* @param container Contains the functions to be inlined.
* @param graph Graph where the inline operation takes place.
*/
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
final List<INaviViewNode> nodes = mutableGraph.getNodes();
final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
for (final INaviViewNode iNaviViewNode : nodes) {
if (iNaviViewNode instanceof INaviCodeNode) {
instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
}
}
for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
INaviCodeNode updatedNode = null;
for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
if (codeNode.hasInstruction(iNaviInstruction)) {
updatedNode = codeNode;
}
}
if (updatedNode != null) {
inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
} else {
throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
}
}
}
use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph in project binnavi by google.
the class PostgreSQLViewLoader method loadView.
/**
* Loads the graph of a view from the database.
*
* @param provider The SQL provider that provides the connection.
* @param view The view to load.
* @param list A list of all modules that are part of the database.
* @param nodeTagManager Node tag manager of the database.
*
* @return The graph of the view.
*
* @throws CouldntLoadDataException Thrown if the graph of view could not be loaded.
* @throws CPartialLoadException Thrown if the graph could not be loaded because not all required
* modules are loaded.
*/
public static MutableDirectedGraph<INaviViewNode, INaviEdge> loadView(final AbstractSQLProvider provider, final INaviView view, final List<INaviModule> list, final CTagManager nodeTagManager) throws CouldntLoadDataException, CPartialLoadException {
checkArguments(provider, view, list, nodeTagManager);
try {
final List<INaviViewNode> nodes = PostgreSQLNodeLoader.loadNodes(provider, view, list, nodeTagManager);
NodeCache.get(provider).addNodes(nodes);
final List<INaviEdge> edges = PostgreSQLEdgeLoader.loadEdges(provider, view, nodes);
EdgeCache.get(provider).addEdges(edges);
return new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph in project binnavi by google.
the class CViewTest method testConstructor16.
@Test
public void testConstructor16() {
final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(new ArrayList<INaviViewNode>(), new ArrayList<INaviEdge>());
final Set<CTag> tags = new HashSet<CTag>();
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
final CView view = new CView(2, module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
assertEquals(2, view.getConfiguration().getId());
assertEquals("View", view.getName());
assertEquals("Description", view.getConfiguration().getDescription());
assertEquals(ViewType.Native, view.getType());
assertEquals(0, view.getNodeCount());
assertEquals(0, view.getEdgeCount());
try {
new CView(-2, module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final IllegalArgumentException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), (CModule) null, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, null, "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, "Description", null, ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", null, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, null, new Date(12345), graph, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), null, graph, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), new Date(12345), null, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), new Date(12345), graph, null, false, provider);
fail();
} catch (final NullPointerException e) {
}
try {
new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), new Date(12345), graph, tags, false, null);
fail();
} catch (final NullPointerException e) {
}
final CTag tag1 = new CTag(1, "Tag1", "Tag1 Tag1", TagType.VIEW_TAG, provider);
final CTag tag2 = new CTag(2, "Tag2", "Tag2 Tag2", TagType.VIEW_TAG, provider);
final CTag tag3 = new CTag(3, "Tag3", "Tag3 Tag3", TagType.VIEW_TAG, provider);
final CTag tag4 = new CTag(4, "Tag4", "Tag4 Tag4", TagType.VIEW_TAG, provider);
tags.add(tag1);
tags.add(tag2);
tags.add(tag3);
tags.add(tag4);
new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
tags.add(null);
try {
new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final NullPointerException e) {
}
tags.clear();
tags.add(tag1);
tags.add(tag2);
tags.add(tag3);
tags.add(tag4);
final CTag tag5 = new CTag(5, "Tag1", "Tag1 Tag1", TagType.NODE_TAG, provider);
tags.add(tag5);
try {
new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final IllegalArgumentException e) {
}
tags.clear();
final CTag tagWrongDB = new CTag(new BigInteger(31, random).intValue(), "Tag4", "Tag4 Tag4", TagType.VIEW_TAG, new MockSqlProvider());
tags.add(tagWrongDB);
try {
new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
fail();
} catch (final IllegalArgumentException e) {
}
}
use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph 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);
}
Aggregations