I am trying to create a C# application that will patch a certain application. As an example, I have 8 files, all 8 need to be patched in a similar fashion, (they have the same hex values to replace, but at different offsets). I need my program to find where these hex values are, and replace them. I cannot figure out a way to get my program to search for the hex values. Any help would be greatly appreciated. Currently, this is my code:
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;
}