View difference between Paste ID: PaaW51gg and D3MFnJhY
SHOW: | | - or go back to the newest paste.
1
        /// <summary>
2
        /// Byte array to be used by FindPattern
3
        /// </summary>
4
        private static byte[] _file;
5
        /// <summary>
6
        /// Finds a specific pattern in a byte array
7
        /// </summary>
8
        /// <param name="btPattern">Byte array containing pattern to search</param>
9
        /// <param name="strMask">x for exact match, ? for wildcard</param>
10
        /// <returns>Position of pattern in _file, -1 if pattern not found</returns>
11
        public static int FindPattern(byte[] btPattern, string strMask)
12
        {
13
            try
14
            {
15
                if (strMask.Length != btPattern.Length)
16
                    return -1;
17
                for (int x = 0; x < _file.Length; x++)
18
                {
19
                    if (MaskCheck(x, btPattern, strMask))
20
                    {
21
                        return x;
22
                    }
23
                }
24
                return -1;
25-
            for (int x = 0; x < btPattern.Length; x++)
25+
26
            catch (Exception ex)
27-
                if (strMask[x] == '?')
27+
28-
                    continue;
28+
29
            }
30-
                if ((strMask[x] == 'x') && (btPattern[x] != _file[nOffset + x]))
30+
31-
                    return false;
31+
32
        private static bool MaskCheck(int nOffset, byte[] btPattern, string strMask)
33-
            return true;
33+
34
            return !btPattern.Where((t, x) => strMask[x] != '?' && ((strMask[x] == 'x') && (t != _file[nOffset + x]))).Any();
35
        }