Search in sources :

Example 1 with MaybeNullException

use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.

the class CLoadProgressPainter method getLoadPercentage.

/**
 * Calculates the load percentage of the rendered view to display a progress bar.
 *
 * @param view The view to be loaded.
 *
 * @return The calculated load percentage.
 */
private static double getLoadPercentage(final INaviView view) {
    final int totalSteps = ViewLoadEvents.values().length + GraphBuilderEvents.values().length;
    final int loadState = view.getLoadState();
    if (loadState == IDatabaseLoadProgressReporter.INACTIVE) {
        try {
            // The view was previously loaded and only needs to be built.
            final ZyGraphBuilder builder = ZyGraphBuilderManager.instance().getBuilder(view);
            return (1.0 * (ViewLoadEvents.values().length + builder.getBuildStep())) / totalSteps;
        } catch (final MaybeNullException exception) {
            return 0;
        }
    } else {
        return (1.0 * view.getLoadState()) / totalSteps;
    }
}
Also used : ZyGraphBuilder(com.google.security.zynamics.binnavi.yfileswrap.zygraph.Builders.ZyGraphBuilder) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) GradientPaint(java.awt.GradientPaint)

Example 2 with MaybeNullException

use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.

the class CViewInserter method insertCodeNode.

/**
 * Clones a source node and inserts the cloned node into the target view.
 *
 * @param target The target view where the node is inserted.
 * @param node Node from the source view that is cloned.
 *
 * @return The cloned code node.
 */
private static INaviCodeNode insertCodeNode(final INaviView target, final INaviCodeNode node) {
    // TODO: cloning the node is a bad solution since this just fixes the symptoms: instructions are
    // closed two times
    final INaviCodeNode sourceNode = (INaviCodeNode) node.cloneNode();
    final Iterable<INaviInstruction> instructions = sourceNode.getInstructions();
    final ArrayList<INaviInstruction> instructionList = Lists.newArrayList(instructions);
    CCodeNode codeNode;
    try {
        codeNode = target.getContent().createCodeNode(sourceNode.getParentFunction(), instructionList);
    } catch (final MaybeNullException e) {
        codeNode = target.getContent().createCodeNode(null, instructionList);
    }
    if (sourceNode.getComments().getGlobalCodeNodeComment() != null) {
        codeNode.getComments().initializeGlobalCodeNodeComment(sourceNode.getComments().getGlobalCodeNodeComment());
    }
    if (sourceNode.getComments().getLocalCodeNodeComment() != null) {
        codeNode.getComments().initializeLocalCodeNodeComment(sourceNode.getComments().getLocalCodeNodeComment());
    }
    final Iterable<INaviInstruction> newInstructions = codeNode.getInstructions();
    for (int i = 0; i < Iterables.size(instructions); i++) {
        codeNode.getComments().initializeLocalInstructionComment(Iterables.get(newInstructions, i), sourceNode.getComments().getLocalInstructionComment(Iterables.get(instructions, i)));
    }
    return codeNode;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 3 with MaybeNullException

use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.

the class CCodeNodeMenu method addRenameFunctionMenu.

private void addRenameFunctionMenu(final INaviCodeNode codeNode, final CGraphModel model) {
    try {
        final INaviFunction function = codeNode.getParentFunction();
        final INaviView view = function.getModule().getContent().getViewContainer().getView(function);
        add(new CChangeFunctionNameAction(model.getParent(), view));
    } catch (final MaybeNullException e) {
    // no parent function no menu entry we are ok with this.
    }
}
Also used : CChangeFunctionNameAction(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CChangeFunctionNameAction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 4 with MaybeNullException

use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.

the class CCodeNodeMenu method addOpenOriginalFunctionMenu.

private void addOpenOriginalFunctionMenu(final CGraphModel model, final NaviNode node) {
    final INaviCodeNode rawNode = (INaviCodeNode) node.getRawNode();
    try {
        final INaviFunction nodeFunction = rawNode.getParentFunction();
        final INaviFunction viewFunction = model.getViewContainer().getFunction(model.getGraph().getRawView());
        if (nodeFunction != viewFunction) {
            add(CActionProxy.proxy(new COpenOriginalFunction(model.getParent(), model.getViewContainer(), nodeFunction)));
        }
    } catch (final MaybeNullException e) {
    // If there is no original function then we can not open it.
    }
}
Also used : COpenOriginalFunction(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.COpenOriginalFunction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 5 with MaybeNullException

use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.

the class CCodeNodeUpdater method initializeListeners.

/**
 * Initializes the listeners that are responsible for updating the code node.
 */
private void initializeListeners() {
    try {
        codeNode.getParentFunction().addListener(functionUpdater);
        codeNode.getParentFunction().getModule().addListener(moduleUpdater);
    } catch (final MaybeNullException exception) {
    // The code nodes does not have a parent function, therefore the information
    // about the parent function is not shown in the code and does not have to
    // be processed when updating.
    }
    final HashMap<INaviInstruction, INaviFunction> referenceMap = CReferenceFinder.getCodeReferenceMap(codeNode);
    for (final INaviFunction functionReference : Sets.newHashSet(referenceMap.values())) {
        functionReference.addListener(functionUpdater);
    }
    codeNode.addListener(codeNodeListener);
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        instruction.addListener(instructionUpdater);
        for (final COperandTree tree : instruction.getOperands()) {
            for (final INaviOperandTreeNode currentNode : tree.getNodes()) {
                currentNode.addListener(operandTreeUpdater);
            }
        }
    }
    final Iterator<CTag> it = codeNode.getTagsIterator();
    while (it.hasNext()) {
        it.next().addListener(tagUpdater);
    }
    for (final IDebugger debugger : provider.getDebuggers()) {
        debugger.getProcessManager().addListener(debuggerUpdater);
    }
    provider.addListener(debuggerProviderListener);
    graph.getSettings().getDisplaySettings().addListener(settingsUpdater);
    try {
        codeNode.getParentFunction().getModule().getTypeManager().addListener(substitutionsUpdater);
    } catch (final MaybeNullException exception) {
    // If the code node doesn't have a a parent function, it is not in the database and therefore
    // cannot receive type substitutions.
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)42 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)11 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)11 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)10 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)7 SQLException (java.sql.SQLException)7 ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)6 CallableStatement (java.sql.CallableStatement)6 ArrayList (java.util.ArrayList)5 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)4 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)4 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)4 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)4 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)3 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)3 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)2