Exemple #1
0
        private static MemoryStream DecryptBhdFile(string filePath, GameVersion version)
        {
            string fileDirectory = Path.GetDirectoryName(filePath) ?? string.Empty;
            string fileName      = Path.GetFileName(filePath) ?? string.Empty;
            string key           = null;

            switch (version)
            {
            case GameVersion.DarkSouls2:
                string keyFileName = Regex.Replace(fileName, @"Ebl\.bhd$", "KeyCode.pem", RegexOptions.IgnoreCase);
                string keyFilePath = Path.Combine(fileDirectory, keyFileName);
                if (File.Exists(keyFilePath))
                {
                    key = File.ReadAllText(keyFilePath);
                }
                break;

            case GameVersion.DarkSouls3:
                DecryptionKeys.TryGetRsaFileKey(fileName, out key);
                break;
            }

            if (key == null)
            {
                throw new ApplicationException($"Missing decryption key for file \'{fileName}\'");
            }

            return(CryptographyUtility.DecryptRsa(filePath, key));
        }
Exemple #2
0
        private static MemoryStream DecryptBhdFile(string filePath)
        {
            string fileName = Path.GetFileName(filePath);
            string key;

            if (!DecryptionKeys.TryGetRsaFileKey(fileName, out key))
            {
                throw new ApplicationException($"Missing decryption key for file \'{fileName}\'");
            }

            return(CryptographyUtility.DecryptRsa(filePath, key));
        }
Exemple #3
0
        private static MemoryStream DecryptBhdFile(string filePath, GameVersion version)
        {
            string fileDirectory = Path.GetDirectoryName(filePath) ?? string.Empty;
            string fileName      = Path.GetFileName(filePath) ?? string.Empty;
            string key           = null;

            // hack: bhd5 may already be decrypted!
            FileStream   fs = File.Open(filePath, FileMode.Open);
            MemoryStream ms = new MemoryStream();

            fs.CopyTo(ms);
            fs.Close();
            ms.Seek(0, SeekOrigin.Begin);
            string bhd5_sig;

            if (TryGetAsciiSignature(ms, 4, out bhd5_sig))
            {
                if (bhd5_sig == "BHD5")
                {
                    return(ms);
                }
            }

            switch (version)
            {
            case GameVersion.DarkSouls2:
                string keyFileName = Regex.Replace(fileName, @"Ebl\.bhd$", "KeyCode.pem", RegexOptions.IgnoreCase);
                string keyFilePath = Path.Combine(fileDirectory, keyFileName);
                if (File.Exists(keyFilePath))
                {
                    key = File.ReadAllText(keyFilePath);
                }
                break;

            case GameVersion.DarkSouls3:
                DecryptionKeys.TryGetRsaFileKey(fileName, out key);
                break;
            }

            if (key == null)
            {
                throw new ApplicationException($"Missing decryption key for file \'{fileName}\'");
            }

            return(CryptographyUtility.DecryptRsa(filePath, key));
        }