Пример #1
0
        public static Byte[] Transform(string pattern)
        {
            pattern = Format(pattern);
            var length = pattern.Length;

            if (length == 0)
            {
                return(null);
            }
            var result = new List <Byte>((length + 1) / 2);

            if (length % 2 != 0)
            {
                pattern += "?";
                length++;
            }
            var newbyte = new Byte();

            for (int i = 0, j = 0; i < length; i++)
            {
                var ch = pattern[i];
                if (ch == '?')                 //wildcard
                {
                    if (j == 0)
                    {
                        newbyte.N1.Wildcard = true;
                    }
                    else
                    {
                        newbyte.N2.Wildcard = true;
                    }
                }
                else                 //hex
                {
                    if (j == 0)
                    {
                        newbyte.N1.Wildcard = false;
                        newbyte.N1.Data     = (byte)(hexChToInt(ch) & 0xF);
                    }
                    else
                    {
                        newbyte.N2.Wildcard = false;
                        newbyte.N2.Data     = (byte)(hexChToInt(ch) & 0xF);
                    }
                }

                j++;
                if (j == 2)
                {
                    j = 0;
                    result.Add(newbyte);
                }
            }
            return(result.ToArray());
        }
Пример #2
0
 public static bool matchByte(byte b, ref Byte p)
 {
     if (!p.N1.Wildcard)             //if not a wildcard we need to compare the data.
     {
         var n1 = b >> 4;
         if (n1 != p.N1.Data)                 //if the data is not equal b doesn't match p.
         {
             return(false);
         }
     }
     if (!p.N2.Wildcard)             //if not a wildcard we need to compare the data.
     {
         var n2 = b & 0xF;
         if (n2 != p.N2.Data)                 //if the data is not equal b doesn't match p.
         {
             return(false);
         }
     }
     return(true);
 }