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);