Ejemplo n.º 1
0
 static uint ParseNum(string s, string name)
 {
     try
     {
         return((uint)converter.ConvertFromString(s));
     }
     catch
     {
         throw new FormatException($"Cannot parse {name} as an uint.");
     }
 }
        static void CheckStrings(string inputFolder, HashType hash, List <string> strings)
        {
            var converter    = new UInt32Converter();
            var makeHash     = HashManager.GetHashFunction(hash);
            var lineComparer = HashManager.GetStringComparer(hash);
            var files        = Directory.GetFiles(inputFolder, "*.hashes", SearchOption.AllDirectories);
            var testData     = strings.Select(s => new KeyValuePair <UInt32, string>(makeHash(s), s)).ToList();

            var bufferCollisions = new List <string>();
            var bufferNew        = new List <string>();

            foreach (var fileName in files)
            {
                var hashList      = File.ReadAllLines(fileName).Select(s => (UInt32)converter.ConvertFromString(s)).ToDictionary(k => k, v => v);
                var lines         = File.ReadAllLines(Path.ChangeExtension(fileName, ".txt")).ToDictionary(k => makeHash(k), v => v);
                var localFileName = fileName.Remove(0, inputFolder.Length + 1);

                foreach (var test in testData)
                {
                    if (hashList.ContainsKey(test.Key))
                    {
                        string currentValue;
                        if (lines.TryGetValue(test.Key, out currentValue))
                        {
                            if (!lineComparer.Equals(currentValue, test.Value))
                            {
                                bufferCollisions.Add(string.Format("COLLISION\t{0}\t{1}\t{2}", localFileName, currentValue, test.Value));
                            }
                        }
                        else
                        {
                            bufferNew.Add(string.Format("NEW\t{0}\t{1}", localFileName, test.Value));
                        }
                    }
                }
            }

            if (bufferCollisions.Any())
            {
                Console.WriteLine("#COLLISION\tFile_name\tCurrent_line\tInput_line");
                bufferCollisions.Sort();
                bufferCollisions.ForEach(s => Console.WriteLine(s));
                Console.WriteLine("");
            }

            if (bufferNew.Any())
            {
                Console.WriteLine("#NEW\tFile_name\tInput_line");
                bufferNew.Sort();
                bufferNew.ForEach(s => Console.WriteLine(s));
                Console.WriteLine("");
            }
        }
Ejemplo n.º 3
0
 void ParseListBin(byte[] data)
 {
     using (var mem = new MemoryStream(data))
         using (var input = new StreamReader(mem))
         {
             var    converter = new UInt32Converter();
             string line;
             while ((line = input.ReadLine()) != null)
             {
                 if (0 == line.Length || '0' != line[0])
                 {
                     continue;
                 }
                 var pair = line.Split(',');
                 if (pair.Length > 1)
                 {
                     uint hash      = (uint)converter.ConvertFromString(pair[0]);
                     uint threshold = (uint)converter.ConvertFromString(pair[1]);
                     EncryptionThresholdMap[hash] = threshold;
                 }
             }
         }
 }
        /// <summary>
        /// Tries to parse a 32-bit unsigned integer from a string. This method should handle hexadecimal values
        /// as well as normal values.
        /// </summary>
        /// <param name="value">The string value to parse.</param>
        /// <param name="result">The parsed integer, if the string was valid. If invalid, this
        /// will be the default integer value.</param>
        /// <returns>True if the conversion was successful; otherwise returns false.</returns>
        public static bool TryParseEx(string value, out uint result)
        {
            bool canConvert = true;

            try
            {
                var converter = new UInt32Converter();
                result = (uint)converter.ConvertFromString(value);
            }
            catch (Exception)
            {
                result     = default(uint);
                canConvert = false;
            }

            return(canConvert);
        }
Ejemplo n.º 5
0
 static uint ParseUInt32(Token token)
 {
     return((uint)uint32Converter.ConvertFromString(token.Image));
 }