Search in sources :

Example 76 with MockSqlProvider

use of com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider in project binnavi by google.

the class ViewGraphTest method testConstructor.

@Test
public void testConstructor() throws CouldntLoadDataException, LoadCancelledException {
    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);
    final View view = new View(module, internalView, tagManager, viewTagManager);
    final List<ViewNode> nodes = Lists.newArrayList((ViewNode) new TextNode(view, new MockTextNode(), tagManager));
    final List<ViewEdge> edges = Lists.newArrayList(new ViewEdge(new MockEdge(1, provider), nodes.get(0), nodes.get(0)));
    final ViewGraph graph = new ViewGraph(nodes, edges);
    assertEquals(1, graph.getNodes().size());
    assertEquals(nodes.get(0), graph.getNodes().get(0));
    assertEquals(1, graph.getEdges().size());
    assertEquals(edges.get(0), graph.getEdges().get(0));
    assertEquals("View Graph [1 nodes, 1 edges]", graph.toString());
}
Also used : MockEdge(com.google.security.zynamics.binnavi.disassembly.MockEdge) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Date(java.util.Date) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 77 with MockSqlProvider

use of com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider in project binnavi by google.

the class ViewNodeTest method setUp.

@Before
public void setUp() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final MockSqlProvider provider = new MockSqlProvider();
    final Database database = new Database(new MockDatabase());
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final CTagManager mockTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Root", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider);
    m_nodeTagManager = new TagManager(mockTagManager);
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    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, provider);
    final Function function = new Function(ModuleFactory.get(), parentFunction);
    final Module module = new Module(database, internalModule, m_nodeTagManager, viewTagManager) {

        @Override
        public Function getFunction(final INaviFunction internalFunction) {
            return function;
        }

        @Override
        public boolean isLoaded() {
            return true;
        }
    };
    final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "", "", "", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final ITreeNode<CTag> tag = mockTagManager.addTag(mockTagManager.getRootTag(), "Initial Tag");
    m_initialTag = m_nodeTagManager.getRootTags().get(0);
    final CView internalView = internalModule.getContent().getViewContainer().createView("", "");
    final CFunctionNode node = internalView.getContent().createFunctionNode(internalFunction);
    node.setColor(Color.MAGENTA);
    node.setX(10);
    node.setY(20);
    node.tagNode(tag.getObject());
    m_view = module.getViews().get(2);
    m_node = (FunctionNode) m_view.getGraph().getNodes().get(0);
    final CFunctionNode node2 = internalView.getContent().createFunctionNode(internalFunction);
    internalView.getContent().createEdge(node, node2, EdgeType.INTER_MODULE);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 78 with MockSqlProvider

use of com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider in project binnavi by google.

the class FunctionNodeTest method testSetComment.

@Test
public void testSetComment() throws CouldntLoadDataException, CouldntLoadDataException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, LoadCancelledException {
    final MockSqlProvider provider = new MockSqlProvider();
    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 CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final CView internalView = internalModule.getContent().getViewContainer().createView("", "");
    @SuppressWarnings("unused") final CFunctionNode internalFunctionNode = internalView.getContent().createFunctionNode(internalFunction);
    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 Function function = new Function(ModuleFactory.get(), internalFunction);
    final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager) {

        @Override
        public Function getFunction(final INaviFunction internalFunction) {
            return function;
        }

        @Override
        public boolean isLoaded() {
            return true;
        }
    };
    module.load();
    final View view = module.getViews().get(2);
    final FunctionNode node = (FunctionNode) view.getGraph().getNodes().get(0);
    final MockFunctionNodeListener listener = new MockFunctionNodeListener();
    node.addListener(listener);
    final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Fark"));
    node.initializeComment(comment);
    assertEquals("initializedComment;", listener.events);
    assertEquals(comment, node.getComment());
    node.removeListener(listener);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Example 79 with MockSqlProvider

use of com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider in project binnavi by google.

the class FunctionTest method testReil.

@Test
public void testReil() throws CouldntLoadDataException, InternalTranslationException {
    final MockSqlProvider provider = new MockSqlProvider();
    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);
    @SuppressWarnings("unused") 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, provider);
    final List<INaviInstruction> instructions1 = new ArrayList<INaviInstruction>();
    instructions1.add(new MockInstruction(1234));
    final List<INaviInstruction> instructions2 = new ArrayList<INaviInstruction>();
    instructions2.add(new MockInstruction(1235));
    new CBlockNode(new CBasicBlock(1, "", instructions1));
    new CBlockNode(new CBasicBlock(1, "", instructions2));
    final Function function = new Function(ModuleFactory.get(), m_internalFunction);
    function.load();
    assertNotNull(function.getReilCode());
}
Also used : CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CBasicBlock(com.google.security.zynamics.binnavi.disassembly.CBasicBlock) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 80 with MockSqlProvider

use of com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider in project binnavi by google.

the class FunctionTest method testLoad.

@Test
public void testLoad() throws CouldntLoadDataException {
    final MockFunctionListener listener = new MockFunctionListener();
    final MockSqlProvider provider = new MockSqlProvider();
    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);
    @SuppressWarnings("unused") 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, provider);
    final List<INaviInstruction> instructions1 = new ArrayList<INaviInstruction>();
    instructions1.add(new MockInstruction(1234));
    final List<INaviInstruction> instructions2 = new ArrayList<INaviInstruction>();
    instructions2.add(new MockInstruction(1235));
    new CBlockNode(new CBasicBlock(1, "", instructions1));
    new CBlockNode(new CBasicBlock(1, "", instructions2));
    final Function function = new Function(ModuleFactory.get(), m_internalFunction);
    function.addListener(listener);
    function.load();
    assertEquals("loadedFunction;", listener.events);
    assertEquals(4, function.getEdgeCount());
    assertEquals(5, function.getBlockCount());
    assertEquals(1, function.getGraph().getNodes().get(0).getChildren().size());
    function.close();
    function.removeListener(listener);
    assertEquals("loadedFunction;closedFunction;", listener.events);
    assertFalse(function.isLoaded());
}
Also used : CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CBasicBlock(com.google.security.zynamics.binnavi.disassembly.CBasicBlock) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Aggregations

MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)111 Test (org.junit.Test)82 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)55 Date (java.util.Date)47 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)44 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)42 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)32 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)29 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)25 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)24 Before (org.junit.Before)23 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)17 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)17 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)14 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)13 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)13 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)12 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)12 Tree (com.google.security.zynamics.zylib.types.trees.Tree)12 ArrayList (java.util.ArrayList)12