略微调整查找

This commit is contained in:
寂静的羽夏 2021-08-23 18:18:17 +08:00
parent 49ca1b3b73
commit d1c46312b0
3 changed files with 35 additions and 47 deletions

View File

@ -16,8 +16,6 @@ namespace PEHexExplorer
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.CheckBox chkMatchCase;
private System.Windows.Forms.Timer timerPercent;
private System.Windows.Forms.Timer timer;
/// <summary>
/// Clean up any resources being used.
@ -40,7 +38,6 @@ namespace PEHexExplorer
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmFind));
this.txtFind = new System.Windows.Forms.TextBox();
this.rbString = new System.Windows.Forms.RadioButton();
@ -48,8 +45,6 @@ namespace PEHexExplorer
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.chkMatchCase = new System.Windows.Forms.CheckBox();
this.timerPercent = new System.Windows.Forms.Timer(this.components);
this.timer = new System.Windows.Forms.Timer(this.components);
this.hexFind = new Be.Windows.Forms.HexBox();
this.lblPercent = new System.Windows.Forms.Label();
this.lblFinding = new System.Windows.Forms.Label();
@ -118,15 +113,6 @@ namespace PEHexExplorer
this.chkMatchCase.Text = "匹配大小写";
this.chkMatchCase.UseVisualStyleBackColor = true;
//
// timerPercent
//
this.timerPercent.Tick += new System.EventHandler(this.TimerPercent_Tick);
//
// timer
//
this.timer.Interval = 50;
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
//
// hexFind
//
this.hexFind.BaseAddr = ((long)(0));
@ -150,6 +136,8 @@ namespace PEHexExplorer
this.hexFind.Name = "hexFind";
this.hexFind.Scaling = 1F;
this.hexFind.ShadowSelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(60)))), ((int)(((byte)(188)))), ((int)(((byte)(255)))));
this.hexFind.ShowBookMark = false;
this.hexFind.ShowBookMarkMain = false;
this.hexFind.ShowColumnInfoBackColor = true;
this.hexFind.ShowLineInfoBackColor = true;
this.hexFind.Size = new System.Drawing.Size(504, 159);

View File

@ -10,11 +10,28 @@ namespace PEHexExplorer
{
InitializeComponent();
hexFind.CreateBuffer();
UpDateUI = new Action(() =>
{
if (lblFinding.Text.Length == 13)
lblFinding.Text = "";
lblFinding.Text += ".";
//===========================
long pos = HexBox.CurrentFindingPosition;
long length = HexBox.ByteProvider.Length;
double percent = pos / (double)length * 100;
string text = percent.ToString("0.00") + " %";
lblPercent.Text = text;
});
}
private FindOptions _findOptions;
private FindOptions _findOptions = new FindOptions();
private bool _finding;
private static FrmFind frmFind = null;
private readonly Action UpDateUI;
public HexBox HexBox
{
@ -115,7 +132,6 @@ namespace PEHexExplorer
}
else // something was found
{
Close();
Application.DoEvents();
@ -126,8 +142,7 @@ namespace PEHexExplorer
private void UpdateUIToNormalState()
{
timer.Stop();
timerPercent.Stop();
UpDateUI.Invoke();
_finding = false;
txtFind.Enabled = chkMatchCase.Enabled = rbHex.Enabled = rbString.Enabled
= hexFind.Enabled = btnOK.Enabled = true;
@ -136,22 +151,27 @@ namespace PEHexExplorer
private void UpdateUIToFindingState()
{
_finding = true;
timer.Start();
timerPercent.Start();
UpDateUI.Invoke();
txtFind.Enabled = chkMatchCase.Enabled = rbHex.Enabled = rbString.Enabled
= hexFind.Enabled = btnOK.Enabled = false;
}
private void BtnOK_Click(object sender, EventArgs e)
{
if (rbString.Checked)
{
_findOptions.Type = FindType.Text;
_findOptions.Text = txtFind.Text;
_findOptions.MatchCase = chkMatchCase.Checked;
}
else
{
_findOptions.Type = FindType.Hex;
var provider = hexFind.ByteProvider as DynamicByteProvider;
_findOptions.Hex = provider.Bytes.ToArray();
var provider = hexFind.ByteProvider as DynamicByteProvider;
_findOptions.Hex = provider.Bytes.ToArray();
_findOptions.Text = txtFind.Text;
_findOptions.Type = rbHex.Checked ? FindType.Hex : FindType.Text;
_findOptions.MatchCase = chkMatchCase.Checked;
}
_findOptions.IsValid = true;
FindNext();
}
@ -165,21 +185,7 @@ namespace PEHexExplorer
private void TimerPercent_Tick(object sender, EventArgs e)
{
long pos = HexBox.CurrentFindingPosition;
long length = HexBox.ByteProvider.Length;
double percent = pos / (double)length * 100;
string text = percent.ToString("0.00") + " %";
lblPercent.Text = text;
}
private void Timer_Tick(object sender, EventArgs e)
{
if (lblFinding.Text.Length == 13)
lblFinding.Text = "";
lblFinding.Text += ".";
}
private void TxtString_TextChanged(object sender, EventArgs e)

View File

@ -117,12 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timerPercent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>168, 17</value>
</metadata>
<data name="hexFind.HexStringLinePen" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAE5CZS5XaW5kb3dzLkZvcm1zLkhleEJveCwgVmVyc2lvbj0xLjYu