mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-28 08:05:41 +08:00
GT-3619: Pattern Search Edit Bytes Input Mode fix
This commit is contained in:
+16
-2
@@ -128,6 +128,7 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis
|
|||||||
@Override
|
@Override
|
||||||
protected void dialogShown() {
|
protected void dialogShown() {
|
||||||
populateDialog();
|
populateDialog();
|
||||||
|
toFront();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************
|
/*********************************************************************************************
|
||||||
@@ -142,7 +143,7 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis
|
|||||||
protected JPanel createWorkPanel() {
|
protected JPanel createWorkPanel() {
|
||||||
|
|
||||||
JPanel contentPanel = new JPanel();
|
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.
|
// Create the input text widget and give it a scrollbar.
|
||||||
inputBytesTA = new HintTextAreaIS(HINT_TEXT);
|
inputBytesTA = new HintTextAreaIS(HINT_TEXT);
|
||||||
@@ -210,7 +211,6 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis
|
|||||||
// clicking the appropriate button.
|
// clicking the appropriate button.
|
||||||
inputBytesTA.setText(sb.toString());
|
inputBytesTA.setText(sb.toString());
|
||||||
selectionModeWidget.setInputMode(InputMode.BINARY);
|
selectionModeWidget.setInputMode(InputMode.BINARY);
|
||||||
selectionModeWidget.hexRB.doClick();
|
|
||||||
|
|
||||||
inputBytesTA.setSelectionStart(0);
|
inputBytesTA.setSelectionStart(0);
|
||||||
inputBytesTA.setSelectionEnd(inputBytesTA.getText().length());
|
inputBytesTA.setSelectionEnd(inputBytesTA.getText().length());
|
||||||
@@ -470,6 +470,20 @@ public class InsertBytesWidget extends DialogComponentProvider implements KeyLis
|
|||||||
return true;
|
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
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(KeyEvent e) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
|
|||||||
+10
-14
@@ -24,6 +24,7 @@ import javax.swing.*;
|
|||||||
|
|
||||||
import docking.widgets.button.GRadioButton;
|
import docking.widgets.button.GRadioButton;
|
||||||
import ghidra.app.plugin.core.instructionsearch.util.InstructionSearchUtils;
|
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}.
|
* 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
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
// If input is invalid, just exit.
|
|
||||||
if (!parent.validateInput()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're already in hex, do nothing.
|
// If we're already in hex, do nothing.
|
||||||
if (inputMode == InputMode.HEX) {
|
if (inputMode == InputMode.HEX) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputMode = InputMode.HEX;
|
inputMode = InputMode.HEX;
|
||||||
|
|
||||||
// CONVERSION
|
// CONVERSION
|
||||||
@@ -102,7 +97,7 @@ public class SelectionModeWidget extends ControlPanelWidget {
|
|||||||
groups = InstructionSearchUtils.getGroupSizes(parent.getInputString().trim(),
|
groups = InstructionSearchUtils.getGroupSizes(parent.getInputString().trim(),
|
||||||
InputMode.BINARY);
|
InputMode.BINARY);
|
||||||
|
|
||||||
// Now convert whatever is in the input box to binary.
|
// Now convert whatever is in the input box to hex.
|
||||||
String hexStr =
|
String hexStr =
|
||||||
InstructionSearchUtils.toHex(parent.getInputString().trim(), true);
|
InstructionSearchUtils.toHex(parent.getInputString().trim(), true);
|
||||||
|
|
||||||
@@ -114,8 +109,11 @@ public class SelectionModeWidget extends ControlPanelWidget {
|
|||||||
parent.setInputString(hexStr);
|
parent.setInputString(hexStr);
|
||||||
parent.validateInput();
|
parent.validateInput();
|
||||||
}
|
}
|
||||||
|
catch (NumberFormatException e2) {
|
||||||
|
parent.setInputInvalid();
|
||||||
|
}
|
||||||
catch (Exception e1) {
|
catch (Exception e1) {
|
||||||
e1.printStackTrace();
|
Msg.error(this, e1.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,11 +124,6 @@ public class SelectionModeWidget extends ControlPanelWidget {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
// If input is invalid, just exit.
|
|
||||||
if (!parent.validateInput()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're already in binary, do nothing.
|
// If we're already in binary, do nothing.
|
||||||
if (inputMode == InputMode.BINARY) {
|
if (inputMode == InputMode.BINARY) {
|
||||||
return;
|
return;
|
||||||
@@ -161,8 +154,11 @@ public class SelectionModeWidget extends ControlPanelWidget {
|
|||||||
parent.setInputString(binaryStr);
|
parent.setInputString(binaryStr);
|
||||||
parent.validateInput();
|
parent.validateInput();
|
||||||
}
|
}
|
||||||
|
catch (NumberFormatException e2) {
|
||||||
|
parent.setInputInvalid();
|
||||||
|
}
|
||||||
catch (Exception e1) {
|
catch (Exception e1) {
|
||||||
e1.printStackTrace();
|
Msg.error(this, e1.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user