Search in sources :

Example 31 with MemorySection

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection in project binnavi by google.

the class CMemoryViewerSynchronizerTest method testResizeSection.

@Test
public void testResizeSection() throws DebugExceptionWrapper {
    m_debugger.connect();
    m_debugger.getProcessManager().setAttached(true);
    m_debugger.getProcessManager().setMemoryMap(new MemoryMap(Lists.newArrayList(new MemorySection(new CAddress(0x100), new CAddress(0x1FF)))));
    m_model.setActiveMemoryAddress(new CAddress(0x100), false);
    assertEquals(0x100, m_hexView.getCurrentOffset());
    assertEquals(0x100, m_hexView.getData().getDataLength());
    m_debugger.getProcessManager().setMemoryMap(new MemoryMap(Lists.newArrayList(new MemorySection(new CAddress(0x100), new CAddress(0x1FF)), new MemorySection(new CAddress(0x500), new CAddress(0x5FF)))));
    assertEquals(0x100, m_hexView.getCurrentOffset());
    assertEquals(0x100, m_hexView.getData().getDataLength());
    m_debugger.getProcessManager().setMemoryMap(new MemoryMap(Lists.newArrayList(new MemorySection(new CAddress(0x0), new CAddress(0x2FF)), new MemorySection(new CAddress(0x500), new CAddress(0x5FF)))));
    assertEquals(0x100, m_hexView.getCurrentOffset());
    assertEquals(0x300, m_hexView.getData().getDataLength());
    final MockMemoryViewerSynchronizerListener listener = new MockMemoryViewerSynchronizerListener();
    m_synchronizer.addListener(listener);
    m_debugger.getProcessManager().setMemoryMap(new MemoryMap(Lists.newArrayList(new MemorySection(new CAddress(0x0), new CAddress(0xFF)), new MemorySection(new CAddress(0x500), new CAddress(0x5FF)))));
    assertEquals(0x000, m_hexView.getCurrentOffset());
    assertEquals(0x100, m_hexView.getData().getDataLength());
    assertEquals("addressTurnedInvalid;", listener.events);
    m_synchronizer.removeListener(listener);
    m_debugger.getProcessManager().setAttached(false);
    m_synchronizer.dispose();
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 32 with MemorySection

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection in project binnavi by google.

the class CMemoryViewerSynchronizerTest method testSwitchSection.

@Test
public void testSwitchSection() throws DebugExceptionWrapper {
    m_debugger.connect();
    m_debugger.getProcessManager().setAttached(true);
    m_debugger.getProcessManager().setMemoryMap(new MemoryMap(Lists.newArrayList(new MemorySection(new CAddress(0x100), new CAddress(0x1FF)), new MemorySection(new CAddress(0x200), new CAddress(0x4FF)))));
    m_model.setActiveMemoryAddress(new CAddress(0x400), false);
    assertEquals(0x400, m_hexView.getCurrentOffset());
    assertEquals(0x300, m_hexView.getData().getDataLength());
    m_model.setActiveMemoryAddress(new CAddress(0x100), false);
    assertEquals(0x100, m_hexView.getCurrentOffset());
    assertEquals(0x100, m_hexView.getData().getDataLength());
    m_debugger.getProcessManager().setAttached(false);
    m_synchronizer.dispose();
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 33 with MemorySection

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection in project binnavi by google.

the class CGotoDialog method dialogClosedOk.

/**
   * Does everything that is necessary if the user clicked the OK button.
   */
private void dialogClosedOk() {
    final String input = offsetField.getText();
    if (!"".equals(input)) {
        try {
            final MemoryExpressionElement expression = DebuggerMemoryExpressionParser.parse(input);
            final CEvaluationVisitor visitor = new CEvaluationVisitor(m_bindings);
            expression.visit(visitor);
            final BigInteger value = visitor.getValue(expression);
            if (value == null) {
                final String errors = Commafier.commafy(visitor.getErrorMessages(), "\n");
                CMessageBox.showError(m_parent, String.format("The expression you entered could not be evaluated:\n %s", errors));
            } else if (value.compareTo(BigInteger.ZERO) == -1 || value.toString(16).length() > 8) {
                // Negative or too long
                CMessageBox.showError(m_parent, String.format("The expression you entered evaluates to the invalid memory address %s.", value.toString(16).toUpperCase()));
            } else {
                final MemorySection section = ProcessHelpers.getSectionWith(m_memoryMap, new CAddress(value.longValue()));
                if (section == null) {
                    CMessageBox.showError(m_parent, String.format("There is no memory at address %s.", value.toString(16).toUpperCase()));
                } else {
                    m_value = new CAddress(value.longValue());
                    dispose();
                }
            }
        } catch (final RecognitionException exception) {
            CMessageBox.showError(m_parent, "Invalid expression string.");
        }
    }
}
Also used : MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) BigInteger(java.math.BigInteger) CEvaluationVisitor(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Implementations.CEvaluationVisitor) RecognitionException(org.antlr.runtime.RecognitionException) MemoryExpressionElement(com.google.security.zynamics.binnavi.debug.models.memoryexpressions.MemoryExpressionElement) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 34 with MemorySection

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection in project binnavi by google.

the class CMemoryViewerSynchronizer method resizeData.

/**
   * Adjusts size, base offset, and current offset of the hex view depending on a given address and
   * the memory sections known to the debugger.
   *
   * @param address The memory address to consider.
   *
   * @return True, if the hex view was adjusted. False, if the address is not in any known memory
   *         section.
   */
private boolean resizeData(final IAddress address) {
    if (address == null) {
        return true;
    }
    final IDebugger debugger = m_debugPerspectiveModel.getCurrentSelectedDebugger();
    if (debugger != null) {
        final MemorySection section = ProcessHelpers.getSectionWith(debugger.getProcessManager().getMemoryMap(), address);
        if (section == null) {
            // No section with the given memory address
            m_debugPerspectiveModel.setActiveMemoryAddress(null, false);
            return false;
        } else {
            m_hexView.setBaseAddress(section.getStart().toLong());
            m_provider.setMemorySize(section.getSize());
            m_hexView.gotoOffset(address.toLong());
            updateGui();
            return true;
        }
    }
    return true;
}
Also used : MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)

Example 35 with MemorySection

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection in project binnavi by google.

the class CRegisterMenuProvider method getRegisterMenu.

@Override
public JPopupMenu getRegisterMenu(final int registerNumber) {
    final IDebugger debugger = m_debugPerspectiveModel.getCurrentSelectedDebugger();
    if (debugger == null) {
        return null;
    }
    final JPopupMenu menu = new JPopupMenu();
    final BigInteger value = m_dataProvider.getRegisterInformation(registerNumber).getValue();
    menu.add(CActionProxy.proxy(new CCopyRegisterValueAction(value.toString(16).toUpperCase())));
    final MemorySection section = ProcessHelpers.getSectionWith(debugger.getProcessManager().getMemoryMap(), new CAddress(value));
    final JMenuItem gotoAddress = menu.add(CActionProxy.proxy(new CGotoOffsetAction(m_debugPerspectiveModel, new CAddress(value))));
    gotoAddress.setEnabled(section != null);
    if (containsAddress(m_debugPerspectiveModel.getGraphModel().getGraph().getRawView(), value.longValue())) {
        menu.add(CActionProxy.proxy(new CZoomToAddressAction(m_debugPerspectiveModel.getGraphModel().getGraph(), new CAddress(value), debugger.getModule(new RelocatedAddress(new CAddress(value))))));
    } else {
        final IViewContainer container = m_debugPerspectiveModel.getGraphModel().getViewContainer();
        menu.add(CActionProxy.proxy(new CSearchAction(m_debugPerspectiveModel.getGraphModel().getParent(), container, new CAddress(value))));
    }
    return menu;
}
Also used : CZoomToAddressAction(com.google.security.zynamics.binnavi.Gui.Debug.RegisterPanel.Actions.CZoomToAddressAction) CCopyRegisterValueAction(com.google.security.zynamics.binnavi.Gui.Debug.RegisterPanel.Actions.CCopyRegisterValueAction) IViewContainer(com.google.security.zynamics.binnavi.disassembly.views.IViewContainer) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) CGotoOffsetAction(com.google.security.zynamics.binnavi.Gui.Debug.RegisterPanel.Actions.CGotoOffsetAction) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BigInteger(java.math.BigInteger) CSearchAction(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CSearchAction) JMenuItem(javax.swing.JMenuItem) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) JPopupMenu(javax.swing.JPopupMenu) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Aggregations

MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)38 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)32 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)31 Test (org.junit.Test)27 MemoryMapReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply)19 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)18 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)17 ArrayList (java.util.ArrayList)17 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)16 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)16 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)16 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)14 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)13 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)7 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)6 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)6 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)6 BigInteger (java.math.BigInteger)6 DebuggerException (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException)4 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)4