0

我将如何用 C# 替换二进制文件中特定十六进制偏移量的内容?

为了更清楚,假设我的偏移量是 0x33347,它的内容是 06。我想将 06 更改为 17。我该怎么做?我对十六进制编辑的经验很少,所以我自己无法弄清楚任何事情,我有点迷茫。

4

2 回答 2

3

Using a FileStream, set the Position of the stream to the offset, then write the byte.

This will overwrite the current content with what you want.

using(var fs = new FileStream("path to file", 
                              FileMode.Open, 
                              FileAccess.ReadWrite))
{
    fs.Position = 0x33347;
    fs.WriteByte(Convert.ToByte(0x6));
}
于 2012-04-19T15:19:29.830 回答
2

Open the stream in read-write mode, read up to your offset (or seek if your stream supports seeking), write your byte, flush and close the stream.

于 2012-04-19T15:18:59.663 回答