Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Byte array to be used by FindPattern
- /// </summary>
- private static byte[] _file;
- /// <summary>
- /// Finds a specific pattern in a byte array
- /// </summary>
- /// <param name="btPattern">Byte array containing pattern to search</param>
- /// <param name="strMask">x for exact match, ? for wildcard</param>
- /// <returns>Position of pattern in _file, -1 if pattern not found</returns>
- public static int FindPattern(byte[] btPattern, string strMask)
- {
- try
- {
- if (strMask.Length != btPattern.Length)
- return -1;
- for (int x = 0; x < _file.Length; x++)
- {
- if (MaskCheck(x, btPattern, strMask))
- {
- return x;
- }
- }
- return -1;
- }
- catch (Exception ex)
- {
- return -1;
- }
- }
- private static bool MaskCheck(int nOffset, byte[] btPattern, string strMask)
- {
- return !btPattern.Where((t, x) => strMask[x] != '?' && ((strMask[x] == 'x') && (t != _file[nOffset + x]))).Any();
- }
Advertisement
Add Comment
Please, Sign In to add comment