How can i search for a specified byte array and replace everything from the beginning to this byte array (included)
Basically i have my pattern to find
byte[] find = { 0x00, 0x48, 0x00 };
and
byte[] ddsHeaderDXT1 = { 0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x56, 0x54, 0x54, 0x06, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x58, 0x54, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
the thing i wanna do is to search for my find array, once it's found, select all bytes from the beginning of the file to this find array included, and replace all this with my ddsHeaderDXT1 array.
The file can be pretty big but the pattern is always at the beginning (less than 500 first bytes), not always at the same offset and can be found only once.
I have already tried rene's code here but it doesn't do anything. Also i get my file from OpenFileDialog and read its bytes
byte[] src = File.ReadAllBytes(ofdFilePath);
ddsHeaderDXT1is shorter than the position found, what do you expect to happen?ReplaceBytes(src, find, ddsHeaderDXT1);and it just didn't change my file but there was no error, maybe i did something wrong. @OlivierJacot-Descombes then i just wanna insert and increase the file size ¯_(ツ)_/¯ddsHeaderDXT1has a length of 110. If you find the pattern at position 400, you can fill the bytes at indexes 0 .. 109 with it. With what are you going to fill the bytes 110 .. 399?