Search in sources :

Example 76 with INaviInstruction

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

the class CStepOverHelper method stepInCodeNode.

/**
 * Adds the addresses of a instructions that follow another instruction to a list when
 * single-stepping in a code node.
 *
 * @param node The code node where the step over operation happens.
 * @param address The address in question.
 * @param instructions List to extend with the successor instructions.
 */
private static void stepInCodeNode(final INaviCodeNode node, final UnrelocatedAddress address, final Set<BreakpointAddress> instructions) {
    final int instructionIndex = CCodeNodeHelpers.getInstruction(node, address.getAddress());
    if (instructionIndex != -1) {
        if (instructionIndex < node.instructionCount() - 1) {
            // ... and the basic block is large enough that the following
            // instruction is also part of the basic block.
            final INaviInstruction instruction = Iterables.get(node.getInstructions(), instructionIndex + 1);
            instructions.add(new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress())));
        } else {
            // ... but the instruction is the last instruction of the basic block,
            // so we have to look into the child nodes of the basic block.
            instructions.addAll(CSteppingHelper.getSuccessors(node));
        }
    }
}
Also used : UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 77 with INaviInstruction

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

the class CReilViewCreator method create.

/**
 * Creates a REIL view from a view.
 *
 * @param container The container in which the new REIL view is created.
 * @param view The view to be translated to REIL code.
 *
 * @return The created REIL code view.
 *
 * @throws InternalTranslationException Thrown if the view could not be translated to REIL code.
 * @throws CouldntLoadDataException
 */
public static INaviView create(final INaviModule container, final INaviView view) throws InternalTranslationException, CouldntLoadDataException {
    Preconditions.checkNotNull(container, "IE01768: Container argument can not be null");
    Preconditions.checkNotNull(view, "IE01769: View argument can not be null");
    final Map<IAddress, String> textMap = new HashMap<IAddress, String>();
    for (final CCodeNode node : view.getBasicBlocks()) {
        for (final INaviInstruction instruction : node.getInstructions()) {
            textMap.put(instruction.getAddress(), instruction.toString());
        }
    }
    final INaviView reilView = CReilViewCreator.create(container, view.getContent().getReilCode().getGraph());
    for (final CCodeNode node : reilView.getBasicBlocks()) {
        for (final INaviInstruction reilInstruction : node.getInstructions()) {
            if ((reilInstruction.getAddress().toLong() & 0xFF) == 0) {
                try {
                    node.getComments().appendLocalInstructionComment(reilInstruction, textMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress())));
                } catch (final CouldntSaveDataException e) {
                    // Not possible for unsaved views.
                    CUtilityFunctions.logException(e);
                }
            }
        }
    }
    return reilView;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) HashMap(java.util.HashMap) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 78 with INaviInstruction

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

the class CViewContent method createCodeNode.

@Override
public CCodeNode createCodeNode(final INaviFunction parentFunction, final List<? extends INaviInstruction> instructions) {
    Preconditions.checkNotNull(instructions, "IE00286: Instructions argument can not be null");
    if ((parentFunction != null) && !parentFunction.inSameDatabase(provider)) {
        throw new IllegalArgumentException("IE00287: Parent function and view are not in the same database");
    }
    for (final INaviInstruction instruction : instructions) {
        Preconditions.checkNotNull(instruction, "IE00288: Instruction list contains a null-instruction");
        Preconditions.checkArgument(instruction.inSameDatabase(provider), "IE00289: Instruction and view are not in the same database");
    }
    final CCodeNode codeNode = new CCodeNode(-1, 0, 0, 0, 0, Color.WHITE, Color.BLACK, false, true, null, parentFunction, new HashSet<CTag>(), provider);
    for (final INaviInstruction instruction : instructions) {
        codeNode.addInstruction(instruction, null);
    }
    addNode(codeNode);
    updateGraphType(codeNode);
    codeNode.addListener(m_internalNodeListener);
    m_reilFunction = null;
    return codeNode;
}
Also used : CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 79 with INaviInstruction

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

the class CCodeNodeUpdater method removeListeners.

/**
 * Removes all listeners this class has attached.
 */
private void removeListeners() {
    try {
        codeNode.getParentFunction().removeListener(functionUpdater);
        codeNode.getParentFunction().getModule().removeListener(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.
    }
    codeNode.removeListener(codeNodeListener);
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        instruction.removeListener(instructionUpdater);
    }
    final Iterator<CTag> it = codeNode.getTagsIterator();
    while (it.hasNext()) {
        it.next().removeListener(tagUpdater);
    }
    for (final IDebugger debugger : provider.getDebuggers()) {
        debugger.getProcessManager().removeListener(debuggerUpdater);
    }
    provider.removeListener(debuggerProviderListener);
    graph.getSettings().getDisplaySettings().removeListener(settingsUpdater);
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 80 with INaviInstruction

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

the class CCodeNodeUpdater method generateContent.

@Override
public void generateContent(final IZyNodeRealizer realizer, final ZyLabelContent content) {
    ZyCodeNodeBuilder.buildContent(content, codeNode, graph.getSettings(), nodeModifier);
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        final INaviModule module = instruction.getModule();
        if ((provider != null) && (provider.getDebugger(module) != null) && graph.getSettings().getDisplaySettings().getShowMemoryAddresses(provider.getDebugger(module))) {
            final int line = CCodeNodeHelpers.instructionToLine(codeNode, instruction);
            if (line != -1) {
                final ZyLineContent lineContent = this.realizer.getNodeContent().getLineContent(line);
                // TODO(timkornau) x64
                lineContent.setTextColor(0, 8, Color.RED);
            }
        }
    }
    // Set highlighting for breakpoints and the instruction pointer.
    final INaviInstruction instruction = codeNode.getInstructions().iterator().next();
    if (instruction != null) {
        final INaviModule module = instruction.getModule();
        final IDebugger debugger = provider.getDebugger(module);
        if (debugger == null) {
            return;
        }
        final BreakpointManager manager = debugger.getBreakpointManager();
        CBreakpointPainter.paintBreakpoints(manager, node, codeNode);
        if (debugger.getProcessManager().getActiveThread() != null) {
            final RelocatedAddress instructionPointer = debugger.getProcessManager().getActiveThread().getCurrentAddress();
            final MemoryModule memoryModule = debugger.getProcessManager().getModule(instructionPointer);
            final UnrelocatedAddress unrelocatedIP = new DefaultAddressConverter(memoryModule.getBaseAddress().getAddress(), module.getConfiguration().getFileBase()).memoryToFile(instructionPointer);
            CDebuggerPainter.updateSingleNodeDebuggerHighlighting(graph, unrelocatedIP, node);
        }
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) DefaultAddressConverter(com.google.security.zynamics.binnavi.debug.debugger.DefaultAddressConverter) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)82 Test (org.junit.Test)27 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)26 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)24 ArrayList (java.util.ArrayList)24 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)20 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)18 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)16 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)15 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)15 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)10 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)10 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)9 IBlockNode (com.google.security.zynamics.binnavi.disassembly.IBlockNode)9 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)9 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)8 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)7