Search in sources :

Example 6 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class CallgraphTest method testConstructor.

@Test
public void testConstructor() {
    final List<FunctionBlock> nodes = new ArrayList<FunctionBlock>();
    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);
    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 FunctionBlock b1 = new FunctionBlock(new Function(ModuleFactory.get(), parentFunction));
    final FunctionBlock b2 = new FunctionBlock(new Function(ModuleFactory.get(), parentFunction));
    nodes.add(b1);
    nodes.add(b2);
    final List<FunctionEdge> edges = new ArrayList<FunctionEdge>();
    final FunctionEdge e1 = new FunctionEdge(b1, b2);
    edges.add(e1);
    final Callgraph cg = new Callgraph(nodes, edges);
    assertEquals(2, cg.getNodes().size());
    assertEquals(b1, cg.getNodes().get(0));
    assertEquals(b2, cg.getNodes().get(1));
    assertEquals(1, cg.getEdges().size());
    assertEquals(e1, cg.getEdges().get(0));
    assertEquals("Callgraph [2 function nodes, 1 edges]", cg.toString());
}
Also used : 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) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 7 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView 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));
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) ViewContainer(com.google.security.zynamics.binnavi.API.disassembly.ViewContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Function(com.google.security.zynamics.binnavi.API.disassembly.Function) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) View(com.google.security.zynamics.binnavi.API.disassembly.View) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 8 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class FunctionNodeTest method testConstructor.

@Test
public void testConstructor() {
    final Database database = new Database(new MockDatabase());
    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 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);
    final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager);
    final MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    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 CFunctionNode internalFunctionNode = new CFunctionNode(0, internalFunction, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), provider);
    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(module, parentFunction);
    final FunctionNode node = new FunctionNode(view, internalFunctionNode, function, viewTagManager);
    assertEquals(function, node.getFunction());
    assertEquals("Function Node ['Mock Function']", node.toString());
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) 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) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) 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) Test(org.junit.Test)

Example 9 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView in project binnavi by google.

the class GroupNodeTest method testSetCollapsed.

@Test
public void testSetCollapsed() {
    final Database database = new Database(new MockDatabase());
    final MockModule mockModule = new MockModule();
    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 MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, new MockSqlProvider());
    final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
    final MockGroupNodeListener listener = new MockGroupNodeListener();
    node.addListener(listener);
    node.setCollapsed(true);
    assertEquals("changedState;", listener.events);
    assertTrue(node.isCollapsed());
    node.removeListener(listener);
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) 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) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 10 with MockView

use of com.google.security.zynamics.binnavi.disassembly.MockView 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);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) 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) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Aggregations

MockView (com.google.security.zynamics.binnavi.disassembly.MockView)38 Test (org.junit.Test)32 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)27 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)25 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)25 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)24 Date (java.util.Date)21 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)19 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)14 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)13 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)13 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)11 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 ArrayList (java.util.ArrayList)9 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)8 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)7 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)6 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)6 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)6