Search in sources :

Example 1 with Memory

use of com.google.security.zynamics.zylib.general.memmanager.Memory in project binnavi by google.

the class CMemoryFunctions method gotoOffset.

/**
   * Shows the Goto Offset dialog and sets the caret of a hex control to the entered offset.
   *
   * @param parent Parent window used for dialogs.
   * @param view Hex view to focus after the Goto operation.
   * @param model Model that contains the memory viewer where the offset is changed.
   */
public static void gotoOffset(final JFrame parent, final CMemoryViewer view, final CDebugPerspectiveModel model) {
    final IDebugger debugger = model.getCurrentSelectedDebugger();
    if (debugger == null) {
        return;
    }
    final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
    final Memory memory = debugger.getProcessManager().getMemory();
    final CDefaultMemoryExpressionBinding binding = new CDefaultMemoryExpressionBinding(activeThread, memory);
    final CGotoDialog dlg = new CGotoDialog(parent, model.getCurrentSelectedDebugger().getProcessManager().getMemoryMap(), binding, model.getGotoAddress());
    dlg.setVisible(true);
    final IAddress value = dlg.getValue();
    if (value != null) {
        model.setGotoAddress(value);
        model.setActiveMemoryAddress(value, true);
        view.requestFocusInWindow();
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) Memory(com.google.security.zynamics.zylib.general.memmanager.Memory) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) CGotoDialog(com.google.security.zynamics.binnavi.Gui.Debug.Goto.CGotoDialog) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 2 with Memory

use of com.google.security.zynamics.zylib.general.memmanager.Memory in project binnavi by google.

the class MemoryLoader method requestMemory.

/**
   * Request a chunk of memory of the target process.
   *
   * @param offset The start offset of the memory chunk.
   * @param size The number of bytes to load.
   *
   * @throws DebugExceptionWrapper Thrown if the request could not be send to the debug client.
   */
public void requestMemory(final IAddress offset, final int size) throws DebugExceptionWrapper {
    Preconditions.checkNotNull(offset, "IE00814: Offset can nott be null");
    Preconditions.checkArgument(size > 9, "IE00815: Size must be positive");
    // Don't issue multiple requests for the same memory chunk.
    final Pair<IAddress, Long> pair = new Pair<IAddress, Long>(offset, (long) size);
    if (lastMemoryRequest.contains(pair)) {
        return;
    }
    lastMemoryRequest.add(pair);
    // Don't reload the entire memory chunk. Some parts of the memory may
    // already exist in the simulated memory.
    final Memory memory = debugger.getProcessManager().getMemory();
    for (int i = 0; i < size; ) {
        final long secstart = memory.getSectionStart(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue());
        final long secsize = memory.getSectionSize(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue());
        long toLoad = (secstart + secsize) - (offset.toBigInteger().add(BigInteger.valueOf(i))).longValue();
        if (toLoad > (size - i)) {
            toLoad = size - i;
        }
        final boolean alloced = memory.hasData(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue(), 1);
        if (!alloced && debugger.isConnected()) {
            // Request the memory for the missing section.
            debugger.readMemory(new CAddress(offset.toBigInteger().add(BigInteger.valueOf(i))), (int) toLoad);
        }
        i += toLoad;
    }
}
Also used : Memory(com.google.security.zynamics.zylib.general.memmanager.Memory) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) Pair(com.google.security.zynamics.zylib.general.Pair) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Aggregations

IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)2 Memory (com.google.security.zynamics.zylib.general.memmanager.Memory)2 CGotoDialog (com.google.security.zynamics.binnavi.Gui.Debug.Goto.CGotoDialog)1 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)1 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)1 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)1 Pair (com.google.security.zynamics.zylib.general.Pair)1