Search in sources :

Example 16 with MaybeNullException

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

the class StepBreakpointHitSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final StepBreakpointHitReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final ProcessManager processManager = getDebugger().getProcessManager();
    RelocatedAddress breakpointAddress = null;
    final RegisterValues registerValues = reply.getRegisterValues();
    final long tid = reply.getThreadId();
    for (final ThreadRegisters threadRegisters : registerValues) {
        if (tid == threadRegisters.getTid()) {
            for (final RegisterValue registerValue : threadRegisters) {
                if (registerValue.isPc()) {
                    breakpointAddress = new RelocatedAddress(new CAddress(registerValue.getValue()));
                    break;
                }
            }
        }
    }
    manager.clearBreakpointsPassive(BreakpointType.STEP);
    try {
        final TargetProcessThread thread = processManager.getThread(tid);
        for (final ThreadRegisters threadRegisters : registerValues) {
            if (tid == threadRegisters.getTid()) {
                // Update the thread with the new register values.
                thread.setRegisterValues(threadRegisters.getRegisters());
            }
        }
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(breakpointAddress);
    } catch (final MaybeNullException exception) {
        // Apparently there is no thread with the specified TID.
        // This is not necessarily an error because the thread might have
        // been closed while this handler was active.
        // Nevertheless this should be logged.
        NaviLogger.info("Error: Process manager could not get thread. Exception %s", exception);
        return;
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 17 with MaybeNullException

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

the class HaltSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final HaltReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    try {
        final TargetProcessThread thread = processManager.getThread(reply.getTid());
        processManager.setActiveThread(thread);
    } catch (final MaybeNullException e) {
        NaviLogger.severe("Error: Process manager could not set active threads. Exception %s", e);
    // Apparently there is no thread with the specified TID.
    // This is not necessarily an error because the thread might have
    // been closed while this handler was active.
    // Nevertheless this should be logged.
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

Example 18 with MaybeNullException

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

the class ModuleLoadedSynchronizer method setActiveThreadById.

/**
 * Sets the currently active thread in the process manager.
 *
 * @param threadId The thread id to be activated.
 */
private static void setActiveThreadById(final ProcessManager processManager, final long threadId) {
    try {
        final TargetProcessThread thread = processManager.getThread(threadId);
        processManager.setActiveThread(thread);
    } catch (final MaybeNullException exception) {
        CUtilityFunctions.logException(exception);
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)

Example 19 with MaybeNullException

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

the class CViewPruner method convertNodes.

/**
 * Converts the nodes from the original view to the pruned view.
 *
 * @param view The original view.
 * @param prunedView The pruned view.
 * @param keptInstructions Instructions to add to the new view.
 *
 * @return A mapping between nodes of the original view and nodes of the pruned view.
 */
private static Map<INaviViewNode, INaviViewNode> convertNodes(final INaviView view, final INaviView prunedView, final List<INaviInstruction> keptInstructions) {
    final Map<INaviViewNode, INaviViewNode> nodeMap = new HashMap<INaviViewNode, INaviViewNode>();
    for (final INaviViewNode node : view.getGraph().getNodes()) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            final ArrayList<INaviInstruction> newInstructions = Lists.newArrayList(cnode.getInstructions());
            newInstructions.retainAll(keptInstructions);
            if (!newInstructions.isEmpty()) {
                CCodeNode newNode;
                try {
                    newNode = prunedView.getContent().createCodeNode(cnode.getParentFunction(), newInstructions);
                } catch (final MaybeNullException e) {
                    newNode = prunedView.getContent().createCodeNode(null, newInstructions);
                }
                newNode.setBorderColor(node.getBorderColor());
                newNode.setColor(node.getColor());
                nodeMap.put(node, newNode);
            }
        } else if (node instanceof INaviFunctionNode) {
            final INaviFunction function = ((INaviFunctionNode) node).getFunction();
            final CFunctionNode newNode = prunedView.getContent().createFunctionNode(function);
            nodeMap.put(node, newNode);
        }
    }
    return nodeMap;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) HashMap(java.util.HashMap) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 20 with MaybeNullException

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

the class CGlobalEdgeCommentSynchronizer method updateOpenViews.

/**
 * Pushes a new global edge comment to all open views.
 *
 * @param edge The edge that has the new comment.
 * @param comments The new comment of the code node.
 *
 * @throws CouldntSaveDataException Thrown if updating the edge comments failed.
 */
public static void updateOpenViews(final INaviEdge edge, final ArrayList<IComment> comments) throws CouldntSaveDataException {
    try {
        final Pair<INaviModule, INaviModule> modules = getModules(edge);
        if (modules.first() != modules.second()) {
            // TODO: Handle this
            return;
        }
        if ((modules.first() != null) && (modules.second() != null) && modules.first().isLoaded()) {
            final List<INaviEdge> edgelist = new ArrayList<INaviEdge>();
            final Quad<Integer, IAddress, Integer, IAddress> refEdgeData = getEdgeData(edge);
            for (final INaviView view : modules.first().getContent().getViewContainer().getViews()) {
                edgelist.addAll(collectEdges(view, refEdgeData));
            }
            for (final INaviEdge updateEdge : edgelist) {
                updateEdge.initializeGlobalComment(comments);
            }
        }
    } catch (final MaybeNullException exception) {
    // Trying to update global comments of code nodes without global comments.
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

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