Hex Editor - add Copy/Paste functions
This commit is contained in:
parent
646a6c1c58
commit
bac863aa70
|
@ -35,6 +35,10 @@
|
|||
this.dumpToFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.pasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.findToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.memoryDomainsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.dataSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
|
@ -47,7 +51,6 @@
|
|||
this.addToRamWatchToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.freezeAddressToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.unfreezeAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.findToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveWindowsSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
|
@ -65,6 +68,7 @@
|
|||
this.MemoryViewerBox = new System.Windows.Forms.GroupBox();
|
||||
this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
|
||||
this.AddressesLabel = new System.Windows.Forms.Label();
|
||||
this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.ViewerContextMenuStrip.SuspendLayout();
|
||||
this.MemoryViewerBox.SuspendLayout();
|
||||
|
@ -74,6 +78,7 @@
|
|||
//
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.fileToolStripMenuItem,
|
||||
this.editToolStripMenuItem,
|
||||
this.optionsToolStripMenuItem,
|
||||
this.settingsToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
|
@ -113,6 +118,41 @@
|
|||
this.exitToolStripMenuItem.Text = "E&xit";
|
||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||
//
|
||||
// editToolStripMenuItem
|
||||
//
|
||||
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.copyToolStripMenuItem,
|
||||
this.pasteToolStripMenuItem,
|
||||
this.toolStripSeparator6,
|
||||
this.findToolStripMenuItem1});
|
||||
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
|
||||
this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20);
|
||||
this.editToolStripMenuItem.Text = "&Edit";
|
||||
//
|
||||
// copyToolStripMenuItem
|
||||
//
|
||||
this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
|
||||
this.copyToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C)));
|
||||
this.copyToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.copyToolStripMenuItem.Text = "&Copy";
|
||||
this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click);
|
||||
//
|
||||
// pasteToolStripMenuItem
|
||||
//
|
||||
this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem";
|
||||
this.pasteToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V)));
|
||||
this.pasteToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.pasteToolStripMenuItem.Text = "&Paste";
|
||||
this.pasteToolStripMenuItem.Click += new System.EventHandler(this.pasteToolStripMenuItem_Click);
|
||||
//
|
||||
// findToolStripMenuItem1
|
||||
//
|
||||
this.findToolStripMenuItem1.Name = "findToolStripMenuItem1";
|
||||
this.findToolStripMenuItem1.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F)));
|
||||
this.findToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
|
||||
this.findToolStripMenuItem1.Text = "&Find...";
|
||||
this.findToolStripMenuItem1.Click += new System.EventHandler(this.findToolStripMenuItem1_Click);
|
||||
//
|
||||
// optionsToolStripMenuItem
|
||||
//
|
||||
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
|
@ -121,7 +161,6 @@
|
|||
this.enToolStripMenuItem,
|
||||
this.toolStripSeparator2,
|
||||
this.goToAddressToolStripMenuItem,
|
||||
this.findToolStripMenuItem,
|
||||
this.addToRamWatchToolStripMenuItem1,
|
||||
this.freezeAddressToolStripMenuItem,
|
||||
this.unfreezeAllToolStripMenuItem});
|
||||
|
@ -215,14 +254,6 @@
|
|||
this.unfreezeAllToolStripMenuItem.Text = "Unfreeze All";
|
||||
this.unfreezeAllToolStripMenuItem.Click += new System.EventHandler(this.unfreezeAllToolStripMenuItem_Click);
|
||||
//
|
||||
// findToolStripMenuItem
|
||||
//
|
||||
this.findToolStripMenuItem.Name = "findToolStripMenuItem";
|
||||
this.findToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F)));
|
||||
this.findToolStripMenuItem.Size = new System.Drawing.Size(219, 22);
|
||||
this.findToolStripMenuItem.Text = "&Find...";
|
||||
this.findToolStripMenuItem.Click += new System.EventHandler(this.findToolStripMenuItem_Click);
|
||||
//
|
||||
// settingsToolStripMenuItem
|
||||
//
|
||||
this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
|
@ -380,6 +411,11 @@
|
|||
this.AddressesLabel.MouseLeave += new System.EventHandler(this.AddressesLabel_MouseLeave);
|
||||
this.AddressesLabel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.AddressesLabel_MouseMove);
|
||||
//
|
||||
// toolStripSeparator6
|
||||
//
|
||||
this.toolStripSeparator6.Name = "toolStripSeparator6";
|
||||
this.toolStripSeparator6.Size = new System.Drawing.Size(149, 6);
|
||||
//
|
||||
// HexEditor
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -444,6 +480,10 @@
|
|||
private System.Windows.Forms.ToolStripMenuItem decrementToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem gotoAddressToolStripMenuItem1;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
|
||||
private System.Windows.Forms.ToolStripMenuItem findToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem pasteToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem findToolStripMenuItem1;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator6;
|
||||
}
|
||||
}
|
|
@ -44,7 +44,8 @@ namespace BizHawk.MultiClient
|
|||
const int fontWidth = 7; //Width of 1 digits
|
||||
|
||||
bool loaded = false;
|
||||
// Configurations
|
||||
|
||||
// Configurations
|
||||
bool AutoLoad;
|
||||
bool SaveWindowPosition;
|
||||
int Wndx = -1;
|
||||
|
@ -1037,6 +1038,11 @@ namespace BizHawk.MultiClient
|
|||
return;
|
||||
}
|
||||
|
||||
if (e.Control || e.Shift || e.Alt) //If user is pressing one of these, don't type into the hex editor
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (DataSize)
|
||||
{
|
||||
default:
|
||||
|
@ -1279,7 +1285,19 @@ namespace BizHawk.MultiClient
|
|||
GoToSpecifiedAddress();
|
||||
}
|
||||
|
||||
private void findToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private string GetHighlightedValue()
|
||||
{
|
||||
if (addressHighlighted != -1)
|
||||
{
|
||||
return String.Format(DigitFormatString, (int)MakeValue(addressHighlighted)).Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private void Find()
|
||||
{
|
||||
InputPrompt prompt = new InputPrompt();
|
||||
prompt.SetMessage("Enter a set of hex values to search for");
|
||||
|
@ -1287,13 +1305,11 @@ namespace BizHawk.MultiClient
|
|||
prompt.HexOnly = true;
|
||||
if (addressHighlighted > 0)
|
||||
{
|
||||
string initial = String.Format(DigitFormatString, (int)MakeValue(addressHighlighted));
|
||||
initial = initial.Trim();
|
||||
prompt.SetInitialValue(initial);
|
||||
prompt.SetInitialValue(GetHighlightedValue());
|
||||
}
|
||||
prompt.ShowDialog();
|
||||
|
||||
|
||||
|
||||
if (prompt.UserOK)
|
||||
{
|
||||
int found = 0;
|
||||
|
@ -1303,7 +1319,7 @@ namespace BizHawk.MultiClient
|
|||
return;
|
||||
|
||||
int numByte = search.Length / 2;
|
||||
|
||||
|
||||
int startByte = 0;
|
||||
if (addressHighlighted == -1)
|
||||
{
|
||||
|
@ -1336,7 +1352,7 @@ namespace BizHawk.MultiClient
|
|||
if (found > 0)
|
||||
{
|
||||
GoToAddress(found);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1344,5 +1360,46 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string value = GetHighlightedValue();
|
||||
if (!String.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
Clipboard.SetDataObject(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
IDataObject iData = Clipboard.GetDataObject();
|
||||
|
||||
if (iData.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
string clipboardRaw = (String)iData.GetData(DataFormats.Text);
|
||||
string hex = InputValidate.DoHexString(clipboardRaw);
|
||||
|
||||
int numBytes = hex.Length / 2;
|
||||
for (int i = 0; i < numBytes; i++)
|
||||
{
|
||||
int value = int.Parse(hex.Substring(i * 2, 2), NumberStyles.HexNumber);
|
||||
int address = addressHighlighted + i;
|
||||
Domain.PokeByte(address, (byte)value);
|
||||
}
|
||||
UpdateValues();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
private void findToolStripMenuItem1_Click(object sender, EventArgs e)
|
||||
{
|
||||
Find();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,127 +5,150 @@ using System.Text;
|
|||
|
||||
namespace BizHawk
|
||||
{
|
||||
/// <summary>
|
||||
/// Includes helper functions to validate user input
|
||||
/// </summary>
|
||||
public static class InputValidate
|
||||
{
|
||||
public static bool IsValidUnsignedNumber(string Str)
|
||||
{
|
||||
char[] input = (Str.ToCharArray());
|
||||
ASCIIEncoding AE = new ASCIIEncoding();
|
||||
// Check each character in the new label to determine if it is a number.
|
||||
for (int x = 0; x < input.Length; x++)
|
||||
{
|
||||
// Encode the character from the character array to its ASCII code.
|
||||
byte[] bc = AE.GetBytes(input[x].ToString());
|
||||
/// <summary>
|
||||
/// Includes helper functions to validate user input
|
||||
/// </summary>
|
||||
public static class InputValidate
|
||||
{
|
||||
public static bool IsValidUnsignedNumber(string Str)
|
||||
{
|
||||
char[] input = (Str.ToCharArray());
|
||||
ASCIIEncoding AE = new ASCIIEncoding();
|
||||
// Check each character in the new label to determine if it is a number.
|
||||
for (int x = 0; x < input.Length; x++)
|
||||
{
|
||||
// Encode the character from the character array to its ASCII code.
|
||||
byte[] bc = AE.GetBytes(input[x].ToString());
|
||||
|
||||
// Determine if the ASCII code is within the valid range of numerical values.
|
||||
if (bc[0] < 47 || bc[0] > 58)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Determine if the ASCII code is within the valid range of numerical values.
|
||||
if (bc[0] < 47 || bc[0] > 58)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsValidUnsignedNumber(char c)
|
||||
{
|
||||
if (c < 47 || c > 58)
|
||||
return false;
|
||||
public static bool IsValidUnsignedNumber(char c)
|
||||
{
|
||||
if (c < 47 || c > 58)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates all chars are 0-9 or a dash as the first value
|
||||
/// </summary>
|
||||
/// <param name="Str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidSignedNumber(string Str)
|
||||
{
|
||||
char[] input = (Str.ToCharArray());
|
||||
ASCIIEncoding AE = new ASCIIEncoding();
|
||||
// Check each character in the new label to determine if it is a number.
|
||||
for (int x = 0; x < input.Length; x++)
|
||||
{
|
||||
// Encode the character from the character array to its ASCII code.
|
||||
byte[] bc = AE.GetBytes(input[x].ToString());
|
||||
/// <summary>
|
||||
/// Validates all chars are 0-9 or a dash as the first value
|
||||
/// </summary>
|
||||
/// <param name="Str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidSignedNumber(string Str)
|
||||
{
|
||||
char[] input = (Str.ToCharArray());
|
||||
ASCIIEncoding AE = new ASCIIEncoding();
|
||||
// Check each character in the new label to determine if it is a number.
|
||||
for (int x = 0; x < input.Length; x++)
|
||||
{
|
||||
// Encode the character from the character array to its ASCII code.
|
||||
byte[] bc = AE.GetBytes(input[x].ToString());
|
||||
|
||||
// Determine if the ASCII code is within the valid range of numerical values.
|
||||
if (bc[0] > 58)
|
||||
return false;
|
||||
// Determine if the ASCII code is within the valid range of numerical values.
|
||||
if (bc[0] > 58)
|
||||
return false;
|
||||
|
||||
if (bc[0] < 47)
|
||||
{
|
||||
if (bc[0] == 45 && x == 0)
|
||||
continue;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (bc[0] < 47)
|
||||
{
|
||||
if (bc[0] == 45 && x == 0)
|
||||
continue;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsValidSignedNumber(char c)
|
||||
{
|
||||
if (c == 45) return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (c < 47 || c > 58)
|
||||
return false;
|
||||
public static bool IsValidSignedNumber(char c)
|
||||
{
|
||||
if (c == 45) return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
if (c < 47 || c > 58)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// validates is a Hex number 0-9, A-F (must be capital letters)
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidHexNumber(string Str)
|
||||
{
|
||||
char[] input = (Str.ToCharArray());
|
||||
ASCIIEncoding AE = new ASCIIEncoding();
|
||||
// Check each character in the new label to determine if it is a number.
|
||||
for (int x = 0; x < input.Length; x++)
|
||||
{
|
||||
// Encode the character from the character array to its ASCII code.
|
||||
byte[] bc = AE.GetBytes(input[x].ToString());
|
||||
/// <summary>
|
||||
/// validates is a Hex number 0-9, A-F (must be capital letters)
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidHexNumber(string Str)
|
||||
{
|
||||
char[] input = (Str.ToCharArray());
|
||||
ASCIIEncoding AE = new ASCIIEncoding();
|
||||
// Check each character in the new label to determine if it is a number.
|
||||
for (int x = 0; x < input.Length; x++)
|
||||
{
|
||||
// Encode the character from the character array to its ASCII code.
|
||||
byte[] bc = AE.GetBytes(input[x].ToString());
|
||||
|
||||
// Determine if the ASCII code is within the valid range of numerical values.
|
||||
if (bc[0] < 47) //0
|
||||
return false;
|
||||
if (bc[0] > 58) //9
|
||||
{
|
||||
if (bc[0] < 65) //A
|
||||
return false;
|
||||
// Determine if the ASCII code is within the valid range of numerical values.
|
||||
if (bc[0] < 47) //0
|
||||
return false;
|
||||
if (bc[0] > 58) //9
|
||||
{
|
||||
if (bc[0] < 65) //A
|
||||
return false;
|
||||
|
||||
if (bc[0] > 70) //F
|
||||
{
|
||||
if (bc[0] < 97 || bc[0] > 102) //a-f
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (bc[0] > 70) //F
|
||||
{
|
||||
if (bc[0] < 97 || bc[0] > 102) //a-f
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsValidHexNumber(char c)
|
||||
{
|
||||
if (c < 47) return false; //0
|
||||
public static bool IsValidHexNumber(char c)
|
||||
{
|
||||
if (c < 47) return false; //0
|
||||
|
||||
if (c > 58) //9
|
||||
{
|
||||
if (c < 65) //A
|
||||
return false;
|
||||
if (c > 58) //9
|
||||
{
|
||||
if (c < 65) //A
|
||||
return false;
|
||||
|
||||
if (c > 70) //F
|
||||
{
|
||||
if (c < 97 || c > 102) //a-f
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (c > 70) //F
|
||||
{
|
||||
if (c < 97 || c > 102) //a-f
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes any string and removes any value that is not a valid hex value (0-9, a-f, A-F), returns the remaining characters in uppercase
|
||||
/// </summary>
|
||||
/// <param name="raw"></param>
|
||||
/// <returns></returns>
|
||||
public static string DoHexString(string raw)
|
||||
{
|
||||
raw = raw.ToUpper();
|
||||
StringBuilder output = new StringBuilder();
|
||||
foreach (char x in raw)
|
||||
{
|
||||
if (x >= 'A' && x <= 'F')
|
||||
{
|
||||
output.Append(x);
|
||||
}
|
||||
else if (x >= '0' && x <= '9')
|
||||
{
|
||||
output.Append(x);
|
||||
}
|
||||
}
|
||||
return output.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue