【问题标题】:How to find and replace certain hex value within a compiled exe [closed]如何在已编译的 exe 中查找和替换某些十六进制值 [关闭]
【发布时间】:2018-02-16 17:57:58
【问题描述】:

我正在尝试创建一个可以修补某个应用程序的 C# 应用程序。例如,我有 8 个文件,所有 8 个文件都需要以类似的方式进行修补(它们具有相同的十六进制值要替换,但偏移量不同)。我需要我的程序找到这些十六进制值的位置,并替换它们。我想不出办法让我的程序搜索十六进制值。任何帮助将不胜感激。目前,this 是我的代码:

private const string SoftwareDirectory = @"C:\Program Files\ExampleSoftware";
private const string HexCode = "C8 49 73 B9";
private const string IgnoreEXE = "ignoreMe.exe";

static void Main(string[] args)
    {
        List<string> allTheFiles = FindFiles(SoftwareDirectory, "*.exe", SearchOption.AllDirectories, IgnoreEXE);
        allTheFiles.ForEach((string s) =>
        {
            // Find and replace hex value here, Hex value defined by HexCode, and modified version is C7 49 73 C6, as an example
        });
        Console.ReadLine();
    }

static List<string> FindFiles(string directory, string searchPattern, SearchOption searchOption, string ignoreFiles = null)
    {
        List<string> files = new List<string>();
        foreach (string file in Directory.EnumerateFiles(directory, searchPattern, searchOption))
        {
            if (!file.Contains(ignoreFiles))
            {
                files.Add(file);
            }
        }
        return files;
    }

【问题讨论】:

  • 该代码似乎与问题无关。这是否意味着你还没有尝试过任何东西?对于您所描述的内容,您不必找到该值-它们可以出现在很多地方。修补程序应该已经知道偏移量,否则您可能会更改错误的偏移量或太多或...
  • 我确实有偏移量,我只是想找到一个更模块化的替代方案,而不是每次都输入新的偏移量。此外,“示例”软件在整个表格中只出现一次十六进制值。

标签: c# .net patch


【解决方案1】:

它是 exe 并不重要(除了您可能没有写入 Program Files 目录的权限,或者可能无法写入可执行文件,因为它正在运行)。将其视为二进制文件即可。

使用IO.File.ReadAllBytes 和IO.File.WriteAllBytes。

已经回答了在字节数组中查找字节序列的问题。 byte[] array pattern search

【讨论】:

  • 并用byte[] HexCode = new byte[]{0xC8, 0x49, 0x73, 0xB9}替换你原来的字符串HexCode
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
  • 2014-09-04
  • 2018-07-16
  • 2019-12-11
  • 1970-01-01
相关资源
最近更新 更多