From cfc75ca84d232140b47ca22776ab3cf187ca2443 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 20 Aug 2024 14:08:51 -0400 Subject: [PATCH] Move BEE method to better location --- CHANGELIST.md | 1 + MPF.Frontend/Tools/PhysicalTool.cs | 50 ++++++++++++++++++++++++++++ MPF.Frontend/Tools/ProtectionTool.cs | 48 -------------------------- 3 files changed, 51 insertions(+), 48 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 3433d6e0..78bef447 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -21,6 +21,7 @@ - Make GD-ROM LD code nicer to read - Rename 2 XGD helper methods - Add bus encryption enabled method +- Move BEE method to better location ### 3.2.1 (2024-08-05) diff --git a/MPF.Frontend/Tools/PhysicalTool.cs b/MPF.Frontend/Tools/PhysicalTool.cs index fefd0487..546c96bd 100644 --- a/MPF.Frontend/Tools/PhysicalTool.cs +++ b/MPF.Frontend/Tools/PhysicalTool.cs @@ -14,6 +14,56 @@ namespace MPF.Frontend.Tools { #region Information Extraction + /// + /// Get if the Bus Encryption Enabled (BEE) flag is set in a path + /// + /// Drive to extract information from + /// Bus encryption enabled status if possible, false otherwise + public static bool GetBusEncryptionEnabled(Drive? drive) + { + // If there's no drive path, we can't get BEE flag + if (string.IsNullOrEmpty(drive?.Name)) + return false; + + // If the folder no longer exists, we can't get exe name + if (!Directory.Exists(drive!.Name)) + return false; + + // Get the two possible file paths +#if NET20 || NET35 + string content000 = Path.Combine(Path.Combine(drive.Name, "AACS"), "Content000.cer"); + string content001 = Path.Combine(Path.Combine(drive.Name, "AACS"), "Content001.cer"); +#else + string content000 = Path.Combine(drive.Name, "AACS", "Content000.cer"); + string content001 = Path.Combine(drive.Name, "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 EXE name from a PlayStation disc, if possible /// diff --git a/MPF.Frontend/Tools/ProtectionTool.cs b/MPF.Frontend/Tools/ProtectionTool.cs index ec9457cb..6be17dd9 100644 --- a/MPF.Frontend/Tools/ProtectionTool.cs +++ b/MPF.Frontend/Tools/ProtectionTool.cs @@ -128,54 +128,6 @@ 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 ///