title: C# Binary Search + Replace
body: <p>How can i search for a specified byte array and replace everything from the beginning to this byte array (included)</p>
  
  <p>Basically i have my pattern to find</p>
  
  <pre><code>byte[] find = { 0x00, 0x48, 0x00 };
  </code></pre>
  
  <p>and </p>
  
  <pre><code>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 };
  </code></pre>
  
  <p>the thing i wanna do is to search for my <code>find</code> array, once it's found, select all bytes from the beginning of the file to this <code>find</code> array included, and replace all this with my <code>ddsHeaderDXT1</code> 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.</p>
  
  <p>I have already tried rene's code <a href="https://stackoverflow.com/questions/5132890/c-sharp-replace-bytes-in-byte">here</a> but it doesn't do anything.
  Also i get my file from OpenFileDialog and read its bytes</p>
  
  <pre><code>byte[] src = File.ReadAllBytes(ofdFilePath);
  </code></pre>