diff --git a/CHANGELIST.md b/CHANGELIST.md index 0b81ee76..3433d6e0 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -20,6 +20,7 @@ - Futureproof GD-ROM LD in Redumper - Make GD-ROM LD code nicer to read - Rename 2 XGD helper methods +- Add bus encryption enabled method ### 3.2.1 (2024-08-05) diff --git a/MPF.Frontend/Tools/ProtectionTool.cs b/MPF.Frontend/Tools/ProtectionTool.cs index 6be17dd9..ec9457cb 100644 --- a/MPF.Frontend/Tools/ProtectionTool.cs +++ b/MPF.Frontend/Tools/ProtectionTool.cs @@ -128,6 +128,54 @@ namespace MPF.Frontend.Tools return protectionString; } + /// + /// Get if the Bus Encryption Enabled (BEE) flag is set in a path + /// + /// Path to scan for bus encryption enabled + /// Bus encryption enabled status if possible, false otherwise + public static bool GetBusEncryptionEnabled(string? path) + { + // If there is no valid path + if (string.IsNullOrEmpty(path)) + return false; + else if (!Directory.Exists(path)) + return false; + + // Get the two possible file paths +#if NET20 || NET35 + string content000 = Path.Combine(Path.Combine(path, "AACS"), "Content000.cer"); + string content001 = Path.Combine(Path.Combine(path, "AACS"), "Content001.cer"); +#else + string content000 = Path.Combine(path, "AACS", "Content000.cer"); + string content001 = Path.Combine(path, "AACS", "Content001.cer"); +#endif + + try + { + // Check the required files + if (File.Exists(content000) && new FileInfo(content000).Length > 1) + { + using var fs = File.OpenRead(content000); + _ = fs.ReadByte(); // Skip the first byte + return fs.ReadByte() > 127; + } + else if (File.Exists(content001) && new FileInfo(content001).Length > 1) + { + using var fs = File.OpenRead(content001); + _ = fs.ReadByte(); // Skip the first byte + return fs.ReadByte() > 127; + } + + // False if neither file fits the criteria + return false; + } + catch + { + // We don't care what the error is right now + return false; + } + } + /// /// Get the existence of an anti-modchip string from a PlayStation disc, if possible ///