From e3ed010914d422bdc1d390c847f8283cbdca1b4f Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Thu, 29 Sep 2022 19:30:45 -0400 Subject: [PATCH] GP-2662 - Paste hex in search memory window --- .../core/searchmem/MemSearchDialog.java | 30 +++++++++++-------- .../searchmem/MnemonicSearchPluginTest.java | 18 +++++------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchDialog.java index 5fc7396ede..c35997745d 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchDialog.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchDialog.java @@ -580,10 +580,10 @@ class MemSearchDialog extends DialogComponentProvider { memoryBlockGroup.add(loadedBlocks); memoryBlockGroup.add(allBlocks); - loadedBlocks.setToolTipText(HTMLUtilities.toHTML( - "Only searches memory blocks that are loaded in a running executable.\n " + - "Ghidra now includes memory blocks for other data such as section headers.\n" + - "This option exludes these OTHER (non loaded) blocks.")); + loadedBlocks.setToolTipText(HTMLUtilities + .toHTML("Only searches memory blocks that are loaded in a running executable.\n " + + "Ghidra now includes memory blocks for other data such as section headers.\n" + + "This option exludes these OTHER (non loaded) blocks.")); allBlocks.setToolTipText( "Searches all memory blocks including blocks that are not actually loaded in a running executable"); @@ -710,9 +710,9 @@ class MemSearchDialog extends DialogComponentProvider { public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { clearStatusText(); - // allow pasting numbers in the forms like 0xABC or ABCh + // allow pasting numbers in the forms like 0xABC or ABCh str = removeNumberBasePrefixAndSuffix(str); - + String currentText = getText(0, getLength()); String beforeOffset = currentText.substring(0, offs); String afterOffset = currentText.substring(offs, currentText.length()); @@ -791,28 +791,32 @@ class MemSearchDialog extends DialogComponentProvider { } return null; } - + private String removeNumberBasePrefixAndSuffix(String str) { - if (!(currentFormat instanceof HexSearchFormat || currentFormat instanceof BinarySearchFormat)) { + if (!(currentFormat instanceof HexSearchFormat || + currentFormat instanceof BinarySearchFormat)) { return str; } - + String numMaybe = str.strip(); String lowercase = numMaybe.toLowerCase(); if (currentFormat instanceof HexSearchFormat) { if (lowercase.startsWith("0x")) { numMaybe = numMaybe.substring(2); - } else if (lowercase.startsWith("$")) { + } + else if (lowercase.startsWith("$")) { numMaybe = numMaybe.substring(1); - } else if (lowercase.endsWith("h")) { + } + else if (lowercase.endsWith("h")) { numMaybe = numMaybe.substring(0, numMaybe.length() - 1); } - } else { + } + else { if (lowercase.startsWith("0b")) { numMaybe = numMaybe.substring(2); } } - + // check if the resultant number looks valid for insertion (i.e. not empty) if (!numMaybe.isEmpty()) { return numMaybe; diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/MnemonicSearchPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/MnemonicSearchPluginTest.java index 5421d1e47e..4d39a84f11 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/MnemonicSearchPluginTest.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/MnemonicSearchPluginTest.java @@ -15,8 +15,7 @@ */ package ghidra.app.plugin.core.searchmem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import java.awt.Container; import java.awt.Window; @@ -99,8 +98,7 @@ public class MnemonicSearchPluginTest extends AbstractGhidraHeadedIntegrationTes performAction(searchMnemonicOperandsNoConstAction, cb.getProvider(), true); - MemSearchDialog dialog = - waitForDialogComponent(tool.getToolFrame(), MemSearchDialog.class, 2000); + MemSearchDialog dialog = waitForDialogComponent(MemSearchDialog.class); assertNotNull(dialog); Container component = dialog.getComponent(); @@ -121,8 +119,7 @@ public class MnemonicSearchPluginTest extends AbstractGhidraHeadedIntegrationTes performAction(searchMnemonicNoOperandsNoConstAction, cb.getProvider(), true); - MemSearchDialog dialog = - waitForDialogComponent(tool.getToolFrame(), MemSearchDialog.class, 2000); + MemSearchDialog dialog = waitForDialogComponent(MemSearchDialog.class); assertNotNull(dialog); Container component = dialog.getComponent(); @@ -143,8 +140,7 @@ public class MnemonicSearchPluginTest extends AbstractGhidraHeadedIntegrationTes performAction(searchMnemonicOperandsConstAction, cb.getProvider(), true); - MemSearchDialog dialog = - waitForDialogComponent(tool.getToolFrame(), MemSearchDialog.class, 2000); + MemSearchDialog dialog = waitForDialogComponent(MemSearchDialog.class); assertNotNull(dialog); Container component = dialog.getComponent(); @@ -160,7 +156,7 @@ public class MnemonicSearchPluginTest extends AbstractGhidraHeadedIntegrationTes /** * Tests that when multiple regions are selected, the user is notified via * pop-up that this is not acceptable. - * + * */ @Test public void testMultipleSelection() { @@ -178,10 +174,10 @@ public class MnemonicSearchPluginTest extends AbstractGhidraHeadedIntegrationTes // Now invoke the menu option we want to test. performAction(searchMnemonicOperandsConstAction, cb.getProvider(), false); - // Here's the main assert: If the code recognizes that we have multiple selection, the + // Here's the main assert: If the code recognizes that we have multiple selection, the // MemSearchDialog will NOT be displayed (an error message pops up instead). So verify that // the dialog is null and we're ok. - Window errorDialog = waitForWindow("Mnemonic Search Error", 2000); + Window errorDialog = waitForWindow("Mnemonic Search Error"); assertNotNull(errorDialog); errorDialog.setVisible(false); }