Deathmax

Untitled

Apr 13th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1.         private static byte[] _file;
  2.         public static int FindPattern(byte[] btPattern, string strMask)
  3.         {
  4.             try
  5.             {
  6.                 if (strMask.Length != btPattern.Length)
  7.                     return -1;
  8.                 for (int x = 0; x < _file.Length; x++)
  9.                 {
  10.                     if (MaskCheck(x, btPattern, strMask))
  11.                     {
  12.                         return x;
  13.                     }
  14.                 }
  15.                 return -1;
  16.             }
  17.             catch (Exception ex)
  18.             {
  19.                 return -1;
  20.             }
  21.         }
  22.  
  23.         private static bool MaskCheck(int nOffset, byte[] btPattern, string strMask)
  24.         {
  25.             for (int x = 0; x < btPattern.Length; x++)
  26.             {
  27.                 if (strMask[x] == '?')
  28.                     continue;
  29.  
  30.                 if ((strMask[x] == 'x') && (btPattern[x] != _file[nOffset + x]))
  31.                     return false;
  32.             }
  33.             return true;
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment