【发布时间】:2019-06-29 16:46:58
【问题描述】:
我有一个 int key1 = -1466731422;,当我在十六进制编辑器中搜索它时,它会从 .exe 中返回十六进制值 62 74 93 A8。
我要做的是覆盖newKey1,用户可以选择它,覆盖key1。
假设我们想用int newKey1 = -1566731422 覆盖key1,到目前为止我所做的是:
private void btnGravar_Click(object sender, EventArgs e)
{
FixHex(key1, newKey1); //transform the int key in hex string
br = new BinaryReader(File.OpenRead(element.FileName));
try
{
for (long i = 0; i <= br.BaseStream.Length; i++)
{
if (br.BaseStream.ReadByte() == (byte)Convert.ToInt32(key1, 16))
{
progressBar.Value = progressBar.Maximum;
br.Close();
bw = new BinaryWriter(File.OpenWrite(element.FileName));
bw.BaseStream.Position = i;
bw.Write(newKey1);
bw.Close();
MessageBox.Show("Key updated", "Success");
break;
}
else
{
progressBar.Value += 1;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
它没有工作,但是。我的for 循环没有找到匹配项,所以我认为它会解决它是一种通过int key(因为在十六进制编辑器中我可以做到)或字符串格式的十六进制来查找地址的方法。
【问题讨论】:
-
您只比较一个字节而不是整个密钥。这会导致很多误报。
-
@itsme86:比较的两边只是一个字节,一个通过读取一个字节,另一个通过丢弃高位。
-
@BenVoigt 我的
FixHex方法返回给我:string key1 = "0x627493A8"和string newKey1 = "0x62939DA2"还有另一种方法可以将它与ReadByte进行比较? -
我不知道是否有帮助,但我也有一个包含每个十六进制对的列表...例如:
627493A8:: pairHex[0] = 62;对十六进制 [1] = 74;对十六进制 [2] = 93;等等。
标签: c# winforms binary hex byte