Make anti-modchip scans safer

This commit is contained in:
Matt Nadareski
2021-11-04 15:23:40 -07:00
parent faf9d1d6f8
commit d1813fdbc7

View File

@@ -57,29 +57,30 @@ namespace MPF.Library
}
/// <summary>
/// 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
/// </summary>
/// <param name="path">Path to scan for anti-modchip strings</param>
/// <returns>Anti-modchip existance if possible, false on error</returns>
/// <returns>Anti-modchip existence if possible, false on error</returns>
public static async Task<bool> 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;
});