use of com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer in project binnavi by google.
the class PluginInterface method showInLastWindow.
/**
* Shows a view in the last window.
*
* @param view The view to show.
*
* @return The view2d object that is shown.
*/
public View2D showInLastWindow(final View view) {
Preconditions.checkNotNull(view, "Error: View argument can not be null");
final ViewContainer container = view.getContainer();
if (container instanceof Module) {
final Module module = (Module) container;
return show(CWindowManager.instance().getLastWindow(), view, new CModuleContainer(container.getDatabase().getNative(), module.getNative()));
} else {
final Project project = (Project) container;
return show(CWindowManager.instance().getLastWindow(), view, new CProjectContainer(container.getDatabase().getNative(), project.getNative()));
}
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer in project binnavi by google.
the class CViewOpener method showForwardedFunction.
/**
* Shows a forwarded function in a graph window.
*
* @param parent Parent window that is used as the parent of all dialogs.
* @param container View container that provides the context in which a view is opened.
* @param view The view to show.
* @param function The imported function to show.
* @param window Graph window where the graph is shown. If this value is null, the graph is shown
* in a new window.
*/
private static void showForwardedFunction(final Window parent, final IViewContainer container, final INaviView view, final INaviFunction function, final CGraphWindow window) {
if (container instanceof CModuleContainer) {
CMessageBox.showInformation(parent, "Please open forwarded views from inside a project.");
return;
}
final IDatabase database = container.getDatabase();
final int moduleId = function.getForwardedFunctionModuleId();
final INaviModule forwardedModule = database.getContent().getModule(moduleId);
if (forwardedModule == null) {
final String message = "E00019: " + "Forwarded view can not be loaded (Unknown module)";
final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the module of " + "the forwarding target is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the " + "forwarding target again. Restart BinNavi if the view " + "can still not be opened. Contact the BinNavi support if necessary." });
NaviErrorDialog.show(parent, message, description);
} else if (forwardedModule.isLoaded()) {
final IAddress address = function.getForwardedFunctionAddress();
final INaviFunction forwardedFunction = forwardedModule.getContent().getFunctionContainer().getFunction(address);
if (forwardedFunction == null) {
final String message = "E00020: " + "Forwarded view can not be loaded (Unknown function)";
final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the target function is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the forwarding target " + "again. Restart BinNavi if the view can still not be opened. Contact the " + "BinNavi support if necessary." });
NaviErrorDialog.show(parent, message, description);
} else {
final INaviView forwardedView = forwardedModule.getContent().getViewContainer().getView(forwardedFunction);
if (forwardedView == null) {
final String message = "E00107: " + "Forwarded view can not be loaded (Unknown view)";
final String description = CUtilityFunctions.createDescription("BinNavi could not open the forwarded view because the target view is unknown.", new String[] { "Probably the result of a bug in BinNavi" }, new String[] { "The view can not be opened. Try to update the forwarding target " + "again. Restart BinNavi if the view can still not be opened. Contact the " + "BinNavi support if necessary." });
NaviErrorDialog.show(parent, message, description);
} else {
CGraphOpener.showGraph(container, forwardedView, window, parent);
}
}
} else {
if (CMessageBox.showYesNoQuestion(parent, "The view can not be opened because it is forwarded to an unloaded module.\n\n" + "Do you want to load the forwarded module now?") == JOptionPane.YES_OPTION) {
CModuleLoader.loadModule(parent, forwardedModule);
if (forwardedModule.isLoaded()) {
// Just call this function recursively now that the module is loaded.
showForwardedFunction(parent, container, view, function, window);
}
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer in project binnavi by google.
the class CViewLoader method load.
/**
* Loads a view.
*
* @throws LoadCancelledException Thrown if the user canceled the load operation.
* @throws CPartialLoadException Thrown if not all required modules are loaded.
* @throws CouldntLoadDataException Thrown if the view data could not be loaded from the database.
*/
public void load() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException {
if (!view.isLoaded()) {
view.load();
}
// Convert the data from the raw view into a graph that can be displayed.
final ZyGraph graph = container instanceof CModuleContainer ? CGraphBuilder.buildDnDGraph(view, container.getModules().get(0).getTypeManager()) : CGraphBuilder.buildGraph(view);
CRegisterHotKeys.register(graph);
if (window == null) {
// If the parent window of the graph is null, a new graph window is created.
final CGraphWindow navi = new CGraphWindow();
final CGraphModel model = new CGraphModel(navi, container.getDatabase(), container, graph);
CNodeUpdaterInitializer.addUpdaters(model);
final CGraphPanel panel = new CGraphPanel(model);
navi.addGraph(panel);
CWindowManager.instance().register(navi);
// Part of the workaround you can find in WorkaroundListener in CGraphWindow
navi.setSize(Toolkit.getDefaultToolkit().getScreenSize());
navi.setVisible(true);
GuiHelper.applyWindowFix(navi);
navi.setExtendedState(Frame.MAXIMIZED_BOTH);
workArounds(panel);
graphModel = model;
} else {
final CGraphModel model = new CGraphModel(window, container.getDatabase(), container, graph);
CNodeUpdaterInitializer.addUpdaters(model);
final CGraphPanel panel = new CGraphPanel(model);
// If a parent window is given, the graph is added to this window.
window.addGraph(panel);
workArounds(panel);
window.toFront();
graphModel = model;
}
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer in project binnavi by google.
the class PostgreSQLGroupNodeCommentTests method appendInstructionCommentInGroupNode.
@Test
public void appendInstructionCommentInGroupNode() 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 INSTRUCTION COMMENTS IN GROUP NODE ", " TESTING GROUP NODE COMMENTS ");
final INaviInstruction instruction = view.getContent().getBasicBlocks().get(0).getLastInstruction();
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final String firstCommentString = "TEST INSTRUCTION COMMENT PROPAGATION";
final int firstCommentId = getProvider().appendGlobalInstructionComment(instruction, firstCommentString, user.getUserId());
final IComment firstComment = new CComment(firstCommentId, user, null, firstCommentString);
final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(firstCommentId);
assertNotNull(commentsFromDatabase);
assertEquals(1, commentsFromDatabase.size());
assertTrue(commentsFromDatabase.contains(firstComment));
final INaviInstruction instruction2 = nonNativeView.getBasicBlocks().get(0).getLastInstruction();
assertEquals(1, instruction2.getGlobalComment().size());
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer in project binnavi by google.
the class CModuleNodeTest method testUnloadedClosed.
@Test
public void testUnloadedClosed() throws CouldntLoadDataException, CouldntDeleteException, LoadCancelledException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
final CModuleNode node = new CModuleNode(m_tree, new DefaultMutableTreeNode(), m_database, m_module, new CModuleContainer(m_database, m_module));
assertEquals("Name (55/66)", node.toString());
m_module.load();
assertEquals("Name (1/0)", node.toString());
final CView view = m_module.getContent().getViewContainer().createView("Foo", "Bar");
assertEquals("Name (1/1)", node.toString());
m_module.getContent().getViewContainer().deleteView(view);
assertEquals("Name (1/0)", node.toString());
m_module.close();
node.dispose();
assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")) == null);
assertTrue(((Collection<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_module, "m_listeners"), "m_listeners")).isEmpty());
}
Aggregations