如何覆盖特定字节在C#中的二进制文件? [英] How to overwrite specific bytes in a binary file with C#?

查看:519
本文介绍了如何覆盖特定字节在C#中的二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要覆盖字节的一个exe。

I want to overwrite bytes in an exe.

所以,我需要生成一个随机字符串,将其转换,然后将其写入EXE。

So I need to generate a random string, convert it, and then write it to the exe.

我要覆盖您看到有这种格式XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX(8-4-4-4-12)需要破折号,这样也是一个问题,我的4个十六进制的字符串。

I need to overwrite the 4 hex strings you see there in this format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12) the dashes are needed so that also was a problem for me.

这是第一个字符串的位置。

this is the location of the first string.

我绝对有不知道如何开始这一点,我怎么能覆盖这些四弦,在随机字符串正确的格式(十六进制,所以随机只能0123456789ABCDEF)

I absolutely got no idea how to start this, how I can overwrite these 4 strings, in the correct format with random strings (hex, so the random can only be 0123456789abcdef)

任何帮助很多AP preciated。

any help is much appreciated.

推荐答案

要覆盖的字符串是一个GUID。您可以使用的Guid 类生成一个新的(见的 MSDN文档

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

至于写入文件,使用的BinaryWriter 类。

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样品

这篇关于如何覆盖特定字节在C#中的二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆