Search in sources :

Example 1 with MockInstruction

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

the class BlockEdgeTest method testConstructor.

@Test
public void testConstructor() {
    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 List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
    instructions.add(new MockInstruction(0x123));
    final INaviBasicBlock bblock = new CBasicBlock(1, "Hannes", instructions);
    final IBlockNode node = new CBlockNode(bblock);
    final Function pFunction = new Function(ModuleFactory.get(), parentFunction);
    final BasicBlock block1 = new BasicBlock(node, pFunction);
    final BasicBlock block2 = new BasicBlock(node, pFunction);
    final IBlockEdge mockEdge = new CFunctionEdge(node, node, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
    final BlockEdge edge = new BlockEdge(mockEdge, block1, block2);
    assertEquals(block1, edge.getSource());
    assertEquals(block2, edge.getTarget());
    assertEquals(block1, block2.getParents().get(0));
    assertEquals(block2, block1.getChildren().get(0));
    assertEquals(EdgeType.JumpUnconditional, edge.getType());
    assertEquals("Block Edge [123 -> 123]", edge.toString());
}
Also used : CFunctionEdge(com.google.security.zynamics.binnavi.disassembly.CFunctionEdge) IBlockEdge(com.google.security.zynamics.binnavi.disassembly.IBlockEdge) CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) IBlockNode(com.google.security.zynamics.binnavi.disassembly.IBlockNode) ArrayList(java.util.ArrayList) INaviBasicBlock(com.google.security.zynamics.binnavi.disassembly.INaviBasicBlock) CBasicBlock(com.google.security.zynamics.binnavi.disassembly.CBasicBlock) 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) IBlockEdge(com.google.security.zynamics.binnavi.disassembly.IBlockEdge) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) INaviBasicBlock(com.google.security.zynamics.binnavi.disassembly.INaviBasicBlock) Test(org.junit.Test)

Example 2 with MockInstruction

use of com.google.security.zynamics.binnavi.disassembly.MockInstruction 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)

Example 3 with MockInstruction

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

the class BasicBlockTest method testConstructor.

@Test
public void testConstructor() throws 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);
    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 List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
    instructions.add(new MockInstruction(0x123));
    final INaviBasicBlock bblock = new CBasicBlock(1, "Hannes", instructions);
    final IBlockNode node = new CBlockNode(bblock);
    final Function pFunction = new Function(ModuleFactory.get(), internalFunction);
    final BasicBlock block = new BasicBlock(node, pFunction);
    assertEquals(0x123, block.getAddress().toLong());
    assertEquals(pFunction, block.getParentFunction());
    assertEquals("Hannes", block.getComment());
    assertEquals(0x123, block.getInstructions().get(0).getAddress().toLong());
    assertNotNull(block.getReilCode());
    assertTrue(block.getChildren().isEmpty());
    assertTrue(block.getParents().isEmpty());
    assertEquals("123  nop \n", block.toString());
}
Also used : CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) IBlockNode(com.google.security.zynamics.binnavi.disassembly.IBlockNode) ArrayList(java.util.ArrayList) INaviBasicBlock(com.google.security.zynamics.binnavi.disassembly.INaviBasicBlock) CBasicBlock(com.google.security.zynamics.binnavi.disassembly.CBasicBlock) 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) INaviBasicBlock(com.google.security.zynamics.binnavi.disassembly.INaviBasicBlock) Test(org.junit.Test)

Example 4 with MockInstruction

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

the class CViewInserterTest method test.

@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final INaviModule mockModule = new MockModule();
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(mockProvider);
    final IUser user = userManager.addUser(" VIEW INSERTER USER ");
    userManager.setCurrentActiveUser(user);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view.load();
    final MockFunction mockFunction = new MockFunction(mockProvider);
    final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
    final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
    @SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
    final MockInstruction instruction1 = new MockInstruction();
    final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    @SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
    final CTextNode tnode1 = view.getContent().createTextNode(comments);
    @SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
    final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
    gnode1.appendComment("TEST GROUP NODE COMMENT 1");
    final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view2.load();
    CViewInserter.insertView(view, view2);
    final List<INaviViewNode> nodes = view2.getGraph().getNodes();
    assertEquals(view2.getNodeCount(), 6);
    assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
    assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) 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) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 5 with MockInstruction

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

the class CUnInlinerTest method testUninlineSingleBlock.

@Test
public void testUninlineSingleBlock() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction(m_provider);
    final INaviFunction mockFunction2 = new MockFunction(m_provider);
    final MockInstruction mi1 = new MockInstruction(0x123);
    final MockInstruction mi2 = new MockInstruction(0x124);
    final MockInstruction mi3 = new MockInstruction(0x125);
    final CCodeNode upperNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CTextNode textNode = new CTextNode(0, 0, 0, 0, 0, Color.RED, false, true, new HashSet<CTag>(), null, m_provider);
    upperNode.addInstruction(mi1, null);
    inlinedNode.addInstruction(mi2, null);
    lowerNode.addInstruction(mi3, null);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(textNode);
    nodes.add(lowerNode);
    final CNaviViewEdge enteringEdge = new CNaviViewEdge(0, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge leavingEdge = new CNaviViewEdge(0, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge textEdge = new CNaviViewEdge(0, textNode, inlinedNode, EdgeType.TEXTNODE_EDGE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(enteringEdge);
    edges.add(leavingEdge);
    edges.add(textEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(textNode, inlinedNode, textEdge);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(1, view.getNodeCount());
    assertEquals(0, view.getEdgeCount());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(0);
    assertEquals(2, Iterables.size(cnode.getInstructions()));
    assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
    assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Aggregations

MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)16 Test (org.junit.Test)15 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)11 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)8 Date (java.util.Date)8 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)7 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)7 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)7 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)6 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)6 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)6 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)6 ArrayList (java.util.ArrayList)6 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)5 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)5 CBasicBlock (com.google.security.zynamics.binnavi.disassembly.CBasicBlock)4 CBlockNode (com.google.security.zynamics.binnavi.disassembly.CBlockNode)4