Search in sources :

Example 1 with CFunctionNode

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

the class CViewContent method createFunctionNode.

@Override
public CFunctionNode createFunctionNode(final INaviFunction function) {
    Preconditions.checkNotNull(function, "IE00294: Function argument can not be null");
    Preconditions.checkArgument(function.inSameDatabase(provider), "IE00295: Function and view are not in the same database");
    final CFunctionNode functionNode = new CFunctionNode(-1, function, 0, 0, 0, 0, CFunctionNodeColorizer.getFunctionColor(function.getType()), false, true, null, new HashSet<CTag>(), provider);
    addNode(functionNode);
    updateGraphType(functionNode);
    functionNode.addListener(m_internalNodeListener);
    return functionNode;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Example 2 with CFunctionNode

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

the class View method createFunctionNode.

// ! Creates a new function node.
/**
 * Creates a function node in the view.
 *
 * @param function The function the function node represents.
 *
 * @return The created function node.
 */
public FunctionNode createFunctionNode(final Function function) {
    Preconditions.checkNotNull(function, "Error: Function argument can't be null");
    Preconditions.checkNotNull(getFunction(function.getNative()), "Error: Function does not belong to this container");
    final CFunctionNode functionNode = naviView.getContent().createFunctionNode(function.getNative());
    return (FunctionNode) cachedNodes.get(functionNode);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)

Example 3 with CFunctionNode

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

the class FunctionNodeTest method testConstructor.

@Test
public void testConstructor() {
    final Database database = new Database(new MockDatabase());
    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 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 Module module = new Module(database, internalModule, nodeTagManager, viewTagManager);
    final MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    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 CFunctionNode internalFunctionNode = new CFunctionNode(0, internalFunction, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), 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 Function function = new Function(module, parentFunction);
    final FunctionNode node = new FunctionNode(view, internalFunctionNode, function, viewTagManager);
    assertEquals(function, node.getFunction());
    assertEquals("Function Node ['Mock Function']", node.toString());
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) 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) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 4 with CFunctionNode

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

the class CGraphDebuggerTest method testToggleBreakpoint2.

@Test
public void testToggleBreakpoint2() {
    final MockModule module = new MockModule();
    module.getConfiguration().setDebugger(m_debugger);
    m_debugger.setAddressTranslator(module, m_fileBase, m_imageBase);
    final DebugTargetSettings target = new ModuleTargetSettings(module);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    debuggerProvider.addDebugger(m_debugger);
    final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
    final CFunctionNode functionNode = new CFunctionNode(0, function, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), m_provider);
    CGraphDebugger.toggleBreakpoint(debuggerProvider, functionNode);
    assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(0x123, m_debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, 0).getAddress().getAddress().getAddress().toLong());
    assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_debugger.getBreakpointManager().getBreakpointStatus(BreakpointType.REGULAR, 0));
    CGraphDebugger.toggleBreakpoint(debuggerProvider, functionNode);
    assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 5 with CFunctionNode

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

the class PostgreSQLNodeSaver method saveFunctionNodes.

/**
 * Saves the function nodes to the database.
 *
 * @param provider The connection to the database.
 * @param nodes The nodes to save.
 * @param firstNode The database index of the first node.
 * @param functionNodeIndices Index into the nodes list that identifies the function nodes.
 *
 * @throws SQLException Thrown if saving the function nodes failed.
 */
protected static void saveFunctionNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> functionNodeIndices) throws SQLException {
    if (functionNodeIndices.isEmpty()) {
        return;
    }
    final String query = "INSERT INTO " + CTableNames.FUNCTION_NODES_TABLE + "(module_id, node_id, function, comment_id) VALUES (?, ?, ?, ?)";
    final ArrayList<INaviFunctionNode> functionNodesWithUnsavedComments = new ArrayList<INaviFunctionNode>();
    final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
    try {
        for (final int index : functionNodeIndices) {
            final CFunctionNode node = (CFunctionNode) nodes.get(index);
            final INaviFunction function = node.getFunction();
            final List<IComment> comments = node.getLocalFunctionComment();
            final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
            if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
                functionNodesWithUnsavedComments.add(node);
            }
            preparedStatement.setInt(1, function.getModule().getConfiguration().getId());
            preparedStatement.setInt(2, firstNode + index);
            preparedStatement.setObject(3, function.getAddress().toBigInteger(), Types.BIGINT);
            if (commentId == null) {
                preparedStatement.setNull(4, Types.INTEGER);
            } else {
                preparedStatement.setInt(4, commentId);
            }
            preparedStatement.addBatch();
        }
        preparedStatement.executeBatch();
    } finally {
        preparedStatement.close();
    }
    for (final INaviFunctionNode functionNode : functionNodesWithUnsavedComments) {
        final ArrayList<IComment> functionNodeComments = new ArrayList<IComment>();
        for (final IComment comment : functionNode.getLocalFunctionComment()) {
            try {
                final Integer commentId = provider.appendFunctionNodeComment(functionNode, comment.getComment(), comment.getUser().getUserId());
                final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
                functionNodeComments.add(newComment);
            } catch (final CouldntSaveDataException exception) {
                CUtilityFunctions.logException(exception);
            }
        }
        functionNode.initializeLocalFunctionComment(functionNodeComments);
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Aggregations

CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)18 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)10 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)9 Test (org.junit.Test)8 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)7 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)6 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)6 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)6 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)6 ArrayList (java.util.ArrayList)6 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)5 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)5 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)5 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)5 Date (java.util.Date)5 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)4 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)4 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)4 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)4 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)4