public static dynamic CalculateHash(string type, string text)
 {
     if (type == "NLG_Hash")
     {
         return(StringToHash(text));
     }
     else if (type == "FNV64A1")
     {
         return(FNV64A1.Calculate(text));
     }
     else if (type == "CRC32")
     {
         return(Toolbox.Library.Security.Cryptography.Crc32.Compute(text));
     }
     else if (type == "BCSV")
     {
         return(stringToHash(text));
     }
     else if (type == "SARC")
     {
         return(NameHash(text));
     }
     else if (type == "MMH3")
     {
         return(Toolbox.Library.Security.Cryptography.MurMurHash3.Hash(text));
     }
     return(0);
 }
Exemple #2
0
        private void GenerateHashList()
        {
            foreach (string hashStr in Properties.Resources.Pkmn.Split('\n'))
            {
                string HashString = hashStr.TrimEnd();

                ulong hash = FNV64A1.Calculate(HashString);
                if (!hashList.ContainsKey(hash))
                {
                    hashList.Add(hash, HashString);
                }

                if (HashString.Contains("pm0000") ||
                    HashString.Contains("poke_XXXX") ||
                    HashString.Contains("poke_ball_0000") ||
                    HashString.Contains("poke_face_0000") ||
                    HashString.Contains("poke_motion_0000"))
                {
                    GeneratePokeStrings(HashString);
                }

                string[] hashPaths = HashString.Split('/');
                for (int i = 0; i < hashPaths?.Length; i++)
                {
                    hash = FNV64A1.Calculate(hashPaths[i]);
                    if (!hashList.ContainsKey(hash))
                    {
                        hashList.Add(hash, HashString);
                    }
                }
            }
        }
Exemple #3
0
        private void GeneratePokeStrings(string hashStr)
        {
            //Also check file name just in case
            if (FileName.Contains("pm"))
            {
                string baseName    = Path.GetFileNameWithoutExtension(FileName);
                string pokeStrFile = hashStr.Replace("pm0000_00", baseName);

                ulong hash = FNV64A1.CalculateSuffix(pokeStrFile);
                if (!hashList.ContainsKey(hash))
                {
                    hashList.Add(hash, pokeStrFile);
                }
            }

            for (int i = 0; i < 1000; i++)
            {
                string pokeStr = hashStr.Replace("pm0000", $"pm{i.ToString("D4")}");

                ulong hash = FNV64A1.CalculateSuffix(pokeStr);
                if (!hashList.ContainsKey(hash))
                {
                    hashList.Add(hash, pokeStr);
                }
            }
        }
 private static void GenerateGenericPokeStrings(string hashStr)
 {
     for (int i = 0; i < 1000; i++)
     {
         string pokeStr = string.Empty;
         if (hashStr.Contains("pm0000"))
         {
             pokeStr = hashStr.Replace("pm0000", $"pm{i.ToString("D4")}");
         }
         else if (hashStr.Contains("poke_XXXX"))
         {
             pokeStr = hashStr.Replace("poke_XXXX", $"poke_{i.ToString("D4")}");
         }
         else if (hashStr.Contains("poke_ball_0000"))
         {
             pokeStr = hashStr.Replace("poke_ball_0000", $"poke_ball_{i.ToString("D4")}");
         }
         else if (hashStr.Contains("poke_face_0000"))
         {
             pokeStr = hashStr.Replace("poke_face_0000", $"poke_face_{i.ToString("D4")}");
         }
         else if (hashStr.Contains("poke_motion_0000"))
         {
             pokeStr = hashStr.Replace("poke_motion_0000", $"poke_motion_{i.ToString("D4")}");
         }
         ulong hash = FNV64A1.Calculate(pokeStr);
         if (!HashCacheContent.ContainsKey(hash))
         {
             HashCacheContent.Add(hash, pokeStr);
         }
     }
 }
Exemple #5
0
        private static void TryAddHash(string str)
        {
            ulong hash = FNV64A1.Calculate(str);

            if (!HashCacheContent.ContainsKey(hash))
            {
                HashCacheContent.Add(hash, str);
            }
        }
Exemple #6
0
        private static ulong GetToolboxVersionHash()
        {
            string VersionFilePath = Path.Combine(Runtime.ExecutableDir, "Version.txt");
            ulong  VersionHash     = 0;

            if (File.Exists(VersionFilePath))
            {
                byte[] VersionBytes = File.ReadAllBytes(VersionFilePath);
                VersionHash = FNV64A1.Calculate(VersionBytes);
            }
            return(VersionHash);
        }
 public static ulong CalculateHash(string type, string text)
 {
     if (type == "NLG_Hash")
     {
         return(StringToHash(text));
     }
     else if (type == "FNV64A1")
     {
         return(FNV64A1.CalculateSuffix(text));
     }
     else if (type == "CRC32")
     {
         return(Toolbox.Library.Security.Cryptography.Crc32.Compute(text));
     }
     return(0);
 }
Exemple #8
0
        private void GeneratePokeStrings(string hashStr)
        {
            //Also check file name just in case
            if (FileName.Contains("pm"))
            {
                string baseName    = FileName.Substring(0, 12);
                string pokeStrFile = hashStr.Replace("pm0000_00", baseName);

                ulong hash = FNV64A1.Calculate(pokeStrFile);
                if (!hashList.ContainsKey(hash))
                {
                    hashList.Add(hash, pokeStrFile);
                }
            }

            for (int i = 0; i < 1000; i++)
            {
                string pokeStr = string.Empty;
                if (hashStr.Contains("pm0000"))
                {
                    pokeStr = hashStr.Replace("pm0000", $"pm{i.ToString("D4")}");
                }
                else if (hashStr.Contains("poke_XXXX"))
                {
                    pokeStr = hashStr.Replace("poke_XXXX", $"poke_{i.ToString("D4")}");
                }
                else if (hashStr.Contains("poke_ball_0000"))
                {
                    pokeStr = hashStr.Replace("poke_ball_0000", $"poke_ball_{i.ToString("D4")}");
                }
                else if (hashStr.Contains("poke_face_0000"))
                {
                    pokeStr = hashStr.Replace("poke_face_0000", $"poke_face_{i.ToString("D4")}");
                }
                else if (hashStr.Contains("poke_motion_0000"))
                {
                    pokeStr = hashStr.Replace("poke_motion_0000", $"poke_motion_{i.ToString("D4")}");
                }

                ulong hash = FNV64A1.Calculate(pokeStr);
                if (!hashList.ContainsKey(hash))
                {
                    hashList.Add(hash, pokeStr);
                }
            }
        }
Exemple #9
0
        private string GetString(ulong fullHash, HashIndex fileHashIndex, byte[] Data)
        {
            var folderHash = fileHashIndex.Parent.hash;
            var fileHash   = fileHashIndex.hash;

            bool hasFolderHash = false;

            string folder = "";

            if (HashList.ContainsKey(folderHash))
            {
                hasFolderHash = true;
                folder        = $"{HashList[folderHash]}/";
            }

            if (!hasFolderHash)
            {
                folder = $"{folderHash.ToString("X")}/";
            }



            string ext = FindMatch(Data);

            if (ext == ".bntx" || ext == ".bfres" || ext == ".bnsh" || ext == ".bfsha")
            {
                string fileName = GetBinaryHeaderName(Data);
                //Check for matches for shaders
                if (ext == ".bnsh")
                {
                    if (FNV64A1.Calculate($"{fileName}.bnsh_fsh") == fileHash)
                    {
                        fileName = $"{fileName}.bnsh_fsh";
                    }
                    else if (FNV64A1.Calculate($"{fileName}.bnsh_vsh") == fileHash)
                    {
                        fileName = $"{fileName}.bnsh_vsh";
                    }
                }
                else
                {
                    fileName = $"{fileName}{ext}";
                }

                if (hasFolderHash)
                {
                    return($"{folder}{fileName}");
                }
                else
                {
                    return($"{folder}{fileName}[FullHash={fullHash.ToString("X")}]{ext}");
                }
            }
            else
            {
                if (HashList.ContainsKey(fileHash))
                {
                    if (hasFolderHash)
                    {
                        return($"{folder}{HashList[fileHash]}");
                    }
                    else
                    {
                        return($"{folder}{HashList[fileHash]}[FullHash={fullHash.ToString("X")}]{ext}");
                    }
                }
                else
                {
                    return($"{folder}{fileHash.ToString("X")}[FullHash={fullHash.ToString("X")}]{ext}");
                }
            }
        }
Exemple #10
0
        public bool AddFile(ArchiveFileInfo archiveFileInfo)
        {
            //First we need to determine the paths
            string fullPath      = archiveFileInfo.FileName.Replace("\\", "/");
            string filePath      = Path.GetFileName(fullPath);
            string filePathNoExt = Path.GetFileNameWithoutExtension(fullPath);
            string directoryPath = Path.GetDirectoryName(fullPath).Replace("\\", "/");

            ulong fullPathHash  = 0;
            ulong directoryHash = 0;
            ulong fileHash      = 0;

            //Calculate hashes for each one

            //Check for full path hashes
            if (fullPath.Contains("[FullHash="))
            {
                string HashString = fullPath.Split('=').LastOrDefault().Replace("]", string.Empty);
                HashString = Path.GetFileNameWithoutExtension(HashString);

                filePath = filePath.Split('[').FirstOrDefault();

                TryParseHex(HashString, out fullPathHash);
            }

            ulong hash            = 0;
            bool  isDirectoryHash = TryParseHex(directoryPath, out hash);
            bool  isFileHash      = TryParseHex(filePath, out hash);

            if (isFileHash)
            {
                TryParseHex(filePath, out fileHash);
            }
            else
            {
                fileHash = FNV64A1.Calculate(filePath);
            }

            if (isDirectoryHash)
            {
                TryParseHex(directoryPath, out directoryHash);
            }
            else
            {
                directoryHash = FNV64A1.Calculate($"{directoryPath}/");
            }

            if (!isFileHash && !isDirectoryHash)
            {
                fullPathHash = FNV64A1.Calculate(fullPath);
            }

            var folder = folders.FirstOrDefault(x => x.hash == directoryHash);

            Console.WriteLine($"{fullPath} FilePathHash {fullPathHash}");
            Console.WriteLine($"{directoryPath} FolderHash {directoryHash} directoryHash {directoryHash}");
            Console.WriteLine($"{filePath} fileHash {fileHash} isFileHash {isFileHash}");

            if (folder != null)
            {
                folder.hashes.Add(new HashIndex()
                {
                    hash   = fileHash,
                    Parent = folder,
                    Index  = files.Count,
                });
            }
            else
            {
                folder      = new Folder();
                folder.hash = directoryHash;
                folder.hashes.Add(new HashIndex()
                {
                    hash   = fileHash,
                    Parent = folder,
                    Index  = files.Count,
                });
                folders.Add(folder);
            }

            files.Add(new FileEntry(this)
            {
                FilePathHash   = fullPathHash,
                FolderHash     = folder.hashes.LastOrDefault(),
                FileData       = archiveFileInfo.FileData,
                FileDataStream = archiveFileInfo.FileDataStream,
                FileName       = archiveFileInfo.FileName,
            });

            return(true);
        }
Exemple #11
0
 public static void PutHash(string Name)
 {
     PutHash(FNV64A1.Calculate(Name), Name);
 }