diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryByteViewerComponent.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryByteViewerComponent.java
index 8bfade0898..f871a79c3f 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryByteViewerComponent.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryByteViewerComponent.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,7 +16,6 @@
package ghidra.app.plugin.core.debug.gui.memory;
import java.awt.Color;
-import java.awt.FontMetrics;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
@@ -118,9 +117,8 @@ public class DebuggerMemoryByteViewerComponent extends ByteViewerComponent
private final List Charsets are named mappings between byte sequences and Unicode code points. Common examples:
+ Charsets
+
+
+
+
The term "code point" denotes an integer that represents a character in the Unicode standard. + The first 127 code points map directly to the well-known ASCII characters.
+ +There are approximately 1.1 million defined code points in the Unicode standard.
+ +Unicode code points are grouped into categories called 'scripts'. For example, the Latin + script contains the well-known ABC..XYZ characters, the Common script contains numbers (0-9) and + punctuation, and the Greek script contains characters such as the delta 'Δ' symbol.
+ +Do not conflate a script (alphabet) with a human language, even though there can be some + correlation.
+ +The Unicode standard that Java implements has about 160 different scripts.
+ +The charset picker dialog allows the user to browse the available installed charsets + and select one to be used when decoding strings / character data.
+ +
+ The dialog has a table with the following columns:
+ +Name of the charset. Charsets not in the IANA Charset Registry will have a "x-" prefix
+ +A short description of the charset.
+ +Flag to indicate that the charset always uses a fixed number of bytes to encode a character.
+ +The minimum and maximum number of bytes that the charset uses to encoded a single character. + This value may include the length of escape sequences that typically only appear once in a + string.
+ +A list of the scripts (alphabets) that the charset can encode/decode characters for. For + example, US-ASCII can only produce Latin characters (along with ubiquitous Common characters), + whereas the UTF-8 charset can encoded characters for every script that the Unicode standard + supports.
+ +In the Details panel, the Scripts list also can contain a short snippet of example + characters from that script (if your font supports the script in question).
+ +Below the dialog's table is an area that displays the details of the charset, which + in addition to the information displayed in the table contains:
+ +For charsets where the bytes of encoded characters should be treated as a larger-than-byte + integer type (because they would have been specified as arrays of those integer types), this + field will specify the size of that integer. Currently, only UTF-16 and UTF-32 specify a + value for this setting.
+ + + +
+ * Call {@link #getSelectedCharset()} after the dialog closes to get the selected value.
+ */
+public class CharsetPickerDialog extends DialogComponentProvider {
+
+ /**
+ * Allows user to pick a charset from a table in a modal dialog.
+ *
+ * @param defaultCSI default charset to initially select in the table
+ * @return selected charset, or null if canceled
+ */
+ public static CharsetInfo pickCharset(CharsetInfo defaultCSI) {
+ CharsetPickerDialog dlg = new CharsetPickerDialog();
+ dlg.setSelectedCharset(defaultCSI);
+ DockingWindowManager.showDialog(dlg);
+ return dlg.getSelectedCharset();
+ }
+
+ private CharsetPickerPanel panel;
+ private CharsetInfo csi;
+
+ public CharsetPickerDialog() {
+ super("Pick Charset", true, false, true, false);
+
+ panel = new CharsetPickerPanel(null);
+ addWorkPanel(panel);
+ addOKButton();
+ addCancelButton();
+ setDefaultSize(800, 800);
+ setRememberLocation(false);
+ setHelpLocation(new HelpLocation("Charsets", "CharsetPicker"));
+ }
+
+ @Override
+ protected void okCallback() {
+ this.csi = panel.getSelectedCharset();
+ close();
+ }
+
+ @Override
+ protected void cancelCallback() {
+ this.csi = null;
+ super.cancelCallback();
+ }
+
+ public void setSelectedCharset(CharsetInfo csi) {
+ panel.setSelectedCharset(csi);
+ }
+
+ public CharsetInfo getSelectedCharset() {
+ return csi;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/util/charset/picker/CharsetPickerPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/util/charset/picker/CharsetPickerPanel.java
new file mode 100644
index 0000000000..5626cb3836
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/util/charset/picker/CharsetPickerPanel.java
@@ -0,0 +1,103 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.util.charset.picker;
+
+import java.awt.BorderLayout;
+import java.nio.charset.Charset;
+import java.util.function.Consumer;
+
+import javax.swing.*;
+import javax.swing.table.TableColumn;
+
+import ghidra.util.charset.CharsetInfo;
+import ghidra.util.table.GhidraTable;
+import ghidra.util.table.GhidraTableFilterPanel;
+
+/**
+ * JPanel that displays a table of all charsets on top and a detail panel on bottom.
+ */
+public class CharsetPickerPanel extends JPanel {
+
+ private GhidraTable table;
+ private CharsetTableModel tableModel = new CharsetTableModel();
+ private GhidraTableFilterPanel The Byte Viewer displays bytes in memory in various formats, e.g.,
- Hex, Ascii, Octal, etc. The figure below shows the Byte Viewer
+ Hex, Characters, Octal, etc. The figure below shows the Byte Viewer
plugin in a separate window from the
default
- tool, the Code Browser. The Byte Viewer
+The Byte Viewer


To show the Byte Viewer, select the icon,
,
- on the Code Browser toolbar, OR, choose the Window
Bytes: ... menu.
The following paragraphs describe the Byte Viewer.
+To show the Byte Viewer, select the icon,
,
+ on the Code Browser toolbar, OR, choose the Window
+
Bytes: ... menu.
The following paragraphs describe the Byte Viewer.
-This section describes the formats that Ghidra provides by - default. Each format is an instance of a DataFormatModel interface, - so any - new formats that you provide will automatically show up in the Byte Viewer Options dialog that - lists the data formats that - may be added to your view. To add or remove a data format view - from the tool, press the
+ default. Each format is an instance of a DataFormatModel interface, + so any new formats that you provide + will automatically show up in the Byte Viewer Options dialog that + lists the data formats that may be added to your view. + +- icon to bring up the Byte Viewer Options dialog. - Select the formats that you want and press the OK button.
-To add or remove a data format view from the tool, press the +
+icon to bring up the + Byte Viewer Options dialog. Select the formats that you want and press the + OK button.
--The Hex view shows each byte as a two character hex value. Hex +
+- -The Hex view shows each byte as a two character hex value. Change the group size for the Hex format to show - the bytes grouped in that size. When you add the Byte Viewer + the bytes grouped in that size. When you add the Byte Viewer plugin to a tool and then open a program, the Hex view is automatically - displayed by default.
+ displayed by default. -This view supports byte editing.
-Ascii
--+ +The Ascii view shows each byte as its equivalent Ascii character. - For those bytes that do not represent an Ascii character, the format shows +
This view supports byte editing.
+Chars
++- -The Chars view shows each byte (or group of bytes) as its equivalent + character, using a JVM installed charset. Typical examples will be US-ASCII + (1 byte per character), UTF-8 (between 1 and 3 bytes per character), UTF-16 + (typically 2 bytes per character, but can also require 4 bytes for some).
+ +For those bytes that do not encode a valid Unicode character, the view shows it as a tic (".").
-This view supports byte editing.
-Address
--+ +The Address view displays a tic (".") for all bytes whose + +
Some characters, though valid, will not be able to be displayed if the active + font does not support that character. Typically these characters are rendered + as a blank square or some other distinctive shape to indicate the issue.
+ +This view supports byte editing.
+Address
++- -The Address view displays a tic (".") for all bytes whose formed address does not fall within the range of memory for the program. For those addresses that can be formed and are in memory, the view shows the symbol,
- -- So if you go to that address in the Code Browser, and + So if you go to that address in the Code Browser, and make a Pointer data type, the address pointed to is in memory. Conversely, if you go to a "tic" address in the Code Browser and make a pointer, the - address pointed to is not in memory (the operand is - rendered in red).
This view does not support editing.
-Disassembled
--+ +The Disassemble view shows a "box" (
+ +) symbol for each address that has - undefined bytes. For those addresses that are instructions - or defined data, the - view - shows a tic ("."). With this view, you can easily see what areas of the + address pointed to is not in memory (the operand is rendered in red).
This view does not support editing.
+Disassembled
++- -The Disassemble view shows a "box" + (
-) symbol + for each address that has undefined bytes. For those addresses that are + instructions or + defined data, the + view shows a tic ("."). With this view, you can easily see what areas of the program have been disassembled.
This view does not support editing.
-Hex Short
--+ +This format shows two-byte numbers represented as an four-digit hex number.
-This view supports editing. When a byte - is changed, both bytes associated with this address are rendered in - red to denote the change.
-This view does not support editing.
+
--This format shows four-byte numbers represented as an eight-digit hex number.
-This view supports editing. When a byte +
Hex Short
+++ +This format shows two-byte numbers represented as an four-digit hex number.
+ +This view supports editing. When a byte is changed, + both bytes associated with this address are rendered in + red to denote the change.
+Hex Integer
+++ red to denote the change. +This format shows four-byte numbers represented as an eight-digit hex number.
+ +This view supports editing. When a byte is changed, all four bytes associated with this address are rendered in - red to denote the change.
-
--This format shows eight-byte numbers represented as an 16-digit hex number.
-This view supports editing. When a byte +
Hex Long
+++ red to denote the change. +This format shows eight-byte numbers represented as an 16-digit hex number.
+This view supports editing. When a byte is changed, all eight bytes associated with this address are rendered in - red to denote the change.
-
--This format shows 16-byte numbers represented as an 32-digit hex number.
-This view supports editing. When a byte +
Hex Long Long
+++ red to denote the change. +This format shows 16-byte numbers represented as an 32-digit hex number.
+ +This view supports editing. When a byte is changed, all 16 bytes associated with this address are rendered in - red to denote the change.
-
-- -This view shows four-byte numbers represented in decimal format.
-This view does not support editing.
-
-- -The octal view shows each byte as a three character octal value.
-This view supports editing.
-
-+The binary view shows each byte as an eight character binary value.
-This view supports editing.
-
++ +This view shows four-byte numbers represented in decimal format.
+ +This view does not support editing.
+
++ +The octal view shows each byte as a three character octal value.
+ +This view supports editing.
+
+The binary view shows each byte as an eight character binary value.
+ +This view supports editing.
+
--The labels below the scroll pane that contains the views shows the following information:
--
- -- -
+- -Start -The minimum address of Memory -- -End -The maximum address of Memory -- +Offset -Displayed in decimal, the + +The labels below the scroll pane that contains the views shows the following + information:
+++ This number is calculated when you set the alignment + offset or the number of bytes per line.+ +
-+ +Start +The minimum address of Memory ++ +End +The maximum address of Memory ++ -Offset +Displayed in decimal, the number of bytes added to each block of memory that is being displayed. - This number is calculated when you set the alignment - address or the number of bytes per line. -- - -Insertion -The address of your current cursor location -+ + +Insertion +The address of your current cursor location +
- -
-To enable byte editing,
--
-- Toggle the Enable/Disable Edit toolbar button
-- so that it appears pushed-in.
- Click in a view that supports editing, e.g., Hex or Ascii
-- The cursor changes to red to indicate that this view can be edited.
-Changing bytes is allowed only if your cursor is at an address - that does not contain an instruction. If you attempt to change a byte - of an instruction, an "editing not allowed" message is displayed in the - status area of the - tool.
+To enable byte editing,
++
+- Toggle the Enable/Disable Edit toolbar button +
+so that it appears pushed-in.
- Click in a view that supports editing, e.g., Hex or Chars
+- The cursor changes to red to indicate that this view can be edited.
+Changing bytes is allowed only if your cursor is at an address + that does not contain an instruction. If you attempt to change a byte + of an instruction, an "editing not allowed" message is displayed in the + status area of the tool.
-Changed bytes are rendered in red. - This color can be changed via the Byte Viewer Edit Options by double-clicking on - the Edit Color - field.
+Changed bytes are rendered in red. + This color can be changed via the + Byte Viewer Edit Options + by double-clicking on the Edit Color + field.
-Undo the edit by hitting the Undo button (
+ hitting the Redo button () on +
Undo the edit by hitting the Undo button (
) on the tool. The byte reverts to its original value. Redo your edit by - hitting the Redo button (
).
).
-To turn off byte editing, click the - Enable/Disable - Edit toolbar button
-- so that it no longer appears pushed-in.
If - you have two Byte Viewers running, you can connect +
To turn off byte editing, click the Enable/Disable Edit toolbar button +
+ +so that it no longer appears pushed-in.
+ changes in one Byte Viewer, the other will reflect those changes in red.
If you have two Byte Viewers running, you can + connect the two tools for the "Byte Block Edit" event so that when you make - changes - in one Byte Viewer, the other will reflect those changes in red.
The Byte
- Viewer Options dialog can be used to add and remove views, set the
- Alignment Address, set the
- number of bytes per line,
- and set the group size to be
- used by the hex view.
- To launch the Byte Viewer Options dialog,
- press the
icon on the Byte Viewer toolbar.
+-The Byte Viewer Options dialog can be + used to add and remove views, set the alignment offset, set the number + of bytes per line, and set the group size to be used by the hex + view.
+To launch the Byte Viewer Options dialog, + press the
+icon on the Byte Viewer toolbar.


-Alignment Address
--- -The alignment address specifies what address should appear in - column 0. Any address can be specified, but the address will be - normalized to be near the program's minimum address. This enables you to - view bytes in an offcut manner and to identify patterns in the bytes. - Changing the alignment address affects the offset, - which is the column that would display the bytes for address 0 if it - existed. - The offset is affected by both the alignment address and the bytes per - line. The offset is displayed as a label below the scroll - pane containing the views.
--
Sometimes - you might see a byte pattern such that you want all the bytes - to line up in the first column of the display. Consider the cursor - position in the image below. If you want to see the fourth column of - bytes (values of 00) to appear in the first column, you would enter an - alignment address of 0040b003, as indicated by your cursor position.
-
The result of setting the alignment address to 0040b003 - is shown below. The calculated offset is 13, the number of bytes added - to each memory block to create a new alignment. The first line of the - display shows the "remainder" bytes of 16 (bytes per line) divided by - 13, the offset. If you were to put your cursor on the starting byte of - the first line, you would see that your insertion point is 0040b000, in - this example.
--
Set Bytes Per Line
--The bytes per line indicates how many bytes are displayed in one - line in a view. The default value is 16.
-
- All formats shown must be able to support the new value. - For example, since the HexInteger and Integer formats show +
Bytes Per Line
++- -The bytes per line value indicates how many bytes are displayed in one + line in a view. The default value is 16.
+ +-
+ All formats shown must be able to support the new value. + For example, since the HexInteger and Integer formats show bytes in groups of four, the bytes per line must be a multiple of four. If a selected format cannot support a value for the bytes per line, an - error message will appear and the OK - button will be disabled.
Set Group Size
--+ +The group size is the number of bytes that the Hex view shows as + error message will appear and the OK button will be disabled.
++ Alignment Offset
+++ +The alignment offset controls which bytes should appear in column 0. This enables + you to view bytes in an offcut manner and to identify patterns in the bytes. + The offset is displayed as a label below the scroll pane containing the views.
+ ++ +
Sometimes + you might see a byte pattern such that you want all the bytes + to line up in the first column of the display. Consider the cursor position in the + image below:
+ +
If you want the fourth column of bytes (values of 00) to appear in + the first column, you need to decrease the alignment offset by 3, either by using + the Shift Bytes Left popup action (or hitting Ctrl+Comma) a few times, + or by changing the alignment offset value in the configuration dialog.
+ +The result of setting the alignment offset is shown below.
+ ++
Hex Group Size
++- -The group size is the number of bytes that the Hex view shows as a "unit." For example, a group size of two means to show two bytes - grouped together with no spaces.
-View Selection
--+ +Each potential view is listed as a checkbox. Select the - checkboxes corresponding to the views to be shown. Red text + grouped together with no spaces.
+Charset
+++ +This specifies how bytes are converted into characters. Typically + US-ASCII or UTF-8 are good choices, but other charsets + that are installed in your Java JVM will be available also.
+ +Character encoding schemes that use more than 1 byte to encode a + character are supported, but can produce incorrect values interlaced + with the actual text characters that should be there, as each byte is treated + as the starting position of a character, even if it was already 'used' by + a previous multi-byte character.
+ +For instance, if a sequence of UTF-8 characters are being displayed, and + some characters take 1 byte while some take 2 or 3, the positions in the + Chars display grid that are not valid starting locations may display + garbage, or just a "." dot indicating the byte could not be decoded.
+ +Character encoding schemes that rely on escape sequences to shift between + code pages will not produce useful values in the Chars display grid as + each byte (and some number of following bytes) are treated as a unique string + to decode and will not include any previous escape sequences that would be needed + to correctly decode the bytes in question.
+ +The available charsets are listed in a dialog that is displayed + when clicking the "..." browse button. You can filter by name, sizes, + supported scripts, etc by using the standard table filter mechanisms.
+Compact Char Width
+++ +This option toggles between wide and narrow display of characters. If + displaying ASCII or other Latin alphabet based text, the narrow option should + be sufficient to be able to see each character.
+ +If displaying data that has non-Latin alphabets (scripts) the wide option + will prevent characters from overwriting their neighbors.
+Use Char Alignment
+++ +This option will only display characters for fixed-width multi-byte character + sets (such as UTF-16, UTF-32) starting at aligned offsets, avoiding converting + bytes sequences that are not aligned with the charset alignment size.
+ +Use the alignment offset option to control + where the starting offset for aligned characters is located.
+ +NOTE: UTF-16 is not technically a fixed-width character encoding, as a + single character may need 2 or 4 bytes to be encoded. However, it is + self-synchronizing and the 2nd half of a 4 byte sequence should be ignored and + rendered as a "." dot.
+ +NOTE: An align-able charset needs to be marked with its alignment size in + the charset_info.json configuration file, and by default only UTF-16 and + UTF-32 have these values.
+View Selection
+++Each potential view is listed as a checkbox. Select the + checkboxes corresponding to the views to be shown. Red text indicates a view cannot be displayed since it doesn't support the specified number of bytes per line.
-
The various views in the ByteViewer can be reordered by dragging the view header to the left or right of its current position. The view - positions are swapped.
+ positions are swapped. +The width of each view can also be changed by dragging the separator bars in the view header to the left or right. This will resize the view that is to - the left of the separator bar.
+ the left of the separator bar.
--To supply your own format to be added to the list of views +
To supply your own format to be added to the list of views displayed in the Byte Viewer,
-
+ to add your class files to your classpath in your development environment. +- Write an implementation of the ghidra.app.plugin.core.format.DataFormatModel interface, - which determines the format of how the bytes should be - represented.
-- Edit your Plugin +
- Write an implementation of the ghidra.app.plugin.core.format.DataFormatModel interface, + which determines the format of how the bytes should be represented.
+- Edit your Plugin path to include your class files if you are running Ghidra in production mode versus development mode; in development mode, you will have - to add your class files to your classpath in your development - environment.
-- Restart Ghidra.
-Restart Ghidra. +
-
Provided by: Byte Viewer Plugin
- +Provided by: Byte Viewer Plugin
+ + +