コード例 #1
0
        private static void AddGuidsFromLine(int index, string line, List<Found> guids)
        {
            MatchCollection mc = s_Parser.Matches(line);
            foreach (Match m in mc)
            {
                byte[] bytes = new byte[16];
                for (int i = 0; i < 16; i++)
                {
                    byte b;
                    if (!byte.TryParse(m.Groups["b" + i.ToString()].Value, System.Globalization.NumberStyles.HexNumber, null, out b))
                    {
                        if (!m.Success) throw new ArgumentOutOfRangeException();
                    }
                    bytes[i] = b;
                }
                guids.Add(new Found() { Line = index, Match = m.Value, Guids = new Guid[] { new Guid(bytes) } });
            }

            mc = s_B64Parser_Single.Matches(line);
            foreach (Match m in mc)
            {
                Found f = new Found() { Line = index, Match = m.Value };
                AddGuidsFromBytes(Convert.FromBase64String(m.Value), f);
                guids.Add(f);
            }
        }
コード例 #2
0
        public static int Search(System.IO.TextReader reader, List<Found> found)
        {
            int startCount = found.Count;
            bool inBase64 = false;
            int lineCount = 0;
            string line;
            while (reader.Peek() != -1 && (line = reader.ReadLine()) != null)
            {

                if (s_isB64.IsMatch(line))
                {
                    int len = line.Length;
                    int beginLine = lineCount;
                    System.Text.StringBuilder concatd = new StringBuilder(line);
                    bool appendLast = false;
                    List<Found> temp = new List<Found>();
                    AddGuidsFromLine(lineCount, line, temp);
                    if (!line.EndsWith("="))
                    {
                        while (!line.EndsWith("=") && (line = reader.ReadLine()) != null && (appendLast = s_isB64.IsMatch(line)) && line.Length == len)
                        {
                            lineCount++;
                            AddGuidsFromLine(lineCount, line, temp);
                            concatd.Append(line);
                            appendLast = false;
                        }
                        if (line != null && (inBase64 = appendLast)) concatd.Append(line);
                    }
                    if (s_B64Parser.IsMatch(concatd.ToString()))
                    {
                        Found f = new Found() { Line = beginLine, Match = concatd.ToString() };
                        AddGuidsFromBytes(Convert.FromBase64String(concatd.ToString()), f);
                        found.Add(f);
                    }
                    else
                    {
                        found.AddRange(temp);
                    }
                }
                else if (line != null)
                {
                    AddGuidsFromLine(lineCount, line, found);
                }
                lineCount++;
            }
            return found.Count - startCount;
        }
コード例 #3
0
 private static void AddGuidsFromBytes(byte[] bytes, Found guids)
 {
     if (bytes.Length == 16)
     {
         guids.Guids = new Guid[] { new Guid(bytes) };
     }
     else if (bytes.Length % 16 == 0)
     {
         guids.Guids = new Guid[bytes.Length / 16];
         int index = 0;
         while (index * 16 < bytes.Length)
         {
             byte[] dest = new byte[16];
             Array.Copy(bytes, index * 16, dest, 0, 16);
             guids.Guids[index] = new Guid(dest);
             index++;
         }
     }
 }
コード例 #4
0
        public static int SearchB64Combined(System.IO.TextReader reader, List<Found> found)
        {
            int startCount = found.Count;
            int lineCount = 0;
            int startLine = 0;
            string line;
            System.Text.StringBuilder concatd = new StringBuilder();
            while (reader.Peek() != -1 && (line = reader.ReadLine()) != null)
            {
                if (s_isB64.IsMatch(line))
                {
                    concatd.Append(line);
                    Match m = s_B64Parser.Match(concatd.ToString());
                    if (m.Success)
                    {
                        Found f = new Found() { Line = startLine, Match = m.Value };
                        AddGuidsFromBytes(Convert.FromBase64String(m.Value), f);
                        found.Add(f);
                        startLine = lineCount+1;
                        concatd.Clear();
                    }
                }
                else
                {
                    concatd.Clear();
                    startLine = lineCount+1;
                }
                lineCount++;

            }
            return found.Count - startCount;
        }