Search in sources :

Example 21 with CModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule 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);
}
Also used : CallGraphSettingsConfigItem(com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) Node(y.base.Node) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) CReference(com.google.security.zynamics.binnavi.disassembly.CReference) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) LinkedHashMap(java.util.LinkedHashMap) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) ZyGraph2DView(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) Date(java.util.Date) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) MockDatabaseManager(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabaseManager) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 22 with CModule

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

the class GraphSearcherTest method setUp.

@Before
public void setUp() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException {
    final Graph2D g = new Graph2D();
    m_ynode = g.createNode();
    final MockSqlProvider sql = new MockSqlProvider();
    final CModule module = MockCreator.createModule(sql);
    module.load();
    final CFunction function = MockCreator.createFunction(module, sql);
    final CView m_view = MockCreator.createView(sql, module);
    final CInstruction instruction1 = MockCreator.createInstruction(module, sql);
    final CInstruction instruction2 = MockCreator.createInstruction(module, sql);
    final CInstruction instruction3 = MockCreator.createInstruction(module, sql);
    m_view.load();
    m_codeNode1 = m_view.getContent().createCodeNode(function, Lists.newArrayList(instruction1, instruction2, instruction3));
    m_content = new ZyLabelContent(null);
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Graph2D(y.view.Graph2D) Before(org.junit.Before)

Example 23 with CModule

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

the class CAddressSpaceContentTest method testRemoveModule.

@Test
public void testRemoveModule() throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException, LoadCancelledException {
    final CModule module = MockCreator.createModule(m_sql);
    m_addressSpace.load();
    m_addressSpace.getContent().addListener(m_listener);
    try {
        m_addressSpace.getContent().removeModule(null);
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        m_addressSpace.getContent().removeModule(module);
        fail();
    } catch (final IllegalArgumentException exception) {
    }
    m_addressSpace.getContent().addModule(module);
    m_addressSpace.getContent().removeModule(module);
    // Check the listener events
    assertEquals("addedModule;changedImageBase;removedModule;", m_listener.events);
    // Check the address space
    assertEquals(0, m_addressSpace.getModuleCount());
}
Also used : CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 24 with CModule

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

the class CCodeNodeTest method testMiscFunctions.

@Test
public void testMiscFunctions() throws MaybeNullException, CouldntSaveDataException, CouldntLoadDataException {
    final MockSqlProvider provider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(provider);
    final IUser currentUser = userManager.addUser("TEST USER 1");
    userManager.setCurrentActiveUser(currentUser);
    final CModule internalModule = 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 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 CCodeNode node = new CCodeNode(1, 0, 0, 0, 0, Color.BLACK, Color.BLACK, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "foobar")), parentFunction, new LinkedHashSet<CTag>(), provider);
    final MockInstruction i1 = new MockInstruction(new CAddress(0x123), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i2 = new MockInstruction(new CAddress(0x124), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i3 = new MockInstruction(new CAddress(0x125), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i4 = new MockInstruction(new CAddress(0x126), "nop", new ArrayList<COperandTree>(), m_globalComment);
    final MockInstruction i5 = new MockInstruction(new CAddress(0x127), "nop", new ArrayList<COperandTree>(), null);
    node.addInstruction(i1, Lists.<IComment>newArrayList(new CComment(null, currentUser, null, "Foo\nBar")));
    node.addInstruction(i2, Lists.<IComment>newArrayList(new CComment(null, currentUser, null, "\n")));
    node.addInstruction(i3, null);
    node.addInstruction(i4, null);
    final INaviCodeNodeListener listener = new CNaviCodeNodeListenerAdapter();
    node.addListener(listener);
    node.addInstruction(i5, null);
    assertNotNull(node.cloneNode());
    assertFalse(CCodeNodeHelpers.containsAddress(node, new CAddress(0xFFFFFFFEL)));
    assertEquals(null, node.getComments().getGlobalCodeNodeComment());
    assertEquals(new CAddress(0x123L), node.getAddress());
    assertEquals(0, CCodeNodeHelpers.getInstruction(node, new CAddress(0x123L)));
    assertEquals(-1, CCodeNodeHelpers.getInstruction(node, new CAddress(0x129L)));
    assertEquals(i1, Iterables.getFirst(node.getInstructions(), null));
    assertEquals(5, Iterables.size(node.getInstructions()));
    assertEquals(5, node.instructionCount());
    assertNotNull(node.getParentFunction());
    node.removeInstruction(i5);
    assertEquals(4, node.instructionCount());
    try {
        node.removeInstruction(null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        node.removeInstruction(i5);
        fail();
    } catch (final IllegalArgumentException e) {
    }
    final List<IComment> comments = node.getComments().appendGlobalCodeNodeComment("barfoos");
    assertEquals(comments, node.getComments().getGlobalCodeNodeComment());
    try {
        node.getComments().appendGlobalCodeNodeComment(null);
        fail();
    } catch (final Exception e) {
    }
    node.setInstructionColor(i4, 0, Color.YELLOW);
    try {
        node.setInstructionColor(null, 0, null);
        fail();
    } catch (final Exception e) {
    }
    try {
        node.setInstructionColor(i5, 0, null);
        fail();
    } catch (final Exception e) {
    }
    node.setBorderColor(Color.GRAY);
    assertEquals(Color.GRAY, node.getBorderColor());
    final List<IComment> comments2 = node.getComments().appendLocalCodeNodeComment("barfoos2");
    assertEquals(comments2, node.getComments().getLocalCodeNodeComment());
    final List<IComment> appendedComments = node.getComments().appendLocalInstructionComment(i4, "foo");
    assertEquals(appendedComments, node.getComments().getLocalInstructionComment(i4));
    try {
        node.getComments().appendLocalInstructionComment(i5, " INSTRUCTION i5 COMMENT ");
        fail();
    } catch (final IllegalArgumentException e) {
    }
    node.getComments().appendLocalCodeNodeComment("foo");
    node.toString();
    node.removeListener(listener);
    node.close();
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 25 with CModule

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

the class CModuleNodeTest method setUp.

@Before
public void setUp() throws IllegalArgumentException, SecurityException, FileReadException {
    ConfigManager.instance().read();
    m_database = new MockDatabase(m_provider);
    final CRawModule rawModule = new CRawModule(1, "", 0, false, m_provider);
    m_module = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, m_provider), rawModule, Integer.MAX_VALUE, false, m_provider);
    final CProjectTreeModel model = new CProjectTreeModel(m_tree);
    model.setRoot(new DefaultMutableTreeNode());
    m_tree.setModel(model);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CProjectTreeModel(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.CProjectTreeModel) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CRawModule(com.google.security.zynamics.binnavi.disassembly.CRawModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Before(org.junit.Before)

Aggregations

CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)57 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)47 Date (java.util.Date)46 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)40 Test (org.junit.Test)36 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)23 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)23 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)22 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)19 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)16 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)14 Before (org.junit.Before)14 ArrayList (java.util.ArrayList)12 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)11 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)9 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)8 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)8 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)7 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)7 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)6