use of com.google.security.zynamics.binnavi.disassembly.CFunction in project binnavi by google.
the class GraphSearcherTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException {
final Graph2D g = new Graph2D();
m_ynode = g.createNode();
final MockSqlProvider sql = new MockSqlProvider();
final CModule module = MockCreator.createModule(sql);
module.load();
final CFunction function = MockCreator.createFunction(module, sql);
final CView m_view = MockCreator.createView(sql, module);
final CInstruction instruction1 = MockCreator.createInstruction(module, sql);
final CInstruction instruction2 = MockCreator.createInstruction(module, sql);
final CInstruction instruction3 = MockCreator.createInstruction(module, sql);
m_view.load();
m_codeNode1 = m_view.getContent().createCodeNode(function, Lists.newArrayList(instruction1, instruction2, instruction3));
m_content = new ZyLabelContent(null);
}
use of com.google.security.zynamics.binnavi.disassembly.CFunction in project binnavi by google.
the class PostgreSQLFunctionsLoader method parseFunctionInformation.
/**
* This function parses a {@link ResultSet result set} from a database query and generates a
* {@link List} of {@link INaviFunction} from it.
*
* @param resultSet The {@link ResultSet} in which the result from the database query is stored.
* @param provider The {@link SQLProvider} to access the database with.
* @param module The {@link INaviModule} to which the {@link INaviFunction function(s)} are
* associated.
*
* @return A {@link List} of {@link INaviFunction functions} parsed from the {@link ResultSet
* resultSet}.
*
* @throws SQLException if the {@link ResultSet} could not be parsed.
* @throws CouldntLoadDataException if the associated comments could not be loaded from the
* database.
*/
private static List<INaviFunction> parseFunctionInformation(final ResultSet resultSet, final SQLProvider provider, final INaviModule module) throws SQLException, CouldntLoadDataException {
final List<INaviFunction> functions = Lists.newArrayList();
final Map<Integer, INaviFunction> commentIdToFunction = new HashMap<Integer, INaviFunction>();
try {
while (resultSet.next()) {
final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
final String name = resultSet.getString("name");
final String originalName = resultSet.getString("original_name");
Integer globalCommentId = resultSet.getInt("global_comment");
if (resultSet.wasNull()) {
globalCommentId = null;
}
final String description = resultSet.getString("description");
final FunctionType type = FunctionType.valueOf(resultSet.getString("type").toUpperCase());
final String parentModuleName = resultSet.getString("parent_module_name");
final int parentModuleId = resultSet.getInt("parent_module_id");
final IAddress parentModuleFunction = resultSet.wasNull() ? null : PostgreSQLHelpers.loadAddress(resultSet, "parent_module_function");
final Integer nodeCount = resultSet.getInt("bbcount");
final Integer edgeCount = resultSet.getInt("edgeCount");
final Integer indegree = resultSet.getInt("incount");
final Integer outdegree = resultSet.getInt("outcount");
Integer stackFrameId = resultSet.getInt("stack_frame");
if (resultSet.wasNull()) {
stackFrameId = null;
}
Integer prototypeId = resultSet.getInt("prototype");
if (resultSet.wasNull()) {
prototypeId = null;
}
final INaviView view = ViewManager.get(provider).getView(resultSet.getInt("view_id"));
final BaseType stackFrame = stackFrameId == null ? null : module.getTypeManager().getBaseType(stackFrameId);
if (stackFrameId != null) {
module.getTypeManager().setStackFrame(stackFrame);
}
final BaseType prototype = prototypeId == null ? null : module.getTypeManager().getBaseType(prototypeId);
final CFunction function = new CFunction(module, view, address, name, originalName, description, indegree, outdegree, nodeCount, edgeCount, type, parentModuleName, parentModuleId, parentModuleFunction, stackFrame, prototype, provider);
if (globalCommentId != null) {
commentIdToFunction.put(globalCommentId, function);
}
functions.add(function);
}
} finally {
resultSet.close();
}
if (!commentIdToFunction.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunction.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
CommentManager.get(provider).initializeGlobalFunctionComment(commentIdToFunction.get(commentIdToComment.getKey()), commentIdToComment.getValue());
}
}
return functions;
}
use of com.google.security.zynamics.binnavi.disassembly.CFunction 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.CFunction 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.CFunction in project binnavi by google.
the class CallgraphTest method testConstructor.
@Test
public void testConstructor() {
final List<FunctionBlock> nodes = new ArrayList<FunctionBlock>();
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 FunctionBlock b1 = new FunctionBlock(new Function(ModuleFactory.get(), parentFunction));
final FunctionBlock b2 = new FunctionBlock(new Function(ModuleFactory.get(), parentFunction));
nodes.add(b1);
nodes.add(b2);
final List<FunctionEdge> edges = new ArrayList<FunctionEdge>();
final FunctionEdge e1 = new FunctionEdge(b1, b2);
edges.add(e1);
final Callgraph cg = new Callgraph(nodes, edges);
assertEquals(2, cg.getNodes().size());
assertEquals(b1, cg.getNodes().get(0));
assertEquals(b2, cg.getNodes().get(1));
assertEquals(1, cg.getEdges().size());
assertEquals(e1, cg.getEdges().get(0));
assertEquals("Callgraph [2 function nodes, 1 edges]", cg.toString());
}
Aggregations