How to overwrite specific bytes in a binary file with C#?

天涯浪子 提交于 2019-12-04 21:30:53

The string you want to overwrite is a GUID. You can use theGuid class to generate a new one (see the MSDN Documentation)

As for writing to the file, use the BinaryWriter class.

using (System.IO.BinaryWriter fileWriter = new System.IO.BinaryWriter(System.IO.File.Open("path", System.IO.FileMode.Open)))
{
    fileWriter.BaseStream.Position = 0xB8EB9; // set the offset
    fileWriter.Write(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString()));
}

ideone sample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!