Alright so i came up with a new method of searching but the old one is like 4 times faster because it only needs to search up until something is invalid and doesn't have to track back, if you have a better way of doing this then let me know.
void ByteArraySearcher()
{
byte[] SearchBytes = new byte[] { 0x00, 0x00, 0x00, 0x70, 0x72, 0x6F, 0x6A };
long SearchPosition = 0x00;
BinaryReader br = new BinaryReader(File.OpenRead(MapFile));
br.BaseStream.Position = SearchPosition;
for (var i = SearchPosition; i <= br.BaseStream.Length; i++)
{
byte[] ReadBytes = br.ReadBytes(SearchBytes.Length);
if (BitConverter.ToString(ReadBytes) == BitConverter.ToString(SearchBytes)) //Must convert both byte arrays to string to compare correctly for some odd reason
{
byte[] Position = BitConverter.GetBytes(br.BaseStream.Position - SearchBytes);
Array.Reverse(Position);
output.AppendText(BitConverter.ToString(Position).Replace("00-00-00-00-0", "").Replace("-", "") + "\n");
}
else
{
br.BaseStream.Position = br.BaseStream.Position - SearchBytes.Length + 1; //Go forward 1 byte and search again
}
}
br.Close();
if (ShowMessage == true)
{
MessageBox.Show("The application is done searching your file.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}