Exemple #1
0
        /// <summary>
        /// Opens a file containing one string per line, hashes each string, and adds each pair to a lookup table.
        /// </summary>
        private static Dictionary <uint, string> MakeHashLookupTableFromFile(string path, FoxHash.Type hashType)
        {
            ConcurrentDictionary <uint, string> table = new ConcurrentDictionary <uint, string>();

            // Read file
            List <string> stringLiterals = new List <string>();

            using (StreamReader file = new StreamReader(path))
            {
                // TODO multi-thread
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    stringLiterals.Add(line);
                }
            }

            // Hash entries
            Parallel.ForEach(stringLiterals, (string entry) =>
            {
                if (hashType == FoxHash.Type.StrCode32)
                {
                    uint hash = HashManager.StrCode32(entry);
                    table.TryAdd(hash, entry);
                }
                else
                {
                    uint hash = HashManager.PathCode32(entry);
                    table.TryAdd(hash, entry);
                }
            });

            return(new Dictionary <uint, string>(table));
        }
Exemple #2
0
        public static LbaFile ReadFromBinary(string path, HashManager hashManager)
        {
            LbaFile lba = new LbaFile();

            using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open)))
            {
                lba.Read(reader, hashManager);
            }
            return(lba);
        }
Exemple #3
0
 /// <summary>
 /// Outputs all hash matched strings to a file.
 /// </summary>
 private static void WriteHashMatchesToFile(string path, HashManager hashManager)
 {
     using (StreamWriter file = new StreamWriter(path))
     {
         foreach (var entry in hashManager.UsedHashes)
         {
             file.WriteLine(entry.Value);
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Reads and populates data from a binary lba file.
        /// </summary>
        public void Read(BinaryReader reader, HashManager hashManager)
        {
            // Read header
            uint locatorCount = reader.ReadUInt32();

            Type = (LocatorType)reader.ReadUInt32();
            reader.ReadDouble();

            // Read locators
            bool hasFooter = false;

            for (int i = 0; i < locatorCount; i++)
            {
                switch (Type)
                {
                case LocatorType.Type0:
                    ILocator locator0 = new LocatorType0();
                    locator0.Read(reader, hashManager.StrCode32LookupTable, hashManager.OnHashIdentified);
                    Locators.Add(locator0);
                    hasFooter = locator0.HasFooter;
                    break;

                case LocatorType.Type2:
                    ILocator locator2 = new LocatorType2();
                    locator2.Read(reader, hashManager.StrCode32LookupTable, hashManager.OnHashIdentified);;
                    Locators.Add(locator2);
                    hasFooter = locator2.HasFooter;
                    break;

                case LocatorType.Type3:
                    ILocator locator3 = new LocatorType3();
                    locator3.Read(reader, hashManager.StrCode32LookupTable, hashManager.OnHashIdentified);
                    Locators.Add(locator3);
                    hasFooter = locator3.HasFooter;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            // Read footer
            if (hasFooter)
            {
                foreach (ILocator locator in Locators)
                {
                    locator.ReadFooter(reader, hashManager.StrCode32LookupTable, hashManager.PathCode32LookupTable, hashManager.OnHashIdentified);
                }
            }
        }
Exemple #5
0
        public void ReadXml(XmlReader reader, string label)
        {
            string value = reader[label];

            if (uint.TryParse(value, out uint maybeHash))
            {
                HashValue = maybeHash;
            }
            else
            {
                StringLiteral = value;

                if (this.type == Type.StrCode32)
                {
                    HashValue = HashManager.StrCode32(StringLiteral);
                }
                else
                {
                    HashValue = HashManager.PathCode32(StringLiteral);
                }
            }
        }
Exemple #6
0
        private static void Main(string[] args)
        {
            var hashManager = new HashManager();

            // Read hash dictionaries
            if (File.Exists(DefaultNameDictionaryFileName))
            {
                hashManager.StrCode32LookupTable  = MakeHashLookupTableFromFile(DefaultNameDictionaryFileName, FoxHash.Type.StrCode32);
                hashManager.PathCode32LookupTable = MakeHashLookupTableFromFile(DefaultDataSetDictionaryFileName, FoxHash.Type.PathCode32);
            }

            foreach (var lbaPath in args)
            {
                if (File.Exists(lbaPath))
                {
                    // Read input file
                    string fileExtension = Path.GetExtension(lbaPath);
                    if (fileExtension.Equals(".xml", StringComparison.OrdinalIgnoreCase))
                    {
                        LbaFile lba = ReadFromXml(lbaPath);
                        WriteToBinary(lba, Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(lbaPath)) + ".lba");
                    }
                    else if (fileExtension.Equals(".lba", StringComparison.OrdinalIgnoreCase))
                    {
                        LbaFile lba = ReadFromBinary(lbaPath, hashManager);
                        WriteToXml(lba, Path.GetFileNameWithoutExtension(lbaPath) + ".lba.xml");
                    }
                    else
                    {
                        throw new IOException("Unrecognized input type.");
                    }
                }
            }

            // Write hash matches output
            WriteHashMatchesToFile(DefaultHashMatchOutputFileName, hashManager);
        }