use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class BreakpointHelpersTest method setUp.
@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
final Database apiDatabase = new Database(database);
final SQLProvider mockProvider = new MockSqlProvider();
final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
m_module.load();
m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
m_mockDebugger.connect();
m_debugger = new Debugger(m_mockDebugger);
final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
final INaviView naviView = new MockView(mockProvider);
final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
setM_functionNode(m_view.createFunctionNode(apiFunction));
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class GroupNodeTest method testElements.
@Test
public void testElements() throws CouldntLoadDataException, PartialLoadException {
final Database database = new Database(new MockDatabase());
final SQLProvider mockProvider = new MockSqlProvider();
final CModule mockModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
final INaviView mockView = generator.generate(1, "", "", ViewType.NonNative, GraphType.FLOWGRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
final View view = new View(module, mockView, nodeTagManager, viewTagManager);
view.load();
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, mockProvider);
final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, mockProvider);
final CodeNode codeNode = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
final CodeNode codeNode2 = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
final GroupNode node = view.createGroupNode("", Lists.newArrayList((ViewNode) codeNode2));
final MockGroupNodeListener listener = new MockGroupNodeListener();
final MockViewNodeListener listener2 = new MockViewNodeListener();
node.addListener(listener);
codeNode.addListener(listener2);
node.addNode(codeNode);
assertEquals(2, node.getElements().size());
assertEquals(codeNode, node.getElements().get(1));
assertEquals(node, codeNode.getParentGroup());
assertEquals("addedElement;", listener.events);
assertEquals("changedParentGroup;", listener2.events);
node.removeNode(codeNode);
assertEquals(1, node.getElements().size());
assertEquals(null, codeNode.getParentGroup());
assertEquals("addedElement;removedElement;", listener.events);
assertEquals("changedParentGroup;changedParentGroup;", listener2.events);
node.removeListener(listener);
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class CGraphInliner method inlineFunction.
/**
* Replaces a function node with the basic blocks of a function.
*
* @param parent Parent window that is used to display error messages.
* @param graph Graph where the inlining operation happens.
* @param node The function node that is replaced by the basic blocks of the corresponding
* function.
*/
public static void inlineFunction(final JFrame parent, final ZyGraph graph, final INaviFunctionNode node) {
Preconditions.checkNotNull(parent, "IE01743: Parent argument can not be null");
Preconditions.checkNotNull(graph, "IE01744: Graph argument can not be null");
Preconditions.checkNotNull(node, "IE01745: Node argument can not be null");
final INaviView view = graph.getRawView();
final INaviFunction function = node.getFunction();
try {
if (!function.isLoaded()) {
function.load();
}
CInliningHelper.inlineFunctionNode(view, node);
if (graph.getSettings().getLayoutSettings().getAutomaticLayouting()) {
CGraphLayouter.refreshLayout(parent, graph);
}
} catch (final CouldntLoadDataException e) {
exceptionDialog(parent, function, e);
}
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class CViewInserter method insertView.
/**
* Asks the user for a view and inserts that view into a graph.
*
* @param parent Parent window used to display dialogs.
* @param graph The graph where the view is inserted.
* @param viewContainer The container that provides the views that can be inserted.
*/
public static void insertView(final JFrame parent, final ZyGraph graph, final IViewContainer viewContainer) {
Preconditions.checkNotNull(parent, "IE00008: Parent argument can not be null");
Preconditions.checkNotNull(graph, "IE00009: Graph argument can not be null");
Preconditions.checkNotNull(viewContainer, "IE00010: View container argument can not be null");
final CViewSelectionDialog dlg = new CViewSelectionDialog(parent, viewContainer);
GuiHelper.centerChildToParent(parent, dlg, true);
dlg.setVisible(true);
final INaviView view = dlg.getView();
if (view != null) {
if (!view.isLoaded() && !loadView(parent, viewContainer, view)) {
// View can not be loaded for some reason
return;
}
com.google.security.zynamics.binnavi.disassembly.algorithms.CViewInserter.insertView(view, graph.getRawView());
graph.updateViews();
view.close();
}
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class PostgreSQLViewNotificationParser method informProjectNotification.
/**
* The inform function for notifications from the bn_project_views table. This function is used
* when a project view is created or deleted.
*
* @param projectNotificationContainer The {@link ViewNotificationContainer} to use as data
* source.
* @param provider The {@link SQLProvider} to access the database.
* @throws CouldntLoadDataException if the information could not be loaded from the database.
*/
private void informProjectNotification(final ViewNotificationContainer projectNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
if (projectNotificationContainer.getDatabaseOperation().equals("INSERT")) {
final INaviProject project = projectNotificationContainer.getNotificationProject().get();
if (!project.isLoaded()) {
return;
}
final Integer viewId = projectNotificationContainer.getViewId();
final ImmutableNaviViewConfiguration databaseViewConfiguration = provider.loadFlowGraphInformation(project, viewId);
final CProjectViewGenerator generator = new CProjectViewGenerator(provider, project);
final INaviView view = generator.generate(databaseViewConfiguration);
project.getContent().addView(view);
}
if (projectNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
// updates will not happen as this is only a mapping of id to id.
return;
}
if (projectNotificationContainer.getDatabaseOperation().equals("DELETE")) {
final INaviProject project = projectNotificationContainer.getNotificationProject().get();
if (!project.isLoaded()) {
return;
}
final Integer viewId = projectNotificationContainer.getViewId();
final INaviView view = ViewManager.get(provider).getView(viewId);
project.getContent().deleteViewInternal(view);
}
}
Aggregations