Search in sources :

Example 56 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class CGraphDebuggerTest method testToggleBreakpoint3.

@Test
public void testToggleBreakpoint3() {
    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 ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
    final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
    codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
    codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
    CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
    assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(0x124, 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, codeNode, 2);
    assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) 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) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) Test(org.junit.Test)

Example 57 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag 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 58 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLViewsLoader method getNodeTags.

/**
   * Loads the node tags of the views of a module.
   * 
   * @param connection Provides the connection to the database.
   * @param module The module whose node-tagged views are determined.
   * @param nodeTagManager Provides the available node tags.
   * 
   * @return Maps view ID -> node tags used in the view.
   * 
   * @throws SQLException Thrown if the data could not be loaded.
   */
private static Map<Integer, Set<CTag>> getNodeTags(final CConnection connection, final INaviModule module, final ITagManager nodeTagManager) throws SQLException {
    final Map<Integer, Set<CTag>> tagMap = new HashMap<Integer, Set<CTag>>();
    final String query = "SELECT * FROM load_module_node_tags(?)";
    final PreparedStatement statement = connection.getConnection().prepareStatement(query);
    statement.setInt(1, module.getConfiguration().getId());
    final ResultSet resultSet = statement.executeQuery();
    try {
        while (resultSet.next()) {
            final int viewId = resultSet.getInt(1);
            final int tagId = resultSet.getInt(2);
            if (!tagMap.containsKey(viewId)) {
                tagMap.put(viewId, new HashSet<CTag>());
            }
            final CTag tag = CTagHelpers.findTag(nodeTagManager.getRootTag(), tagId);
            if (tag != null) {
                tagMap.get(viewId).add(tag);
            }
        }
    } finally {
        resultSet.close();
    }
    return tagMap;
}
Also used : HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) HashMap(java.util.HashMap) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 59 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLFunctionNodeLoader method load.

/**
   * Loads the function nodes of a view.
   * 
   * @param provider The connection to the database.
   * @param view The view whose function nodes are loaded.
   * @param nodes The loaded nodes are stored here.
   * 
   * @throws CPartialLoadException Thrown if loading the nodes failed because a necessary module was
   *         not loaded.
   * @throws CouldntLoadDataException
   */
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CPartialLoadException, CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE02510: provider argument can not be null");
    Preconditions.checkNotNull(view, "IE02511: view argument can not be null");
    Preconditions.checkNotNull(nodes, "IE02512: nodes argument can not be null");
    // TODO (timkornau): query needs to go into the database.
    final String query = "SELECT nodes.view_id, nodes.id, functions.module_id, " + " function, fnodes.comment_id as local_comment, x, y, width, height, " + " color, selected, visible FROM " + CTableNames.NODES_TABLE + " AS nodes JOIN " + CTableNames.FUNCTION_NODES_TABLE + " AS fnodes " + " ON nodes.id = fnodes.node_id JOIN " + CTableNames.FUNCTIONS_TABLE + " AS functions ON functions.address = fnodes.function " + " AND functions.module_id = fnodes.module_id  WHERE view_id = ?";
    final Map<Integer, INaviFunctionNode> commentIdToFunctionNode = new HashMap<Integer, INaviFunctionNode>();
    try {
        final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
        statement.setInt(1, view.getConfiguration().getId());
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                final int moduleId = resultSet.getInt("module_id");
                final INaviModule module = provider.findModule(moduleId);
                if (!module.isLoaded()) {
                    try {
                        module.load();
                    } catch (final CouldntLoadDataException e) {
                        throw new CPartialLoadException("E00064: The view could not be loaded because not all modules that form the view are loaded", module);
                    } catch (final LoadCancelledException e) {
                        throw new CPartialLoadException("E00065: The view could not be loaded because not all modules that form the view are loaded", module);
                    }
                }
                final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "function");
                final INaviFunction function = module.getContent().getFunctionContainer().getFunction(address);
                final int nodeId = resultSet.getInt("id");
                Integer commentId = resultSet.getInt("local_comment");
                if (resultSet.wasNull()) {
                    commentId = null;
                }
                final double posX = resultSet.getDouble("x");
                final double posY = resultSet.getDouble("y");
                final double width = resultSet.getDouble("width");
                final double height = resultSet.getDouble("height");
                final Color color = new Color(resultSet.getInt("color"));
                final boolean selected = resultSet.getBoolean("selected");
                final boolean visible = resultSet.getBoolean("visible");
                final INaviFunctionNode functionNode = new CFunctionNode(nodeId, function, posX, posY, width, height, color, selected, visible, null, new HashSet<CTag>(), provider);
                nodes.add(functionNode);
                if (commentId != null) {
                    commentIdToFunctionNode.put(commentId, functionNode);
                }
            }
        } finally {
            resultSet.close();
        }
        if (!commentIdToFunctionNode.isEmpty()) {
            final HashMap<Integer, ArrayList<IComment>> commentIdsToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunctionNode.keySet());
            for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdsToComments.entrySet()) {
                commentIdToFunctionNode.get(commentIdToComment.getKey()).initializeLocalFunctionComment(commentIdToComment.getValue());
            }
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) Color(java.awt.Color) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) ResultSet(java.sql.ResultSet) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 60 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLTextNodeLoader method load.

/**
   * Loads the text nodes of a view.
   * 
   * @param provider The connection to the database.
   * @param view The view whose text nodes are loaded.
   * @param nodes The loaded nodes are stored here.
   * 
   * @throws CouldntLoadDataException
   */
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE02516: provider argument can not be null");
    Preconditions.checkNotNull(view, "IE02517: view argument can not be null");
    Preconditions.checkNotNull(nodes, "IE02518: nodes argument can not be null");
    final Map<Integer, INaviTextNode> commentIdToTextNode = new HashMap<Integer, INaviTextNode>();
    final String query = "SELECT id, comment_id, x, y, width, height, color, selected, visible " + " FROM " + CTableNames.NODES_TABLE + " JOIN " + CTableNames.TEXT_NODES_TABLE + " ON id = node_id " + " WHERE view_id = " + view.getConfiguration().getId();
    try {
        final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                final int nodeId = resultSet.getInt("id");
                Integer commentId = resultSet.getInt("comment_id");
                if (resultSet.wasNull()) {
                    commentId = null;
                }
                final double xPos = resultSet.getDouble("x");
                final double yPos = resultSet.getDouble("y");
                final double width = resultSet.getDouble("width");
                final double height = resultSet.getDouble("height");
                final Color color = new Color(resultSet.getInt("color"));
                final boolean selected = resultSet.getBoolean("selected");
                final boolean visible = resultSet.getBoolean("visible");
                final INaviTextNode textNode = new CTextNode(nodeId, xPos, yPos, width, height, color, selected, visible, new HashSet<CTag>(), null, provider);
                if (commentId != null) {
                    commentIdToTextNode.put(commentId, textNode);
                }
                nodes.add(textNode);
            }
        } finally {
            resultSet.close();
        }
        if (!commentIdToTextNode.isEmpty()) {
            final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToTextNode.keySet());
            for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
                commentIdToTextNode.get(commentIdToComment.getKey()).initializeComment(commentIdToComment.getValue());
            }
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Color(java.awt.Color) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode)

Aggregations

CTag (com.google.security.zynamics.binnavi.Tagging.CTag)113 Test (org.junit.Test)55 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)42 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)35 Date (java.util.Date)28 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)24 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)24 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)21 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)20 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)18 ArrayList (java.util.ArrayList)17 Tree (com.google.security.zynamics.zylib.types.trees.Tree)15 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)14 TreeNode (com.google.security.zynamics.zylib.types.trees.TreeNode)14 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)13 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)13 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)13 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)13 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)13 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12