Search in sources :

Example 81 with INaviModule

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

the class CModulesModel method setValueAt.

@Override
public void setValueAt(final Object value, final int row, final int col) {
    if ((col != NAME_COLUMN) && (col != DESCRIPTION_COLUMN)) {
        throw new IllegalStateException("IE01167: Column can not be edited");
    }
    final INaviModule module = getModules().get(row);
    if (col == NAME_COLUMN) {
        try {
            module.getConfiguration().setName((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String message = "E00167: " + "Could not change the module name";
            final String description = CUtilityFunctions.createDescription("The new module name could not be saved to the database.", new String[] { "There was a problem with the connection to the database while the module name was saved" }, new String[] { "The module name was not saved. Please try to find out what went wrong with the database connection and try to save the module name again." });
            NaviErrorDialog.show(null, message, description, e);
        }
    } else if (col == DESCRIPTION_COLUMN) {
        try {
            module.getConfiguration().setDescription((String) value);
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            final String message = "E00168: " + "Could not change the module description";
            final String description = CUtilityFunctions.createDescription("The new module description could not be saved to the database.", new String[] { "There was a problem with the connection to the database while the module description was saved" }, new String[] { "The module description was not saved. Please try to find out what went wrong with the database connection and try to save the module description again." });
            NaviErrorDialog.show(null, message, description, e);
        }
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)

Example 82 with INaviModule

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

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

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

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

INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)180 Test (org.junit.Test)105 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)69 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)39 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)39 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)29 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)28 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)28 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)24 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)22 ArrayList (java.util.ArrayList)19 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)18 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)13 BigInteger (java.math.BigInteger)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)11 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)11 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)9 CAddressSpace (com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)9 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)9