From d1813fdbc76873bee3384615a34db1b33e81d94b Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 4 Nov 2021 15:23:40 -0700 Subject: [PATCH] Make anti-modchip scans safer --- MPF.Library/Protection.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/MPF.Library/Protection.cs b/MPF.Library/Protection.cs index 211b0235..4bcc8fe1 100644 --- a/MPF.Library/Protection.cs +++ b/MPF.Library/Protection.cs @@ -57,29 +57,30 @@ namespace MPF.Library } /// - /// Get the existance of an anti-modchip string from a PlayStation disc, if possible + /// Get the existence of an anti-modchip string from a PlayStation disc, if possible /// /// Path to scan for anti-modchip strings - /// Anti-modchip existance if possible, false on error + /// Anti-modchip existence if possible, false on error public static async Task GetPlayStationAntiModchipDetected(string path) { return await Task.Run(() => { - var antiModchip = new PSXAntiModchip(); - foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) + try { - try + var antiModchip = new PSXAntiModchip(); + foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) { - byte[] fileContent = File.ReadAllBytes(file); - string protection = antiModchip.CheckContents(file, fileContent, false, null, null); - if (!string.IsNullOrWhiteSpace(protection)) - return true; - } - catch - { - // No-op, we don't care what the error was + try + { + byte[] fileContent = File.ReadAllBytes(file); + string protection = antiModchip.CheckContents(file, fileContent, false, null, null); + if (!string.IsNullOrWhiteSpace(protection)) + return true; + } + catch { } } } + catch { } return false; });