Exemple #1
0
 /// <summary>
 /// Writes the bytes from the given ByteFilter into the given byte array
 /// starting at the given index.
 /// </summary>
 public static void WriteBytes(byte[] writeTo, long startIndex, ByteFilter data)
 {
     for (long i = 0; i < data.Length; i++)
     {
         if (data.IsWildcardIndex(i))
         {
             continue;
         }
         else
         {
             writeTo[startIndex + i] = data.Bytes[i];
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Returns the start index of the first occurrence of the given ByteFilter.
        /// </summary>
        public static long GetStartIndex(byte[] fileBytes, ByteFilter findBytes)
        {
            long matchIndex = 0;

            for (long i = 0; i < fileBytes.Length; i++)
            {
                if (findBytes.IsWildcardIndex(matchIndex) || fileBytes[i] == findBytes.Bytes[matchIndex])
                {
                    matchIndex++;
                    if (matchIndex == findBytes.Length)
                    {
                        return(i - matchIndex + 1);
                    }
                }
                else
                {
                    matchIndex = 0;
                }
            }
            return(-1);
        }