Search in sources :

Example 71 with UnrelocatedAddress

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

Example 72 with UnrelocatedAddress

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

the class TraceEventTest method testConstructor.

@Test
public void testConstructor() {
    final MockModule module = new MockModule();
    final TraceEvent event = new TraceEvent(new com.google.security.zynamics.binnavi.debug.models.trace.TraceEvent(0, new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(0x123))), TraceEventType.ECHO_BREAKPOINT, new ArrayList<com.google.security.zynamics.binnavi.debug.models.trace.TraceRegister>()));
    assertEquals(0x123, event.getAddress().toLong());
    assertEquals(com.google.security.zynamics.binnavi.API.disassembly.TraceEventType.EchoBreakpoint, event.getType());
    assertEquals("Trace Event [EchoBreakpoint : 123]", event.toString());
}
Also used : MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) ArrayList(java.util.ArrayList) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 73 with UnrelocatedAddress

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

the class PostgreSQLModuleFunctions method getViewsWithAddresses.

/**
   * Finds the views inside the module that contain instructions of a given address.
   *
   * The module must be stored in the database connected to by the provider argument.
   *
   * @param provider The SQL provider that provides the connection.
   * @param module The module to search through.
   * @param addresses The addresses to search for.
   * @param all True, to search for views that contain all addresses. False, for any addresses.
   *
   * @return A list of views where instructions with the given address can be found.
   *
   * @throws CouldntLoadDataException Thrown if searching through the module failed.
   */
public static List<INaviView> getViewsWithAddresses(final AbstractSQLProvider provider, final INaviModule module, final List<UnrelocatedAddress> addresses, final boolean all) throws CouldntLoadDataException {
    checkArguments(provider, module);
    Preconditions.checkNotNull(addresses, "IE00492: Addresses argument can not be null");
    final StringBuilder queryBuilder = new StringBuilder();
    final int moduleID = module.getConfiguration().getId();
    if (addresses.size() == 0) {
        return new ArrayList<INaviView>();
    } else if (addresses.size() == 1) {
        queryBuilder.append("SELECT mvt.module_id, mvt.view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " AS mvt JOIN " + CTableNames.NODES_TABLE + " AS nt ON mvt.view_id = nt.view_id AND mvt.module_id = " + moduleID + " JOIN " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS cit ON nt.id = cit.node_id AND cit.module_id = " + moduleID + " JOIN " + CTableNames.INSTRUCTIONS_TABLE + " AS it ON it.address = cit.address AND it.module_id = " + moduleID + " WHERE it.address = " + addresses.get(0).getAddress().toLong());
    } else if (all) {
        boolean needsComma = false;
        int counter = 0;
        queryBuilder.append("select view_id from ");
        for (final UnrelocatedAddress address : addresses) {
            if (needsComma) {
                queryBuilder.append(" inner join ");
            }
            needsComma = true;
            queryBuilder.append("(SELECT mvt.module_id, mvt.view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " AS mvt JOIN " + CTableNames.NODES_TABLE + " AS nt ON mvt.view_id = nt.view_id AND mvt.module_id = " + moduleID + " JOIN " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS cit ON nt.id = cit.node_id AND cit.module_id = " + moduleID + " JOIN " + CTableNames.INSTRUCTIONS_TABLE + " AS it ON it.address = cit.address AND it.module_id = " + moduleID + " WHERE it.address = " + address.getAddress().toLong() + ") AS t" + counter);
            counter++;
        }
        queryBuilder.append(" USING (view_id)");
    } else {
        queryBuilder.append("SELECT mvt.module_id, mvt.view_id FROM " + CTableNames.MODULE_VIEWS_TABLE + " AS mvt JOIN " + CTableNames.NODES_TABLE + " AS nt ON mvt.view_id = nt.view_id AND mvt.module_id = " + moduleID + " JOIN " + CTableNames.CODENODE_INSTRUCTIONS_TABLE + " AS cit ON nt.id = cit.node_id AND cit.module_id = " + moduleID + " JOIN " + CTableNames.INSTRUCTIONS_TABLE + " AS it ON it.address = cit.address AND it.module_id = " + moduleID + " WHERE it.address IN (");
        boolean needsComma = false;
        for (final UnrelocatedAddress address : addresses) {
            if (needsComma) {
                queryBuilder.append(", ");
            }
            needsComma = true;
            queryBuilder.append(address.getAddress().toLong());
        }
        queryBuilder.append(") GROUP BY mvt.view_id, mvt.module_id");
    }
    return PostgreSQLHelpers.getViewsWithAddress(provider.getConnection(), queryBuilder.toString(), "module_id", new CModuleViewFinder(provider));
}
Also used : UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) ArrayList(java.util.ArrayList) CModuleViewFinder(com.google.security.zynamics.binnavi.Database.CModuleViewFinder)

Example 74 with UnrelocatedAddress

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

the class CDebuggerFunctions method stepBlock.

/**
   * Lets the debugger step to the next block.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps to the next block.
   * @param graph The graph where the step operation happens.
   */
public static void stepBlock(final JFrame parent, final IDebugger debugger, final ZyGraph graph) {
    checkArguments(parent, debugger, graph);
    if (!debugger.isConnected()) {
        return;
    }
    final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
    if (activeThread == null) {
        return;
    }
    final RelocatedAddress currentAddress = activeThread.getCurrentAddress();
    if (currentAddress == null) {
        CMessageBox.showError(parent, "Could not step because the selected thread is not suspended");
        return;
    }
    final UnrelocatedAddress oldAddress = debugger.memoryToFile(currentAddress);
    final Set<BreakpointAddress> relocatedBlockAddresses = CStepBlockHelper.getNextBlocks(graph, oldAddress);
    if (relocatedBlockAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step to the next block");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        final Set<BreakpointAddress> setBreakpoints = new HashSet<BreakpointAddress>();
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
        setBreakpoints.addAll(relocatedBlockAddresses);
        try {
            debugger.resume();
        } catch (final DebugExceptionWrapper e) {
            // TODO: Step breakpoints should be removed at this point
            debugger.getProcessManager().setActiveThread(activeThread);
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00045: " + "Could not send step block command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step block command to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The state of the debugged process remains unchanged." });
            NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
        }
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) HashSet(java.util.HashSet)

Example 75 with UnrelocatedAddress

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

the class CDebuggerFunctions method stepOver.

/**
   * Lets the debugger step over the next instruction.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps over the next instruction.
   * @param graph The graph where the step operation happens.
   */
public static void stepOver(final JFrame parent, final IDebugger debugger, final ZyGraph graph) {
    checkArguments(parent, debugger, graph);
    if (!debugger.isConnected()) {
        return;
    }
    final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
    if (activeThread == null) {
        return;
    }
    final RelocatedAddress currentAddress = activeThread.getCurrentAddress();
    if (currentAddress == null) {
        CMessageBox.showError(parent, "Could not step because the selected thread is not suspended");
        return;
    }
    final UnrelocatedAddress oldAddress = debugger.memoryToFile(currentAddress);
    final Set<BreakpointAddress> relocatedAddresses = CStepOverHelper.getNextInstructions(graph, oldAddress);
    if (relocatedAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step over the current instruction");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedAddresses);
        try {
            debugger.resume();
        } catch (final DebugExceptionWrapper e) {
            // TODO: Step breakpoints should be removed at this point
            debugger.getProcessManager().setActiveThread(activeThread);
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00087: " + "Could not send step over command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step over command to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The state of the debugged process remains unchanged." });
            NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
        }
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)

Aggregations

UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)81 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)60 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)60 Test (org.junit.Test)49 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)28 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)15 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)15 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)13 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)12 ArrayList (java.util.ArrayList)11 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)10 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)9 HashSet (java.util.HashSet)9 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)8 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)8 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)8 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)8 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)8 CBreakpointTableModel (com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel)7 TraceLogger (com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger)7