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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations