diff --git a/BurnOutSharp.Builders/AACS.cs b/BurnOutSharp.Builders/AACS.cs index 34374dc5..c085f075 100644 --- a/BurnOutSharp.Builders/AACS.cs +++ b/BurnOutSharp.Builders/AACS.cs @@ -194,6 +194,10 @@ namespace BurnOutSharp.Builders // Set the subset differences record.SubsetDifferences = subsetDifferences.ToArray(); + // If there's any data left, discard it + if (data.Position < initialOffset + length) + _ = data.ReadBytes((int)(initialOffset + length - data.Position)); + return record; } @@ -319,7 +323,8 @@ namespace BurnOutSharp.Builders var blocks = new List(); // Try to parse the signature blocks - while (data.Position < initialOffset + length) + int entryCount = 0; + while (entryCount < record.TotalNumberOfEntries && data.Position < initialOffset + length) { var block = new DriveRevocationSignatureBlock(); @@ -333,6 +338,7 @@ namespace BurnOutSharp.Builders entry.DriveID = data.ReadBytes(6); block.EntryFields[i] = entry; + entryCount++; } blocks.Add(block); @@ -378,7 +384,8 @@ namespace BurnOutSharp.Builders var blocks = new List(); // Try to parse the signature blocks - while (data.Position < initialOffset + length) + int entryCount = 0; + while (entryCount < record.TotalNumberOfEntries && data.Position < initialOffset + length) { var block = new HostRevocationSignatureBlock(); @@ -392,6 +399,7 @@ namespace BurnOutSharp.Builders entry.HostID = data.ReadBytes(6); block.EntryFields[i] = entry; + entryCount++; } blocks.Add(block); diff --git a/BurnOutSharp/FileType/AACSMediaKeyBlock.cs b/BurnOutSharp/FileType/AACSMediaKeyBlock.cs new file mode 100644 index 00000000..14f8e9f3 --- /dev/null +++ b/BurnOutSharp/FileType/AACSMediaKeyBlock.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Concurrent; +using System.IO; +using System.Linq; +using BurnOutSharp.Interfaces; + +namespace BurnOutSharp.FileType +{ + /// + /// AACS media key block + /// + public class AACSMediaKeyBlock : IScannable + { + /// + public ConcurrentDictionary> Scan(Scanner scanner, string file) + { + if (!File.Exists(file)) + return null; + + using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + return Scan(scanner, fs, file); + } + } + + /// + public ConcurrentDictionary> Scan(Scanner scanner, Stream stream, string file) + { + // If the MKB file itself fails + try + { + string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + Directory.CreateDirectory(tempPath); + + // Create the wrapper + Wrappers.AACSMediaKeyBlock mkb = Wrappers.AACSMediaKeyBlock.Create(stream); + if (mkb == null) + return null; + + // Setup the output + var protections = new ConcurrentDictionary>(); + protections[file] = new ConcurrentQueue(); + + var typeAndVersion = mkb.Records.FirstOrDefault(r => r.RecordType == Models.AACS.RecordType.TypeAndVersion); + if (typeAndVersion == null) + protections[file].Enqueue("AACS (Unknown Version)"); + else + protections[file].Enqueue($"AACS {(typeAndVersion as Models.AACS.TypeAndVersionRecord).VersionNumber}"); + + return protections; + } + catch (Exception ex) + { + if (scanner.IncludeDebug) Console.WriteLine(ex); + } + + return null; + } + } +} diff --git a/BurnOutSharp/ProtectionType/AACS.cs b/BurnOutSharp/ProtectionType/AACS.cs deleted file mode 100644 index eec2e3cf..00000000 --- a/BurnOutSharp/ProtectionType/AACS.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.IO; -using BurnOutSharp.Interfaces; -using BurnOutSharp.Matching; - -namespace BurnOutSharp.ProtectionType -{ - public class AACS : IPathCheck - { - /// - public ConcurrentQueue CheckDirectoryPath(string path, IEnumerable files) - { - var matchers = new List - { - // BD-ROM - new PathMatchSet(Path.Combine("AACS", "MKB_RO.inf").Replace("\\", "/"), GetVersion, "AACS"), - - // HD-DVD - new PathMatchSet(Path.Combine("AACS", "MKBROM.AACS").Replace("\\", "/"), GetVersion, "AACS"), - }; - - return MatchUtil.GetAllMatches(files, matchers, any: true); - } - - /// - public string CheckFilePath(string path) - { - var matchers = new List - { - // BD-ROM - new PathMatchSet(new PathMatch("MKB_RO.inf", useEndsWith: true), GetVersion, "AACS"), - - // HD-DVD - new PathMatchSet(new PathMatch("MKBROM.AACS", useEndsWith: true), GetVersion, "AACS"), - }; - - return MatchUtil.GetFirstMatch(path, matchers, any: true); - } - - public static string GetVersion(string firstMatchedString, IEnumerable files) - { - if (!File.Exists(firstMatchedString)) - return "(Unknown Version)"; - - try - { - using (var fs = File.OpenRead(firstMatchedString)) - { - fs.Seek(0xB, SeekOrigin.Begin); - return fs.ReadByte().ToString(); - } - } - catch - { - return "(Unknown Version)"; - } - } - } -} diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs index cadff05c..c4d20b9e 100644 --- a/BurnOutSharp/Scanner.cs +++ b/BurnOutSharp/Scanner.cs @@ -352,6 +352,13 @@ namespace BurnOutSharp // If we're scanning file contents if (ScanContents) { + // AACS media key block + if (scannable is AACSMediaKeyBlock) + { + var subProtections = scannable.Scan(this, stream, fileName); + AppendToDictionary(protections, subProtections); + } + // Executable if (scannable is Executable) { diff --git a/BurnOutSharp/Tools/Utilities.cs b/BurnOutSharp/Tools/Utilities.cs index 1d4e8258..2f1fd174 100644 --- a/BurnOutSharp/Tools/Utilities.cs +++ b/BurnOutSharp/Tools/Utilities.cs @@ -756,7 +756,7 @@ namespace BurnOutSharp.Tools { switch (fileType) { - // case SupportedFileType.AACSMediaKeyBlock: return new FileType.AACSMediaKeyBlock(); + case SupportedFileType.AACSMediaKeyBlock: return new FileType.AACSMediaKeyBlock(); case SupportedFileType.BFPK: return new FileType.BFPK(); case SupportedFileType.BSP: return new FileType.BSP(); case SupportedFileType.BZip2: return new FileType.BZip2();