Binary Pattern Search

Total Post:39


 2323  View(s)
Rate this:
Hi Everyone,

I wanna search a binary file for this pattern '00 00 00 08 00' then to read 8 bytes after it into a variable.

Please help!
  1. Re: Binary Pattern Search

    namespace XYZ
        public partial class Form1 : Form {
            StringBuilder bldr = new StringBuilder();
            byte[] readFromFile;

            Regex hexPattern = new Regex("0000000800(?<binaryText>.{16})");
            MatchCollection matchBinary;
            FileStream bStream = new FileStream("C:\\XYZ.bin", FileMode.Open, FileAccess.Read);
            BinaryReader fruity;

            public Form1() {
                using (fruity = new BinaryReader(bStream)) {
                    readFromFile = fruity.ReadBytes(31);
                // create a hex-dump formatted string
                // from the binary file input data
                foreach (byte thisbyte in readFromFile) {
                // then search the hex-dump-format string for the
                // pattern he seeks. 'Capture' the eight bytes which
                // follow the pattern.
                matchBinary = hexPattern.Matches(bldr.ToString());

                // No recovery required ... just index the data bytes
                // in 'readFromFile' using the index supplied by Regex.
            }// end constructor
        }// end class Form1
    }// end Namespace ‘XYZ’

      Modified On Mar-29-2018 04:06:56 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.