简体   繁体   English

C# BinaryWriter 搜索

[英]C# BinaryWriter Seek

i have some error in my code i need any one to help me please :)我的代码中有一些错误,我需要任何人来帮助我:)

i have offset and when i try to patch it with C# i get a strange result我有偏移,当我尝试用 C# 修补它时,我得到了一个奇怪的结果

this.openFileDialog1.FileName = "Sro_Client.exe";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
    FileStream output = new FileStream(this.openFileDialog1.FileName
                                       , FileMode.Open);
    BinaryWriter writer = new BinaryWriter(output);
    byte[] bytes = new byte[] { byte.Parse(this.textBox1.Text) };
    byte[] buffer = new byte[] { Convert.ToByte(this.textBox1.Text) };
    writer.Seek(0x135FB3, SeekOrigin.Begin);
    writer.Write(bytes, 0, 1);
    writer.Close();
    MessageBox.Show("Successfully patched Sro_Client.exe.");
}

the original offset is PUSH 6E , so my program must change it when i write in textbox1 like 90 convert it to hex like this website and change it to : PUSH 5a原始偏移量是 PUSH 6E ,因此当我在 textbox1 中写入时,我的程序必须更改它,例如 90 将其转换为像 网站一样的十六进制并将其更改为:PUSH 5a

so it must be now : 00135FB3 6A 5A PUSH 5A but my program change it to 00135FB3 5A POP EDX所以现在必须是:00135FB3 6A 5A PUSH 5A 但我的程序将其更改为 00135FB3 5A POP EDX

i need to know what is wrong on my code please我需要知道我的代码有什么问题

thanks谢谢

sorry for my bad english ;)对不起,我的英语不好 ;)

You can't insert data to a file directly using the C# IO classes.不能使用 C# IO 类直接将数据插入到文件中。 The easiest way would be to either read it into a buffer and manipulate the buffer, or write the first part to a temp file, then insert your new data, and then write the remainder of the file and then rename it.最简单的方法是将其读入缓冲区并操作缓冲区,或者将第一部分写入临时文件,然后插入新数据,然后写入文件的其余部分,然后重命名。 Alternatively you can append some data at the end of the file and move everything up to create the right amount of usable space where you want to insert your data.或者,您可以在文件末尾附加一些数据并将所有内容向上移动,以在要插入数据的位置创建适量的可用空间。

Take a look at http://www.codeproject.com/Articles/17716/Insert-Text-into-Existing-Files-in-C-Without-Temp看看http://www.codeproject.com/Articles/17716/Insert-Text-into-Existing-Files-in-C-Without-Temp

Are you sure you have the right offset ?你确定你有正确的偏移量吗? Seems to me like 0x00135FB3 is offset of instruction and 0x00135FB4 is offset of argument;在我看来,0x00135FB3 是指令的偏移量,0x00135FB4 是参数的偏移量; have you tried:你有没有尝试过:

writer.Seek(0x135FB4, SeekOrigin.Begin);

in your code instead ?在你的代码中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM