Skip to content

Commit

Permalink
Better SecuROM handling for DIC and Redumper
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Dec 20, 2024
1 parent 6f8d27b commit 3a1fc93
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 42 deletions.
32 changes: 32 additions & 0 deletions MPF.Processors.Test/DiscImageCreatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,38 @@ public void GetSaturnBuildInfo_Valid_Filled()

#endregion

#region GetSecuROMData

[Fact]
public void GetSecuROMData_Empty_Null()
{
string log = string.Empty;
string? actual = DiscImageCreator.GetSecuROMData(log, out var securomScheme);
Assert.Null(actual);
Assert.Equal(SecuROMScheme.None, securomScheme);
}

[Fact]
public void GetSecuROMData_Invalid_Null()
{
string log = "INVALID";
string? actual = DiscImageCreator.GetSecuROMData(log, out var securomScheme);
Assert.Null(actual);
Assert.Equal(SecuROMScheme.None, securomScheme);
}

[Fact]
public void GetSecuROMData_Valid_Filled()
{
string? expected = "MSF: 00\nMSF: 01\nMSF: 02";
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "DiscImageCreator", "CDROM", "test_subIntention.txt");
string? actual = DiscImageCreator.GetSecuROMData(log, out var securomScheme);
Assert.Equal(expected, actual);
Assert.Equal(SecuROMScheme.Unknown, securomScheme);
}

#endregion

#region GetSegaCDBuildInfo

[Fact]
Expand Down
3 changes: 3 additions & 0 deletions MPF.Processors.Test/RedumperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ public void GetSecuROMData_Empty_Null()
string log = string.Empty;
string? actual = Redumper.GetSecuROMData(log, out var securomScheme);
Assert.Null(actual);
Assert.Equal(SecuROMScheme.None, securomScheme);
}

[Fact]
Expand All @@ -902,6 +903,7 @@ public void GetSecuROMData_Invalid_Null()
string log = "INVALID";
string? actual = Redumper.GetSecuROMData(log, out var securomScheme);
Assert.Null(actual);
Assert.Equal(SecuROMScheme.None, securomScheme);
}

[Fact]
Expand All @@ -911,6 +913,7 @@ public void GetSecuROMData_Valid_Filled()
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log");
string? actual = Redumper.GetSecuROMData(log, out var securomScheme);
Assert.Equal(expected, actual);
Assert.Equal(SecuROMScheme.Unknown, securomScheme);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
TEST DATA
MSF: 00
MSF: 01
MSF: 02
83 changes: 55 additions & 28 deletions MPF.Processors/DiscImageCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,37 +216,12 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, string basePath
case RedumpSystem.IBMPCcompatible:
case RedumpSystem.RainbowDisc:
case RedumpSystem.SonyElectronicBook:
if (File.Exists($"{basePath}_subIntention.txt"))
{
var fi = new FileInfo($"{basePath}_subIntention.txt");
if (fi.Length > 0)
{
info.CopyProtection!.SecuROMData = ProcessingTool.GetFullFile($"{basePath}_subIntention.txt") ?? string.Empty;

// Count the number of sectors
int sectorCount = 0;
for (int index = 0; (index = info.CopyProtection!.SecuROMData.IndexOf("MSF:", index, StringComparison.Ordinal)) != -1; index += "MSF:".Length)
sectorCount++;

// Determine SecuROM schema, warn if unusual type
SecuROMScheme secuROMScheme = SecuROMScheme.Unknown;
if (sectorCount == 216)
secuROMScheme = SecuROMScheme.PreV3;
else if (sectorCount == 90)
secuROMScheme = SecuROMScheme.V3;
else if (sectorCount == 99)
secuROMScheme = SecuROMScheme.V4;
else if (sectorCount == 11)
secuROMScheme = SecuROMScheme.V4Plus;

if (secuROMScheme == SecuROMScheme.Unknown)
info.CommonDiscInfo!.Comments = "Warning: Incorrect SecuROM sector count" + Environment.NewLine;
}
}
info.CopyProtection!.SecuROMData = GetSecuROMData($"{basePath}_subIntention.txt", out SecuROMScheme secuROMScheme) ?? string.Empty;
if (secuROMScheme == SecuROMScheme.Unknown)
info.CommonDiscInfo!.Comments = "Warning: Incorrect SecuROM sector count" + Environment.NewLine;

// Needed for some odd copy protections
info.CopyProtection!.Protection = GetDVDProtection($"{basePath}_CSSKey.txt", $"{basePath}_disc.txt", false) ?? string.Empty;

break;

case RedumpSystem.DVDAudio:
Expand Down Expand Up @@ -1808,6 +1783,58 @@ internal static bool GetSaturnBuildInfo(string? segaHeader, out string? serial,
}
}

/// <summary>
/// Get the SecuROM data from the input file, if possible
/// </summary>
/// <param name="subIntention">_subIntention.txt file location</param>
/// <param name="secuROMScheme">SecuROM scheme found</param>
/// <returns>SecuROM data, if possible</returns>
internal static string? GetSecuROMData(string subIntention, out SecuROMScheme secuROMScheme)
{
secuROMScheme = SecuROMScheme.None;

// If the file doesn't exist, we can't get info from it
if (string.IsNullOrEmpty(subIntention))
return null;
if (!File.Exists(subIntention))
return null;

try
{
var fi = new FileInfo(subIntention);
if (fi.Length == 0)
return null;

string secuROMData = ProcessingTool.GetFullFile(subIntention) ?? string.Empty;

// Count the number of sectors
int sectorCount = 0;
for (int index = 0; (index = secuROMData.IndexOf("MSF:", index, StringComparison.Ordinal)) != -1; index += "MSF:".Length)
{
sectorCount++;
}

// Determine SecuROM schema, warn if unusual type
secuROMScheme = sectorCount switch
{
0 => SecuROMScheme.None,
216 => SecuROMScheme.PreV3,
90 => SecuROMScheme.V3,
99 => SecuROMScheme.V4,
11 => SecuROMScheme.V4Plus,
_ => SecuROMScheme.Unknown,
};

return secuROMData;
}
catch
{
// We don't care what the exception is right now
secuROMScheme = SecuROMScheme.None;
return null;
}
}

/// <summary>
/// Get the build info from a Sega CD disc, if possible
/// </summary>
Expand Down
29 changes: 25 additions & 4 deletions MPF.Processors/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,30 @@ namespace MPF.Processors
internal enum SecuROMScheme
{
Unknown,
PreV3, // 216 Sectors
V3, // 90 Sectors
V4, // 99 Sectors
V4Plus, // 11 Sectors

/// <summary>
/// No SecuROM, 0 Sectors
/// </summary>
None,

/// <summary>
/// SecuROM 1-2, 216 Sectors
/// </summary>
PreV3,

/// <summary>
/// SecuROM 3, 90 Sectors
/// </summary>
V3,

/// <summary>
/// SecuROM 4, 99 Sectors
/// </summary>
V4,

/// <summary>
/// SecuROM 4+, 11 Sectors
/// </summary>
V4Plus,
}
}
21 changes: 12 additions & 9 deletions MPF.Processors/Redumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, string basePath
break;
}

// Extract info based specifically on RedumpSystem
switch (System)
{
case RedumpSystem.AppleMacintosh:
Expand Down Expand Up @@ -1682,7 +1683,7 @@ internal static bool GetSaturnBuildInfo(string? segaHeader, out string? buildDat
/// <returns>SecuROM data, if possible</returns>
internal static string? GetSecuROMData(string log, out SecuROMScheme secuROMScheme)
{
secuROMScheme = SecuROMScheme.Unknown;
secuROMScheme = SecuROMScheme.None;

// If the file doesn't exist, we can't get info from it
if (string.IsNullOrEmpty(log))
Expand Down Expand Up @@ -1715,20 +1716,22 @@ internal static bool GetSaturnBuildInfo(string? segaHeader, out string? buildDat
}

// Return the securom scheme if correct sector count
if (lines.Count == 216)
secuROMScheme = SecuROMScheme.PreV3;
else if (lines.Count == 90)
secuROMScheme = SecuROMScheme.V3;
else if (lines.Count == 99)
secuROMScheme = SecuROMScheme.V4;
else if (lines.Count == 11)
secuROMScheme = SecuROMScheme.V4Plus;
secuROMScheme = lines.Count switch
{
0 => SecuROMScheme.None,
216 => SecuROMScheme.PreV3,
90 => SecuROMScheme.V3,
99 => SecuROMScheme.V4,
11 => SecuROMScheme.V4Plus,
_ => SecuROMScheme.Unknown,
};

return string.Join("\n", [.. lines]).TrimEnd('\n');
}
catch
{
// We don't care what the exception is right now
secuROMScheme = SecuROMScheme.None;
return null;
}
}
Expand Down

0 comments on commit 3a1fc93

Please sign in to comment.