Search in sources :

Example 36 with INaviFunction

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

the class CCodeNodeParser method createCurrentNode.

/**
   * Creates a new code node.
   *
   * @param resultSet Provides the data for the code node.
   *
   * @return The created code node object.
   *
   * @throws ParserException Thrown if the node data could not be read.
   * @throws CPartialLoadException Thrown if not all required modules are loaded.
   */
private CCodeNode createCurrentNode(final ICodeNodeProvider resultSet) throws ParserException, CPartialLoadException {
    final int nodeId = resultSet.getNodeId();
    final int moduleId = resultSet.getModule();
    final IAddress parentFunction = resultSet.getParentFunction();
    final INaviModule module = modules.get(moduleId);
    if (module == null) {
        throw new ParserException(String.format("Node with ID %d has unknown parent module with ID %d", nodeId, moduleId));
    }
    if (!module.isLoaded()) {
        try {
            module.load();
        } catch (final CouldntLoadDataException e) {
            throw new CPartialLoadException("E00066: The view could not be loaded because not all modules that form the view could be loaded", module);
        } catch (final LoadCancelledException e) {
            throw new CPartialLoadException("E00067: The view could not be loaded because it was cancelled", module);
        }
    }
    final INaviFunction function = parentFunction == null ? null : module.getContent().getFunctionContainer().getFunction(parentFunction);
    if ((parentFunction != null) && (function == null)) {
        throw new ParserException(String.format("Node with ID %d has unknown parent function with address %s", nodeId, parentFunction.toHexString()));
    }
    final double x = resultSet.getX();
    final double y = resultSet.getY();
    final double width = resultSet.getWidth();
    final double height = resultSet.getHeight();
    final Color color = new Color(resultSet.getColor());
    final Color bordercolor = new Color(resultSet.getBorderColor());
    final boolean selected = resultSet.isSelected();
    final boolean visible = resultSet.isVisible();
    final Integer localCodeNodeCommentId = resultSet.getLocalNodeCommentId();
    final Integer globalCodeNodeCommentId = resultSet.getGlobalNodeCommentId();
    // TODO(timkornau): final new Set<CTag>! must replaced by a set which
    // contains the loaded node
    // tags from the DB
    final CCodeNode codeNode = new CCodeNode(nodeId, x, y, width, height, color, bordercolor, selected, visible, null, function, new HashSet<CTag>(), sqlProvider);
    if (localCodeNodeCommentId != null) {
        localCommentIdToCodeNode.put(localCodeNodeCommentId, codeNode);
    }
    if (globalCodeNodeCommentId != null) {
        globalCommentIdToCodeNode.put(globalCodeNodeCommentId, codeNode);
    }
    return codeNode;
}
Also used : CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) Color(java.awt.Color) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 37 with INaviFunction

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

the class CResolveAllFunctionDialog method resolveAllFunctions.

/**
   * Takes the information from the GUI and forwards functions.
   */
private int resolveAllFunctions() {
    int counter = 0;
    for (final INaviModule currentModule : m_targetModules) {
        for (final INaviFunction currentFunction : currentModule.getContent().getFunctionContainer().getFunctions()) {
            final String originalName = currentFunction.getOriginalModulename();
            if (!originalName.equalsIgnoreCase(currentModule.getConfiguration().getName()) && !originalName.equalsIgnoreCase("")) {
                for (final INaviModule targetModule : m_sourceModules) {
                    final String targetModuleName = targetModule.getConfiguration().getName();
                    if (targetModuleName.toUpperCase().contains(originalName.toUpperCase()) && CFunctionHelpers.isForwardableFunction(currentFunction) && (currentFunction.getForwardedFunctionModuleId() == 0)) {
                        String currentFunctionName = currentFunction.getName();
                        if (currentFunctionName.startsWith("__imp_")) {
                            currentFunctionName = currentFunctionName.substring("__imp_".length());
                        }
                        try {
                            final INaviFunction targetFunction = targetModule.getContent().getFunctionContainer().getFunction(currentFunctionName);
                            currentFunction.setForwardedFunction(targetFunction);
                            ++counter;
                        } catch (final MaybeNullException exception) {
                        } catch (final CouldntSaveDataException exception) {
                            CUtilityFunctions.logException(exception);
                        }
                    }
                }
            }
        }
    }
    return counter;
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 38 with INaviFunction

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

the class CResolveFunctionDialog method resolveFunctions.

/**
   * Takes the information from the GUI and forwards functions.
   */
private void resolveFunctions() {
    final Object selectedParentString = m_parentBox.getSelectedItem();
    if (selectedParentString == null) {
        return;
    }
    final Object selectedModule = m_targetModuleBox.getSelectedItem();
    if (selectedModule == null) {
        return;
    }
    final INaviModule targetModule = ((CModuleWrapper) selectedModule).getObject();
    if (!targetModule.isLoaded()) {
        if (CMessageBox.showYesNoQuestion(this, "The target module must be loaded before functions can be forwarded.\n\n" + "Do you want to load the target module now?") == JOptionPane.NO_OPTION) {
            return;
        }
        CModuleLoader.loadModule(this, targetModule);
    }
    int counter = 0;
    final String parentString = selectedParentString.toString();
    for (final INaviFunction sourceFunction : m_module.getContent().getFunctionContainer().getFunctions()) {
        if (sourceFunction.getOriginalModulename().equalsIgnoreCase(parentString) && CFunctionHelpers.isForwardableFunction(sourceFunction)) {
            String sourceFunctionName = sourceFunction.getName();
            if (sourceFunctionName.startsWith("__imp_")) {
                sourceFunctionName = sourceFunctionName.substring("__imp_".length());
            }
            try {
                final INaviFunction targetFunction = targetModule.getContent().getFunctionContainer().getFunction(sourceFunctionName);
                sourceFunction.setForwardedFunction(targetFunction);
                ++counter;
            } catch (final MaybeNullException exception) {
            // There is no function in the target modules with the name of the source function.
            } catch (final CouldntSaveDataException exception) {
                CUtilityFunctions.logException(exception);
                final String message = "E00023: " + "Could not save function forwarding";
                final String description = CUtilityFunctions.createDescription(String.format("Could not forward the function '%s' from module '%s' to module '%s'", sourceFunction.getName(), m_module.getConfiguration().getName(), targetModule.getConfiguration().getName()), new String[] { "The database connection was dropped while saving." }, new String[] { "The changes in function forwarding were not saved. Try saving function " + "forwarding again. If necessary, close the connection to the database and " + "reconnect." });
                NaviErrorDialog.show(this, message, description, exception);
            }
        }
    }
    if (counter == 0) {
        CMessageBox.showInformation(this, "No functions suitable for forwarding were found.");
    } else {
        CMessageBox.showInformation(this, String.format("%d functions were forwarded from module '%s' to module '%s'", counter, m_module.getConfiguration().getName(), targetModule.getConfiguration().getName()));
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 39 with INaviFunction

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

the class CFunctionViewsModel method getEdgeCount.

/**
   * Calculates the number of edges in a view.
   * 
   * @param view The view to calculate.
   * @param function The function represented by the view.
   * 
   * @return The number of edges in the view.
   */
private int getEdgeCount(final INaviView view, final INaviFunction function) {
    if (view.isLoaded() || (function.getForwardedFunctionAddress() == null)) {
        return view.getEdgeCount();
    } else {
        final INaviModule forwardedModule = m_database.getContent().getModule(function.getForwardedFunctionModuleId());
        Preconditions.checkNotNull(forwardedModule, "IE01186: Unknown forwarded module");
        if (forwardedModule.isLoaded()) {
            final INaviFunction forwardedFunction = forwardedModule.getContent().getFunctionContainer().getFunction(function.getForwardedFunctionAddress());
            Preconditions.checkNotNull(forwardedFunction, "IE01185: Unknown forwarded function");
            return forwardedFunction.getEdgeCount();
        } else {
            return 0;
        }
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 40 with INaviFunction

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

the class CFunctionViewsModel method getNodeCount.

/**
   * Calculates the number of nodes in a view.
   * 
   * @param view The view to calculate.
   * @param function The function represented by the view.
   * 
   * @return The number of nodes in the view.
   */
private int getNodeCount(final INaviView view, final INaviFunction function) {
    if (view.isLoaded() || (function.getForwardedFunctionAddress() == null)) {
        // View is loaded or not forwarded => Get the active node count
        return view.getNodeCount();
    } else {
        final INaviModule forwardedModule = m_database.getContent().getModule(function.getForwardedFunctionModuleId());
        Preconditions.checkNotNull(forwardedModule, "IE01188: Unknown forwarded module");
        if (forwardedModule.isLoaded()) {
            final INaviFunction forwardedFunction = forwardedModule.getContent().getFunctionContainer().getFunction(function.getForwardedFunctionAddress());
            Preconditions.checkNotNull(forwardedFunction, "IE01187: Unknown forwarded function");
            return forwardedFunction.getBasicBlockCount();
        } else {
            return 0;
        }
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Aggregations

INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)94 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)39 Test (org.junit.Test)38 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)26 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)20 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)16 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)16 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)14 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12 ArrayList (java.util.ArrayList)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)9 HashMap (java.util.HashMap)9 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)8 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)8 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)8