Search in sources :

Example 16 with MockModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.MockModule 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 17 with MockModule

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

the class CCodeNodeParserTest method testSameOperandTwice.

@Test
public void testSameOperandTwice() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    // 00000000: jz eax
    // 00000001: jg eax
    final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
    final MockCodeNodeData instruction1 = new MockCodeNodeData();
    instruction1.nodeId = 0;
    instruction1.expressionId = 0;
    instruction1.expressionType = 5;
    instruction1.operandPosition = 0;
    instruction1.symbol = "eax";
    final MockCodeNodeData instruction2 = new MockCodeNodeData();
    instruction2.address = new CAddress(BigInteger.ONE);
    instruction2.nodeId = 1;
    instruction2.expressionId = 0;
    instruction2.expressionType = 5;
    instruction2.operandPosition = 0;
    instruction2.symbol = "eax";
    cnProvider.data.add(instruction1);
    cnProvider.data.add(instruction2);
    final MockSqlProvider provider = new MockSqlProvider();
    final MockModule module = new MockModule();
    CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
    final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
    final List<CCodeNode> result = p.parse();
    assertEquals(2, result.size());
    assertEquals(1, Iterables.size(result.get(0).getInstructions()));
    assertEquals(1, Iterables.size(result.get(1).getInstructions()));
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockCodeNodeData(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeData) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockCodeNodeProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeProvider) CCodeNodeParser(com.google.security.zynamics.binnavi.Database.NodeParser.CCodeNodeParser) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 18 with MockModule

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

the class CCodeNodeParserTest method testSingleInstruction.

@Test
public void testSingleInstruction() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    // nop
    final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
    cnProvider.data.add(new MockCodeNodeData());
    final MockSqlProvider provider = new MockSqlProvider();
    final MockModule module = new MockModule();
    CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
    final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
    final List<CCodeNode> result = p.parse();
    assertEquals(1, result.size());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockCodeNodeData(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeData) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockCodeNodeProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeProvider) CCodeNodeParser(com.google.security.zynamics.binnavi.Database.NodeParser.CCodeNodeParser) Test(org.junit.Test)

Example 19 with MockModule

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

the class CCodeNodeParserTest method testMultipleOperands.

@Test
public void testMultipleOperands() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    // 00000000: mov eax, ebx
    final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
    final MockCodeNodeData instruction1a = new MockCodeNodeData();
    instruction1a.mnemonic = "mov";
    instruction1a.nodeId = 0;
    instruction1a.expressionId = 0;
    instruction1a.expressionType = 5;
    instruction1a.operandPosition = 0;
    instruction1a.symbol = "eax";
    final MockCodeNodeData instruction1b = new MockCodeNodeData();
    instruction1b.mnemonic = "mov";
    instruction1b.nodeId = 0;
    instruction1b.expressionId = 1;
    instruction1b.expressionType = 5;
    instruction1b.operandPosition = 1;
    instruction1b.symbol = "ebx";
    cnProvider.data.add(instruction1a);
    cnProvider.data.add(instruction1b);
    final MockSqlProvider provider = new MockSqlProvider();
    final MockModule module = new MockModule();
    CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
    final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
    final List<CCodeNode> result = p.parse();
    assertEquals(1, result.size());
    assertEquals(1, Iterables.size(result.get(0).getInstructions()));
    final INaviInstruction instruction = Iterables.getFirst(result.get(0).getInstructions(), null);
    assertEquals("mov", instruction.getMnemonic());
    assertEquals("dword", instruction.getOperands().get(0).getRootNode().getValue());
    assertEquals("eax", instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue());
    assertEquals("dword", instruction.getOperands().get(1).getRootNode().getValue());
    assertEquals("ebx", instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockCodeNodeData(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeData) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockCodeNodeProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeProvider) CCodeNodeParser(com.google.security.zynamics.binnavi.Database.NodeParser.CCodeNodeParser) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 20 with MockModule

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

the class CCodeNodeParserTest method testReference.

@Test
public void testReference() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    // 00000000: jz 123
    final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
    final MockCodeNodeData instruction1 = new MockCodeNodeData();
    instruction1.reference = new CReference(new CAddress(BigInteger.valueOf(123)), ReferenceType.CONDITIONAL_TRUE);
    instruction1.nodeId = 0;
    instruction1.expressionId = 0;
    instruction1.expressionType = 2;
    instruction1.operandPosition = 0;
    instruction1.immediate = "123";
    cnProvider.data.add(instruction1);
    final MockSqlProvider provider = new MockSqlProvider();
    final MockModule module = new MockModule();
    CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
    final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
    final List<CCodeNode> result = p.parse();
    assertEquals(1, result.size());
    assertEquals(1, Iterables.size(result.get(0).getInstructions()));
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockCodeNodeData(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeData) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CReference(com.google.security.zynamics.binnavi.disassembly.CReference) MockCodeNodeProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeProvider) CCodeNodeParser(com.google.security.zynamics.binnavi.Database.NodeParser.CCodeNodeParser) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)98 Test (org.junit.Test)90 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)45 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)32 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)26 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)24 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)14 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)14 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)13 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)13 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)12 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 CCodeBookmarkManager (com.google.security.zynamics.binnavi.models.Bookmarks.code.CCodeBookmarkManager)12 MockAddress (com.google.security.zynamics.zylib.disassembly.MockAddress)12 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)11 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)11 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)10 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)10 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)9