use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph in project binnavi by google.
the class CPanelCloser method closeTab.
/**
* Asks the user whether he wants to save a graph before closing a panel.
*
* @param parent The parent window of the panel.
* @param panel The panel to be closed.
*
* @return True, if the panel can be closed. False, if the user wants to keep the panel open.
*/
public static boolean closeTab(final JFrame parent, final IGraphPanel panel) {
Preconditions.checkNotNull(parent, "IE01630: Parent argument can not be null");
Preconditions.checkNotNull(panel, "IE01631: Panel argument can not be null");
final ZyGraph graph = panel.getModel().getGraph();
return graph.getRawView().wasModified() ? closeModifiedGraph(parent, panel) : true;
}
use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph in project binnavi by google.
the class PostgreSQLGroupNodeCommentTests method setupGroupNode.
private INaviGroupNode setupGroupNode() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1004565");
final INaviView view = module.getContent().getViewContainer().getView(function);
view.load();
assertEquals(42, view.getNodeCount());
final INaviViewNode node1 = view.getContent().getBasicBlocks().get(1);
final INaviViewNode node2 = view.getContent().getBasicBlocks().get(2);
view.getContent().createGroupNode(Lists.newArrayList(node1, node2));
final ZyGraph graph = CGraphBuilder.buildGraph(view);
final INaviView nonNativeView = graph.saveAs(new CModuleContainer(getDatabase(), module), " TEST GROUP NODE COMMENTS ", " TESTING GROUP NODE COMMENTS ");
INaviGroupNode savedGroupNode = null;
for (final INaviViewNode node : nonNativeView.getGraph().getNodes()) {
if (node instanceof INaviGroupNode) {
savedGroupNode = (INaviGroupNode) node;
}
}
return savedGroupNode;
}
use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph in project binnavi by google.
the class PostgreSQLTextNodeCommentTests method setupTextNode.
private INaviTextNode setupTextNode() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
final INaviModule module = getProvider().loadModules().get(1);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunction("SetCommState");
final INaviView view = module.getContent().getViewContainer().getView(function);
view.load();
final INaviCodeNode codeNode = view.getContent().getBasicBlocks().get(5);
final INaviTextNode textNode = view.getContent().createTextNode(null);
view.getContent().createEdge(codeNode, textNode, EdgeType.TEXTNODE_EDGE);
final ZyGraph graph = CGraphBuilder.buildGraph(view);
globalView = graph.saveAs(new CModuleContainer(getDatabase(), module), " TEST TEXT NODE COMMENTS ", " TESTING TEXT NODE COMMENTS ");
INaviTextNode savedTextNode = null;
for (final INaviViewNode node : globalView.getGraph().getNodes()) {
if (node instanceof INaviTextNode) {
savedTextNode = (INaviTextNode) node;
}
}
return savedTextNode;
}
use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph in project binnavi by google.
the class ZyGraphFactory method generateTestGraph.
public static ZyGraph generateTestGraph() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final SQLProvider provider = new MockSqlProvider();
final CModule module = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
database.getContent().addModule(module);
final MockDatabaseManager manager = new MockDatabaseManager();
manager.addDatabase(database);
module.load();
final CView m_view = module.getContent().getViewContainer().createView("name", "description");
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode1, childNode1);
final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode2, childNode2);
final COperandTree operand1 = new COperandTree(rootNode1, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final ArrayList<COperandTree> operands1 = Lists.newArrayList(operand1, operand2);
final List<INaviInstruction> instructions1 = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", operands1, null, module));
final INaviCodeNode rawNode1 = m_view.getContent().createCodeNode(null, instructions1);
final ZyLabelContent content = ZyCodeNodeBuilder.buildContent(rawNode1, settings, null);
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(content), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final List<INaviInstruction> instructions2 = Lists.newArrayList((INaviInstruction) new MockInstruction());
final INaviCodeNode rawNode2 = m_view.getContent().createCodeNode(null, instructions2);
final ZyLabelContent content2 = ZyCodeNodeBuilder.buildContent(rawNode2, settings, null);
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(content2), rawNode2));
rawNode2.setColor(Color.RED);
rawNode2.setVisible(false);
final CTag tag = new CTag(0, "Tag", "Description", TagType.NODE_TAG, new MockSqlProvider());
rawNode2.tagNode(tag);
final Node node3 = g2dView.getGraph2D().createNode();
final String mnemonicName = "call";
final List<COperandTree> operandTrees = new ArrayList<COperandTree>();
final int type = ExpressionType.REGISTER.ordinal();
final CReference reference = new CReference(new CAddress(0x123), ReferenceType.CALL_DIRECT);
final List<IReference> referencea = new ArrayList<IReference>();
referencea.add(reference);
final COperandTreeNode root = new COperandTreeNode(0, type, "eax", null, referencea, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operandTree = new COperandTree(root, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
operandTrees.add(0, operandTree);
final List<INaviInstruction> instructions3 = Lists.newArrayList((INaviInstruction) new MockInstruction(mnemonicName, operandTrees, m_globalComment));
final INaviCodeNode rawNode3 = m_view.getContent().createCodeNode(null, instructions3);
final ZyLabelContent content3 = ZyCodeNodeBuilder.buildContent(rawNode3, settings, null);
nodeMap.put(node3, new NaviNode(node3, new ZyNormalNodeRealizer<NaviNode>(content3), rawNode3));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final Edge edge2 = g2dView.getGraph2D().createEdge(node2, node3);
final INaviEdge rawEdge2 = m_view.getContent().createEdge(rawNode2, rawNode3, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge2, new NaviEdge(nodeMap.get(node2), nodeMap.get(node3), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge2));
return new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
}
use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph in project binnavi by google.
the class CSelectionHistoryTest method testUndo.
@Test
public void testUndo() throws FileReadException, LoadCancelledException {
ConfigManager.instance().read();
final ZyGraph graph = CGraphBuilder.buildGraph(new MockView());
final CSelectionHistory history = new CSelectionHistory(graph, 4);
final CSelectionSnapshot snapshot1 = new CSelectionSnapshot(new ArrayList<NaviNode>());
final CSelectionSnapshot snapshot2 = new CSelectionSnapshot(new ArrayList<NaviNode>());
final CSelectionSnapshot snapshot3 = new CSelectionSnapshot(new ArrayList<NaviNode>());
final CSelectionSnapshot snapshot4 = new CSelectionSnapshot(new ArrayList<NaviNode>());
history.addSnapshot(snapshot1);
history.addSnapshot(snapshot2);
history.addSnapshot(snapshot3);
history.addSnapshot(snapshot4);
// First Undo
assertTrue(history.canUndo());
assertTrue(history.canRedo());
assertEquals(snapshot3, history.getUndoSnapshot(true));
// Second Undo
assertTrue(history.canUndo());
assertTrue(history.canRedo());
assertEquals(snapshot2, history.getUndoSnapshot(true));
// Third Undo
assertTrue(history.canUndo());
assertTrue(history.canRedo());
assertEquals(snapshot1, history.getUndoSnapshot(true));
// Fourth Undo (Fail) + First Redo
assertTrue(history.canUndo());
assertTrue(history.canRedo());
assertEquals(snapshot1, history.getUndoSnapshot(true));
assertEquals(snapshot2, history.getUndoSnapshot(false));
assertTrue(history.canUndo());
assertTrue(history.canRedo());
// Second Redo
assertTrue(history.canUndo());
assertTrue(history.canRedo());
assertEquals(snapshot3, history.getUndoSnapshot(false));
// Third Redo
assertTrue(history.canUndo());
assertTrue(history.canRedo());
assertEquals(snapshot4, history.getUndoSnapshot(false));
// Fourth Redo (Fail) + Last Undo
assertTrue(history.canUndo());
assertTrue(history.canRedo());
assertEquals(snapshot4, history.getUndoSnapshot(false));
assertEquals(snapshot3, history.getUndoSnapshot(true));
assertTrue(history.canUndo());
assertTrue(history.canRedo());
}
Aggregations