Search in sources :

Example 1 with JHexView

use of com.google.security.zynamics.zylib.gui.JHexPanel.JHexView in project binnavi by google.

the class CMemoryFunctions method searchMemory.

/**
 * Shows a Search dialog and searches through the memory of target process afterwards.
 *
 * @param parent Parent window used for dialogs.
 * @param debugger Debugger that requests the target memory.
 * @param memoryView Memory view where the search result is shown.
 */
public static void searchMemory(final Window parent, final IDebugger debugger, final CMemoryViewer memoryView) {
    checkArguments(parent, debugger);
    Preconditions.checkNotNull(memoryView, "IE01431: Memory view argument can not be null");
    // Show the search dialog
    final CSearchDialog dlg = new CSearchDialog(parent);
    final byte[] data = dlg.getSearchData();
    // Make sure that the user entered data and clicked the OK button
    if (data != null && data.length != 0) {
        final JHexView hexView = memoryView.getHexView();
        final long start = hexView.getCurrentOffset();
        final int size = (int) (hexView.getLastOffset() - hexView.getCurrentOffset());
        final CSearchWaiter waiter = new CSearchWaiter(debugger, new CAddress(start), size, data);
        CProgressDialog.showEndless(parent, "Loading memory" + " ...", waiter);
        hexView.uncolorizeAll();
        if (waiter.getException() == null) {
            final SearchReply reply = waiter.getReply();
            if (reply != null) {
                final IAddress offset = reply.getAddress();
                if (reply.success()) {
                    // Make sure that the memory data is actually available
                    if (hexView.isEnabled() && hexView.getDefinitionStatus() == DefinitionStatus.DEFINED) {
                        // It is not necessary to make sure that the offset is
                        // actually part of the currently visible memory range.
                        // If it is not, the new memory range is loaded automatically.
                        hexView.colorize(5, offset.toLong(), data.length, Color.BLACK, Color.YELLOW);
                        hexView.gotoOffset(offset.toLong());
                        hexView.requestFocusInWindow();
                    }
                } else {
                    // Tell the user that the search string was not found
                    CMessageBox.showInformation(parent, "The specified search string was not found.");
                }
            }
        } else {
            CUtilityFunctions.logException(waiter.getException());
            final String innerMessage = "E00079: " + "Could not search through memory";
            final String innerDescription = CUtilityFunctions.createDescription("It was not possible to send the search request to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The search operation could not be started." });
            NaviErrorDialog.show(parent, innerMessage, innerDescription, waiter.getException());
        }
    }
}
Also used : JHexView(com.google.security.zynamics.zylib.gui.JHexPanel.JHexView) CSearchDialog(com.google.security.zynamics.binnavi.Gui.Debug.SearchMemory.CSearchDialog) SearchReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SearchReply) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 2 with JHexView

use of com.google.security.zynamics.zylib.gui.JHexPanel.JHexView in project binnavi by google.

the class CMemoryViewerSynchronizerTest method testNewThread.

/**
 * This test makes sure that the synchronizer can handle new threads.
 *
 * Fix for Case 2036: Listener issue in the memory viewer
 */
@Test
public void testNewThread() {
    final IGraphModel graphModel = new MockGraphModel();
    final CDebugPerspectiveModel model = new CDebugPerspectiveModel(graphModel);
    final JHexView hexView = new JHexView();
    final CMemoryProvider provider = new CMemoryProvider();
    model.setActiveDebugger(m_debugger);
    final TargetProcessThread thread = new TargetProcessThread(0, ThreadState.RUNNING);
    m_debugger.getProcessManager().addThread(thread);
    m_debugger.getProcessManager().setActiveThread(thread);
    final CMemoryViewerSynchronizer synchronizer = new CMemoryViewerSynchronizer(hexView, provider, model);
    synchronizer.dispose();
}
Also used : CDebugPerspectiveModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.Panels.CDebugPerspectiveModel) JHexView(com.google.security.zynamics.zylib.gui.JHexPanel.JHexView) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) IGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.IGraphModel) MockGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.MockGraphModel) Test(org.junit.Test)

Example 3 with JHexView

use of com.google.security.zynamics.zylib.gui.JHexPanel.JHexView in project binnavi by google.

the class CMemoryViewerSynchronizerTest method testActiveDebugger.

@Test
public void testActiveDebugger() {
    final IGraphModel graphModel = new MockGraphModel();
    final CDebugPerspectiveModel model = new CDebugPerspectiveModel(graphModel);
    final JHexView hexView = new JHexView();
    final CMemoryProvider provider = new CMemoryProvider();
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    model.setActiveDebugger(debugger);
    final CMemoryViewerSynchronizer synchronizer = new CMemoryViewerSynchronizer(hexView, provider, model);
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    assertEquals(AddressMode.BIT32, hexView.getAddressMode());
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(64, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    assertEquals(AddressMode.BIT64, hexView.getAddressMode());
    synchronizer.dispose();
}
Also used : CDebugPerspectiveModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.Panels.CDebugPerspectiveModel) JHexView(com.google.security.zynamics.zylib.gui.JHexPanel.JHexView) IGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.IGraphModel) ArrayList(java.util.ArrayList) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) MockGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.MockGraphModel) Test(org.junit.Test)

Aggregations

JHexView (com.google.security.zynamics.zylib.gui.JHexPanel.JHexView)3 IGraphModel (com.google.security.zynamics.binnavi.Gui.GraphWindows.IGraphModel)2 MockGraphModel (com.google.security.zynamics.binnavi.Gui.GraphWindows.MockGraphModel)2 CDebugPerspectiveModel (com.google.security.zynamics.binnavi.Gui.GraphWindows.Panels.CDebugPerspectiveModel)2 Test (org.junit.Test)2 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)1 CSearchDialog (com.google.security.zynamics.binnavi.Gui.Debug.SearchMemory.CSearchDialog)1 SearchReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.SearchReply)1 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)1 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)1 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)1 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)1 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)1 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)1 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 ArrayList (java.util.ArrayList)1