Search in sources :

Example 1 with CBlockNode

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

use of com.google.security.zynamics.binnavi.disassembly.CBlockNode 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 3 with CBlockNode

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

the class FunctionTest method testReil.

@Test
public void testReil() throws CouldntLoadDataException, 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);
    @SuppressWarnings("unused") 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> instructions1 = new ArrayList<INaviInstruction>();
    instructions1.add(new MockInstruction(1234));
    final List<INaviInstruction> instructions2 = new ArrayList<INaviInstruction>();
    instructions2.add(new MockInstruction(1235));
    new CBlockNode(new CBasicBlock(1, "", instructions1));
    new CBlockNode(new CBasicBlock(1, "", instructions2));
    final Function function = new Function(ModuleFactory.get(), m_internalFunction);
    function.load();
    assertNotNull(function.getReilCode());
}
Also used : CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) 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) 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) Test(org.junit.Test)

Example 4 with CBlockNode

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

the class FunctionTest method testLoad.

@Test
public void testLoad() throws CouldntLoadDataException {
    final MockFunctionListener listener = new MockFunctionListener();
    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);
    @SuppressWarnings("unused") 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> instructions1 = new ArrayList<INaviInstruction>();
    instructions1.add(new MockInstruction(1234));
    final List<INaviInstruction> instructions2 = new ArrayList<INaviInstruction>();
    instructions2.add(new MockInstruction(1235));
    new CBlockNode(new CBasicBlock(1, "", instructions1));
    new CBlockNode(new CBasicBlock(1, "", instructions2));
    final Function function = new Function(ModuleFactory.get(), m_internalFunction);
    function.addListener(listener);
    function.load();
    assertEquals("loadedFunction;", listener.events);
    assertEquals(4, function.getEdgeCount());
    assertEquals(5, function.getBlockCount());
    assertEquals(1, function.getGraph().getNodes().get(0).getChildren().size());
    function.close();
    function.removeListener(listener);
    assertEquals("loadedFunction;closedFunction;", listener.events);
    assertFalse(function.isLoaded());
}
Also used : CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) 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) 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) Test(org.junit.Test)

Aggregations

MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)4 CBasicBlock (com.google.security.zynamics.binnavi.disassembly.CBasicBlock)4 CBlockNode (com.google.security.zynamics.binnavi.disassembly.CBlockNode)4 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)4 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)4 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)4 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)4 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)4 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Test (org.junit.Test)4 IBlockNode (com.google.security.zynamics.binnavi.disassembly.IBlockNode)2 INaviBasicBlock (com.google.security.zynamics.binnavi.disassembly.INaviBasicBlock)2 CFunctionEdge (com.google.security.zynamics.binnavi.disassembly.CFunctionEdge)1 IBlockEdge (com.google.security.zynamics.binnavi.disassembly.IBlockEdge)1