From eae73accf3ce5a8dfe2a056f6ad3fe62f13c052a Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 3 Sep 2012 01:17:03 +0000 Subject: [PATCH] Hex Editor - text option in Find Box, this feature converts text to its byte codes and searches that byte array --- BizHawk.MultiClient/tools/HexFind.Designer.cs | 33 ++++++++- BizHawk.MultiClient/tools/HexFind.cs | 71 ++++++++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/BizHawk.MultiClient/tools/HexFind.Designer.cs b/BizHawk.MultiClient/tools/HexFind.Designer.cs index 2aa9436506..e7ddbc2cfb 100644 --- a/BizHawk.MultiClient/tools/HexFind.Designer.cs +++ b/BizHawk.MultiClient/tools/HexFind.Designer.cs @@ -31,6 +31,8 @@ this.FindBox = new System.Windows.Forms.TextBox(); this.Find_Prev = new System.Windows.Forms.Button(); this.Find_Next = new System.Windows.Forms.Button(); + this.HexRadio = new System.Windows.Forms.RadioButton(); + this.TextRadio = new System.Windows.Forms.RadioButton(); this.SuspendLayout(); // // FindBox @@ -40,6 +42,7 @@ this.FindBox.Name = "FindBox"; this.FindBox.Size = new System.Drawing.Size(156, 20); this.FindBox.TabIndex = 0; + this.FindBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.FindBox_KeyPress); // // Find_Prev // @@ -61,11 +64,37 @@ this.Find_Next.UseVisualStyleBackColor = true; this.Find_Next.Click += new System.EventHandler(this.Find_Next_Click); // + // HexRadio + // + this.HexRadio.AutoSize = true; + this.HexRadio.Checked = true; + this.HexRadio.Location = new System.Drawing.Point(13, 69); + this.HexRadio.Name = "HexRadio"; + this.HexRadio.Size = new System.Drawing.Size(44, 17); + this.HexRadio.TabIndex = 3; + this.HexRadio.TabStop = true; + this.HexRadio.Text = "Hex"; + this.HexRadio.UseVisualStyleBackColor = true; + this.HexRadio.CheckedChanged += new System.EventHandler(this.HexRadio_CheckedChanged); + // + // TextRadio + // + this.TextRadio.AutoSize = true; + this.TextRadio.Location = new System.Drawing.Point(63, 69); + this.TextRadio.Name = "TextRadio"; + this.TextRadio.Size = new System.Drawing.Size(46, 17); + this.TextRadio.TabIndex = 4; + this.TextRadio.Text = "Text"; + this.TextRadio.UseVisualStyleBackColor = true; + this.TextRadio.CheckedChanged += new System.EventHandler(this.TextRadio_CheckedChanged); + // // HexFind // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(178, 77); + this.ClientSize = new System.Drawing.Size(178, 93); + this.Controls.Add(this.TextRadio); + this.Controls.Add(this.HexRadio); this.Controls.Add(this.Find_Next); this.Controls.Add(this.Find_Prev); this.Controls.Add(this.FindBox); @@ -84,5 +113,7 @@ private System.Windows.Forms.TextBox FindBox; private System.Windows.Forms.Button Find_Prev; private System.Windows.Forms.Button Find_Next; + private System.Windows.Forms.RadioButton HexRadio; + private System.Windows.Forms.RadioButton TextRadio; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/HexFind.cs b/BizHawk.MultiClient/tools/HexFind.cs index 604d3a9235..87a9a3fc48 100644 --- a/BizHawk.MultiClient/tools/HexFind.cs +++ b/BizHawk.MultiClient/tools/HexFind.cs @@ -31,17 +31,84 @@ namespace BizHawk.MultiClient private void HexFind_Load(object sender, EventArgs e) { if (location.X > 0 && location.Y > 0) + { this.Location = location; + } + } + + private string GetFindBoxChars() + { + if (String.IsNullOrWhiteSpace(FindBox.Text)) + { + return ""; + } + else if (HexRadio.Checked) + { + return FindBox.Text; + } + else + { + List bytes = new List(); + foreach (char c in FindBox.Text) + { + bytes.Add(Convert.ToByte(c)); + } + + StringBuilder bytestring = new StringBuilder(); + foreach (byte b in bytes) + { + bytestring.Append(String.Format("{0:X2}", b)); + } + + return bytestring.ToString(); + } } private void Find_Prev_Click(object sender, EventArgs e) { - Global.MainForm.HexEditor1.FindPrev(FindBox.Text); + Global.MainForm.HexEditor1.FindPrev(GetFindBoxChars()); } private void Find_Next_Click(object sender, EventArgs e) { - Global.MainForm.HexEditor1.FindNext(FindBox.Text); + Global.MainForm.HexEditor1.FindNext(GetFindBoxChars()); + } + + private void FindBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == '\b') + { + return; + } + else if (HexRadio.Checked) + { + if (!InputValidate.IsValidHexNumber(e.KeyChar)) + { + e.Handled = true; + } + } + } + + private void ChangeCasing() + { + if (HexRadio.Checked) + { + FindBox.CharacterCasing = CharacterCasing.Upper; + } + else + { + FindBox.CharacterCasing = CharacterCasing.Normal; + } + } + + private void HexRadio_CheckedChanged(object sender, EventArgs e) + { + ChangeCasing(); + } + + private void TextRadio_CheckedChanged(object sender, EventArgs e) + { + ChangeCasing(); } } }