Search in sources :

Example 1 with IBlockNode

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

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

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

the class PostgreSQLProviderTest method testInstructionFunctionsAddReference1.

@Test
public void testInstructionFunctionsAddReference1() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    final INaviModule module = getProvider().loadModules().get(1);
    module.load();
    final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(1800);
    function.load();
    final IBlockNode basicBlock = function.getBasicBlocks().get(0);
    final INaviInstruction instruction = Iterables.get(basicBlock.getInstructions(), 1);
    final COperandTree tree = instruction.getOperands().get(0);
    final INaviOperandTreeNode node = tree.getRootNode();
    final IAddress address = instruction.getAddress();
    final ReferenceType type = ReferenceType.DATA;
    final int references = node.getReferences().size();
    PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, type);
    final INaviModule module2 = getProvider().loadModules().get(1);
    module2.load();
    final INaviFunction function2 = module2.getContent().getFunctionContainer().getFunctions().get(1800);
    function2.load();
    final IBlockNode basicBlock2 = function2.getBasicBlocks().get(0);
    final INaviInstruction instruction2 = Iterables.get(basicBlock2.getInstructions(), 1);
    final COperandTree tree2 = instruction2.getOperands().get(0);
    final INaviOperandTreeNode node2 = tree2.getRootNode();
    assertEquals(references + 1, node2.getReferences().size());
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) IBlockNode(com.google.security.zynamics.binnavi.disassembly.IBlockNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) ReferenceType(com.google.security.zynamics.zylib.disassembly.ReferenceType) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 4 with IBlockNode

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

the class PostgreSQLProviderTest method testInstructionFunctionsAddReference6.

@Test(expected = CouldntSaveDataException.class)
public void testInstructionFunctionsAddReference6() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    final INaviModule module = getProvider().loadModules().get(1);
    module.load();
    final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(1800);
    function.load();
    final IBlockNode basicBlock = function.getBasicBlocks().get(0);
    final INaviInstruction instruction = Iterables.get(basicBlock.getInstructions(), 1);
    final COperandTree tree = instruction.getOperands().get(0);
    final INaviOperandTreeNode node = tree.getRootNode();
    final IAddress address = instruction.getAddress();
    final ReferenceType type = ReferenceType.DATA;
    PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, type);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) IBlockNode(com.google.security.zynamics.binnavi.disassembly.IBlockNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) ReferenceType(com.google.security.zynamics.zylib.disassembly.ReferenceType) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 5 with IBlockNode

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

the class Function method convertData.

/**
 * Converts internal function data to API function data.
 */
private void convertData() {
    final DirectedGraph<IBlockNode, IBlockEdge> graph = m_function.getGraph();
    final List<BasicBlock> blocks = new ArrayList<BasicBlock>();
    final List<BlockEdge> edges = new ArrayList<BlockEdge>();
    final HashMap<IBlockNode, BasicBlock> blockMap = new HashMap<IBlockNode, BasicBlock>();
    for (final IBlockNode block : graph.getNodes()) {
        final BasicBlock newBlock = new BasicBlock(block, this);
        blockMap.put(block, newBlock);
        blocks.add(newBlock);
    }
    for (final IBlockEdge edge : graph.getEdges()) {
        final BasicBlock source = blockMap.get(edge.getSource());
        final BasicBlock target = blockMap.get(edge.getTarget());
        edges.add(new BlockEdge(edge, source, target));
    }
    m_graph = new FlowGraph(blocks, edges);
}
Also used : IBlockEdge(com.google.security.zynamics.binnavi.disassembly.IBlockEdge) HashMap(java.util.HashMap) IBlockNode(com.google.security.zynamics.binnavi.disassembly.IBlockNode) ArrayList(java.util.ArrayList) IBlockEdge(com.google.security.zynamics.binnavi.disassembly.IBlockEdge)

Aggregations

IBlockNode (com.google.security.zynamics.binnavi.disassembly.IBlockNode)10 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 Test (org.junit.Test)9 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)7 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)7 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)5 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)5 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)5 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)4 ReferenceType (com.google.security.zynamics.zylib.disassembly.ReferenceType)3 ArrayList (java.util.ArrayList)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)2 CBasicBlock (com.google.security.zynamics.binnavi.disassembly.CBasicBlock)2 CBlockNode (com.google.security.zynamics.binnavi.disassembly.CBlockNode)2 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)2 IBlockEdge (com.google.security.zynamics.binnavi.disassembly.IBlockEdge)2 INaviBasicBlock (com.google.security.zynamics.binnavi.disassembly.INaviBasicBlock)2 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)2 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)2