diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/InsertBytesWidget.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/InsertBytesWidget.java index 6bbd3219c4..b98bb2e31b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/InsertBytesWidget.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/InsertBytesWidget.java @@ -128,6 +128,7 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis @Override protected void dialogShown() { populateDialog(); + toFront(); } /********************************************************************************************* @@ -142,7 +143,7 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis protected JPanel createWorkPanel() { JPanel contentPanel = new JPanel(); - contentPanel.setMinimumSize(new Dimension(300, 150)); + contentPanel.setMinimumSize(new Dimension(500, 300)); // Create the input text widget and give it a scrollbar. inputBytesTA = new HintTextAreaIS(HINT_TEXT); @@ -210,7 +211,6 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis // clicking the appropriate button. inputBytesTA.setText(sb.toString()); selectionModeWidget.setInputMode(InputMode.BINARY); - selectionModeWidget.hexRB.doClick(); inputBytesTA.setSelectionStart(0); inputBytesTA.setSelectionEnd(inputBytesTA.getText().length()); @@ -470,6 +470,20 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis return true; } + /** + * Flags the given string as invalid input + * + */ + public void setInputInvalid() { + inputBytesTA.setError(); + if (selectionModeWidget.getInputMode() == InputMode.BINARY) { + errorMsg = ERROR_MSG_BINARY_INPUT; + } + else { + errorMsg = ERROR_MSG_HEX_INPUT; + } + } + @Override public void keyTyped(KeyEvent e) { // Do nothing. diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/SelectionModeWidget.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/SelectionModeWidget.java index edbfbdaaf2..a36205124e 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/SelectionModeWidget.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/SelectionModeWidget.java @@ -24,6 +24,7 @@ import javax.swing.*; import docking.widgets.button.GRadioButton; import ghidra.app.plugin.core.instructionsearch.util.InstructionSearchUtils; +import ghidra.util.Msg; /** * Allows the user to specify whether the input mode is BINARY or HEX for the {@link InsertBytesWidget}. @@ -78,16 +79,10 @@ public class SelectionModeWidget extends ControlPanelWidget { @Override public void actionPerformed(ActionEvent e) { - // If input is invalid, just exit. - if (!parent.validateInput()) { - return; - } - // If we're already in hex, do nothing. if (inputMode == InputMode.HEX) { return; } - inputMode = InputMode.HEX; // CONVERSION @@ -102,7 +97,7 @@ public class SelectionModeWidget extends ControlPanelWidget { groups = InstructionSearchUtils.getGroupSizes(parent.getInputString().trim(), InputMode.BINARY); - // Now convert whatever is in the input box to binary. + // Now convert whatever is in the input box to hex. String hexStr = InstructionSearchUtils.toHex(parent.getInputString().trim(), true); @@ -114,8 +109,11 @@ public class SelectionModeWidget extends ControlPanelWidget { parent.setInputString(hexStr); parent.validateInput(); } + catch (NumberFormatException e2) { + parent.setInputInvalid(); + } catch (Exception e1) { - e1.printStackTrace(); + Msg.error(this, e1.getMessage()); } } @@ -126,11 +124,6 @@ public class SelectionModeWidget extends ControlPanelWidget { @Override public void actionPerformed(ActionEvent e) { - // If input is invalid, just exit. - if (!parent.validateInput()) { - return; - } - // If we're already in binary, do nothing. if (inputMode == InputMode.BINARY) { return; @@ -161,8 +154,11 @@ public class SelectionModeWidget extends ControlPanelWidget { parent.setInputString(binaryStr); parent.validateInput(); } + catch (NumberFormatException e2) { + parent.setInputInvalid(); + } catch (Exception e1) { - e1.printStackTrace(); + Msg.error(this, e1.getMessage()); } }