diff --git a/BinaryObjectScanner.Printing/AACSMediaKeyBlock.cs b/BinaryObjectScanner.Printing/AACSMediaKeyBlock.cs new file mode 100644 index 00000000..93b07cbf --- /dev/null +++ b/BinaryObjectScanner.Printing/AACSMediaKeyBlock.cs @@ -0,0 +1,330 @@ +using System; +using System.Text; +using SabreTools.Models.AACS; + +namespace BinaryObjectScanner.Printing +{ + public static class AACSMediaKeyBlock + { + public static void Print(StringBuilder builder, MediaKeyBlock mediaKeyBlock) + { + builder.AppendLine("AACS Media Key Block Information:"); + builder.AppendLine("-------------------------"); + builder.AppendLine(); + + Print(builder, mediaKeyBlock.Records); + } + +#if NET48 + private static void Print(StringBuilder builder, Record[] records) +#else + private static void Print(StringBuilder builder, Record?[]? records) +#endif + { + builder.AppendLine(" Records Information:"); + builder.AppendLine(" -------------------------"); + if (records == null || records.Length == 0) + { + builder.AppendLine(" No records"); + } + else + { + for (int i = 0; i < records.Length; i++) + { + var record = records[i]; + Print(builder, record, i); + } + } + builder.AppendLine(); + } + +#if NET48 + private static void Print(StringBuilder builder, Record record, int index) +#else + private static void Print(StringBuilder builder, Record? record, int index) +#endif + { + builder.AppendLine($" Record Entry {index}"); + if (record == null) + { + builder.AppendLine(" [NULL]"); + return; + } + + builder.AppendLine($" Record type: {record.RecordType} (0x{record.RecordType:X})"); + builder.AppendLine($" Record length: {record.RecordLength} (0x{record.RecordLength:X})"); + + switch (record) + { + case EndOfMediaKeyBlockRecord eomkb: + Print(builder, eomkb); + break; + case ExplicitSubsetDifferenceRecord esd: + Print(builder, esd); + break; + case MediaKeyDataRecord mkd: + Print(builder, mkd); + break; + case SubsetDifferenceIndexRecord sdi: + Print(builder, sdi); + break; + case TypeAndVersionRecord tav: + Print(builder, tav); + break; + case DriveRevocationListRecord drl: + Print(builder, drl); + break; + case HostRevocationListRecord hrl: + Print(builder, hrl); + break; + case VerifyMediaKeyRecord vmk: + Print(builder, vmk); + break; + case CopyrightRecord c: + Print(builder, c); + break; + } + } + +#if NET48 + private static void Print(StringBuilder builder, EndOfMediaKeyBlockRecord record) +#else + private static void Print(StringBuilder builder, EndOfMediaKeyBlockRecord record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Signature data: {(record.SignatureData == null ? "[NULL]" : BitConverter.ToString(record.SignatureData).Replace('-', ' '))}"); + } + +#if NET48 + private static void Print(StringBuilder builder, ExplicitSubsetDifferenceRecord record) +#else + private static void Print(StringBuilder builder, ExplicitSubsetDifferenceRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Subset Differences:"); + builder.AppendLine(" -------------------------"); + if (record?.SubsetDifferences == null || record.SubsetDifferences.Length == 0) + { + builder.AppendLine($" No subset differences"); + return; + } + + for (int j = 0; j < record.SubsetDifferences.Length; j++) + { + var sd = record.SubsetDifferences[j]; + builder.AppendLine($" Subset Difference {j}"); + if (sd == null) + { + builder.AppendLine(" [NULL]"); + } + else + { + builder.AppendLine($" Mask: {sd.Mask} (0x{sd.Mask:X})"); + builder.AppendLine($" Number: {sd.Number} (0x{sd.Number:X})"); + } + } + } + +#if NET48 + private static void Print(StringBuilder builder, MediaKeyDataRecord record) +#else + private static void Print(StringBuilder builder, MediaKeyDataRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Media Keys:"); + builder.AppendLine(" -------------------------"); + if (record?.MediaKeyData == null || record.MediaKeyData.Length == 0) + { + builder.AppendLine($" No media keys"); + return; + } + + for (int j = 0; j < record.MediaKeyData.Length; j++) + { + var mk = record.MediaKeyData[j]; + builder.AppendLine($" Media key {j}: {(mk == null ? "[NULL]" : BitConverter.ToString(mk).Replace('-', ' '))}"); + } + } + +#if NET48 + private static void Print(StringBuilder builder, SubsetDifferenceIndexRecord record) +#else + private static void Print(StringBuilder builder, SubsetDifferenceIndexRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Span: {record.Span} (0x{record.Span:X})"); + builder.AppendLine($" Offsets:"); + builder.AppendLine(" -------------------------"); + if (record.Offsets == null || record.Offsets.Length == 0) + { + builder.AppendLine($" No offsets"); + return; + } + + for (int j = 0; j < record.Offsets.Length; j++) + { + var offset = record.Offsets[j]; + builder.AppendLine($" Offset {j}: {offset} (0x{offset:X})"); + } + } + +#if NET48 + private static void Print(StringBuilder builder, TypeAndVersionRecord record) +#else + private static void Print(StringBuilder builder, TypeAndVersionRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Media key block type: {record.MediaKeyBlockType} (0x{record.MediaKeyBlockType:X})"); + builder.AppendLine($" Version number: {record.VersionNumber} (0x{record.VersionNumber:X})"); + } + +#if NET48 + private static void Print(StringBuilder builder, DriveRevocationListRecord record) +#else + private static void Print(StringBuilder builder, DriveRevocationListRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Total number of entries: {record.TotalNumberOfEntries} (0x{record.TotalNumberOfEntries:X})"); + builder.AppendLine($" Signature Blocks:"); + builder.AppendLine(" -------------------------"); + if (record.SignatureBlocks == null || record.SignatureBlocks.Length == 0) + { + builder.AppendLine($" No signature blocks"); + return; + } + + for (int j = 0; j < record.SignatureBlocks.Length; j++) + { + var block = record.SignatureBlocks[j]; + builder.AppendLine($" Signature Block {j}"); + if (block == null) + { + builder.AppendLine(" [NULL]"); + continue; + } + + builder.AppendLine($" Number of entries: {block.NumberOfEntries}"); + builder.AppendLine($" Entry Fields:"); + builder.AppendLine(" -------------------------"); + if (block.EntryFields == null || block.EntryFields.Length == 0) + { + builder.AppendLine($" No entry fields"); + } + else + { + for (int k = 0; k < block.EntryFields.Length; k++) + { + var ef = block.EntryFields[k]; + builder.AppendLine($" Entry {k}"); + if (ef == null) + { + builder.AppendLine(" [NULL]"); + } + else + { + builder.AppendLine($" Range: {ef.Range} (0x{ef.Range:X})"); + builder.AppendLine($" Drive ID: {(ef.DriveID == null ? "[NULL]" : BitConverter.ToString(ef.DriveID).Replace('-', ' '))}"); + } + } + } + } + } + +#if NET48 + private static void Print(StringBuilder builder, HostRevocationListRecord record) +#else + private static void Print(StringBuilder builder, HostRevocationListRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Total number of entries: {record.TotalNumberOfEntries} (0x{record.TotalNumberOfEntries:X})"); + builder.AppendLine($" Signature Blocks:"); + builder.AppendLine(" -------------------------"); + if (record.SignatureBlocks == null || record.SignatureBlocks.Length == 0) + { + builder.AppendLine($" No signature blocks"); + return; + } + + for (int j = 0; j < record.SignatureBlocks.Length; j++) + { + builder.AppendLine($" Signature Block {j}"); + var block = record.SignatureBlocks[j]; + if (block == null) + { + builder.AppendLine(" [NULL]"); + continue; + } + + builder.AppendLine($" Number of entries: {block.NumberOfEntries}"); + builder.AppendLine($" Entry Fields:"); + builder.AppendLine(" -------------------------"); + if (block.EntryFields == null || block.EntryFields.Length == 0) + { + builder.AppendLine($" No entry fields"); + continue; + } + + for (int k = 0; k < block.EntryFields.Length; k++) + { + var ef = block.EntryFields[k]; + builder.AppendLine($" Entry {k}"); + if (ef == null) + { + builder.AppendLine(" [NULL]"); + } + else + { + + builder.AppendLine($" Range: {ef.Range} (0x{ef.Range:X})"); + builder.AppendLine($" Host ID: {(ef.HostID == null ? "[NULL]" : BitConverter.ToString(ef.HostID).Replace('-', ' '))}"); + } + } + } + } + +#if NET48 + private static void Print(StringBuilder builder, VerifyMediaKeyRecord record) +#else + private static void Print(StringBuilder builder, VerifyMediaKeyRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Ciphertext value: {(record.CiphertextValue == null ? "[NULL]" : BitConverter.ToString(record.CiphertextValue).Replace('-', ' '))}"); + } + +#if NET48 + private static void Print(StringBuilder builder, CopyrightRecord record) +#else + private static void Print(StringBuilder builder, CopyrightRecord? record) +#endif + { + if (record == null) + return; + + builder.AppendLine($" Copyright: {record.Copyright ?? "[NULL]"}"); + } + } +} \ No newline at end of file diff --git a/BinaryObjectScanner.Printing/BinaryObjectScanner.Printing.csproj b/BinaryObjectScanner.Printing/BinaryObjectScanner.Printing.csproj new file mode 100644 index 00000000..ed7d1258 --- /dev/null +++ b/BinaryObjectScanner.Printing/BinaryObjectScanner.Printing.csproj @@ -0,0 +1,32 @@ + + + + net48;net6.0;net7.0 + win-x86;win-x64;linux-x64;osx-x64 + BinaryObjectScanner.Printing + BinaryObjectScanner.Printing + Matt Nadareski + BurnOutSharp + Copyright (c)2022-2023 Matt Nadareski + https://github.com/mnadareski/BurnOutSharp + 2.8 + 2.8 + 2.8 + true + true + + + + true + + + + enable + + + + + + + + \ No newline at end of file diff --git a/BinaryObjectScanner.Wrappers/AACSMediaKeyBlock.cs b/BinaryObjectScanner.Wrappers/AACSMediaKeyBlock.cs index 8a909a13..6a990403 100644 --- a/BinaryObjectScanner.Wrappers/AACSMediaKeyBlock.cs +++ b/BinaryObjectScanner.Wrappers/AACSMediaKeyBlock.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using System.Text; using SabreTools.Models.AACS; @@ -115,331 +114,10 @@ namespace BinaryObjectScanner.Wrappers public override StringBuilder PrettyPrint() { StringBuilder builder = new StringBuilder(); - Print(builder, _model); + Printing.AACSMediaKeyBlock.Print(builder, _model); return builder; } - private static void Print(StringBuilder builder, MediaKeyBlock mediaKeyBlock) - { - builder.AppendLine("AACS Media Key Block Information:"); - builder.AppendLine("-------------------------"); - builder.AppendLine(); - - Print(builder, mediaKeyBlock.Records); - } - -#if NET48 - private static void Print(StringBuilder builder, Record[] records) -#else - private static void Print(StringBuilder builder, Record?[]? records) -#endif - { - builder.AppendLine(" Records Information:"); - builder.AppendLine(" -------------------------"); - if (records == null || records.Length == 0) - { - builder.AppendLine(" No records"); - } - else - { - for (int i = 0; i < records.Length; i++) - { - var record = records[i]; - Print(builder, record, i); - } - } - builder.AppendLine(); - } - -#if NET48 - private static void Print(StringBuilder builder, Record record, int index) -#else - private static void Print(StringBuilder builder, Record? record, int index) -#endif - { - builder.AppendLine($" Record Entry {index}"); - if (record == null) - { - builder.AppendLine(" [NULL]"); - return; - } - - builder.AppendLine($" Record type: {record.RecordType} (0x{record.RecordType:X})"); - builder.AppendLine($" Record length: {record.RecordLength} (0x{record.RecordLength:X})"); - - switch (record) - { - case EndOfMediaKeyBlockRecord eomkb: - Print(builder, eomkb); - break; - case ExplicitSubsetDifferenceRecord esd: - Print(builder, esd); - break; - case MediaKeyDataRecord mkd: - Print(builder, mkd); - break; - case SubsetDifferenceIndexRecord sdi: - Print(builder, sdi); - break; - case TypeAndVersionRecord tav: - Print(builder, tav); - break; - case DriveRevocationListRecord drl: - Print(builder, drl); - break; - case HostRevocationListRecord hrl: - Print(builder, hrl); - break; - case VerifyMediaKeyRecord vmk: - Print(builder, vmk); - break; - case CopyrightRecord c: - Print(builder, c); - break; - } - } - -#if NET48 - private static void Print(StringBuilder builder, EndOfMediaKeyBlockRecord record) -#else - private static void Print(StringBuilder builder, EndOfMediaKeyBlockRecord record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Signature data: {(record.SignatureData == null ? "[NULL]" : BitConverter.ToString(record.SignatureData).Replace('-', ' '))}"); - } - -#if NET48 - private static void Print(StringBuilder builder, ExplicitSubsetDifferenceRecord record) -#else - private static void Print(StringBuilder builder, ExplicitSubsetDifferenceRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Subset Differences:"); - builder.AppendLine(" -------------------------"); - if (record?.SubsetDifferences == null || record.SubsetDifferences.Length == 0) - { - builder.AppendLine($" No subset differences"); - return; - } - - for (int j = 0; j < record.SubsetDifferences.Length; j++) - { - var sd = record.SubsetDifferences[j]; - builder.AppendLine($" Subset Difference {j}"); - if (sd == null) - { - builder.AppendLine(" [NULL]"); - } - else - { - builder.AppendLine($" Mask: {sd.Mask} (0x{sd.Mask:X})"); - builder.AppendLine($" Number: {sd.Number} (0x{sd.Number:X})"); - } - } - } - -#if NET48 - private static void Print(StringBuilder builder, MediaKeyDataRecord record) -#else - private static void Print(StringBuilder builder, MediaKeyDataRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Media Keys:"); - builder.AppendLine(" -------------------------"); - if (record?.MediaKeyData == null || record.MediaKeyData.Length == 0) - { - builder.AppendLine($" No media keys"); - return; - } - - for (int j = 0; j < record.MediaKeyData.Length; j++) - { - var mk = record.MediaKeyData[j]; - builder.AppendLine($" Media key {j}: {(mk == null ? "[NULL]" : BitConverter.ToString(mk).Replace('-', ' '))}"); - } - } - -#if NET48 - private static void Print(StringBuilder builder, SubsetDifferenceIndexRecord record) -#else - private static void Print(StringBuilder builder, SubsetDifferenceIndexRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Span: {record.Span} (0x{record.Span:X})"); - builder.AppendLine($" Offsets:"); - builder.AppendLine(" -------------------------"); - if (record.Offsets == null || record.Offsets.Length == 0) - { - builder.AppendLine($" No offsets"); - return; - } - - for (int j = 0; j < record.Offsets.Length; j++) - { - var offset = record.Offsets[j]; - builder.AppendLine($" Offset {j}: {offset} (0x{offset:X})"); - } - } - -#if NET48 - private static void Print(StringBuilder builder, TypeAndVersionRecord record) -#else - private static void Print(StringBuilder builder, TypeAndVersionRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Media key block type: {record.MediaKeyBlockType} (0x{record.MediaKeyBlockType:X})"); - builder.AppendLine($" Version number: {record.VersionNumber} (0x{record.VersionNumber:X})"); - } - -#if NET48 - private static void Print(StringBuilder builder, DriveRevocationListRecord record) -#else - private static void Print(StringBuilder builder, DriveRevocationListRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Total number of entries: {record.TotalNumberOfEntries} (0x{record.TotalNumberOfEntries:X})"); - builder.AppendLine($" Signature Blocks:"); - builder.AppendLine(" -------------------------"); - if (record.SignatureBlocks == null || record.SignatureBlocks.Length == 0) - { - builder.AppendLine($" No signature blocks"); - return; - } - - for (int j = 0; j < record.SignatureBlocks.Length; j++) - { - var block = record.SignatureBlocks[j]; - builder.AppendLine($" Signature Block {j}"); - if (block == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - - builder.AppendLine($" Number of entries: {block.NumberOfEntries}"); - builder.AppendLine($" Entry Fields:"); - builder.AppendLine(" -------------------------"); - if (block.EntryFields == null || block.EntryFields.Length == 0) - { - builder.AppendLine($" No entry fields"); - } - else - { - for (int k = 0; k < block.EntryFields.Length; k++) - { - var ef = block.EntryFields[k]; - builder.AppendLine($" Entry {k}"); - if (ef == null) - { - builder.AppendLine(" [NULL]"); - } - else - { - builder.AppendLine($" Range: {ef.Range} (0x{ef.Range:X})"); - builder.AppendLine($" Drive ID: {(ef.DriveID == null ? "[NULL]" : BitConverter.ToString(ef.DriveID).Replace('-', ' '))}"); - } - } - } - } - } - -#if NET48 - private static void Print(StringBuilder builder, HostRevocationListRecord record) -#else - private static void Print(StringBuilder builder, HostRevocationListRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Total number of entries: {record.TotalNumberOfEntries} (0x{record.TotalNumberOfEntries:X})"); - builder.AppendLine($" Signature Blocks:"); - builder.AppendLine(" -------------------------"); - if (record.SignatureBlocks == null || record.SignatureBlocks.Length == 0) - { - builder.AppendLine($" No signature blocks"); - return; - } - - for (int j = 0; j < record.SignatureBlocks.Length; j++) - { - builder.AppendLine($" Signature Block {j}"); - var block = record.SignatureBlocks[j]; - if (block == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - - builder.AppendLine($" Number of entries: {block.NumberOfEntries}"); - builder.AppendLine($" Entry Fields:"); - builder.AppendLine(" -------------------------"); - if (block.EntryFields == null || block.EntryFields.Length == 0) - { - builder.AppendLine($" No entry fields"); - continue; - } - - for (int k = 0; k < block.EntryFields.Length; k++) - { - var ef = block.EntryFields[k]; - builder.AppendLine($" Entry {k}"); - if (ef == null) - { - builder.AppendLine(" [NULL]"); - } - else - { - - builder.AppendLine($" Range: {ef.Range} (0x{ef.Range:X})"); - builder.AppendLine($" Host ID: {(ef.HostID == null ? "[NULL]" : BitConverter.ToString(ef.HostID).Replace('-', ' '))}"); - } - } - } - } - -#if NET48 - private static void Print(StringBuilder builder, VerifyMediaKeyRecord record) -#else - private static void Print(StringBuilder builder, VerifyMediaKeyRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Ciphertext value: {(record.CiphertextValue == null ? "[NULL]" : BitConverter.ToString(record.CiphertextValue).Replace('-', ' '))}"); - } - -#if NET48 - private static void Print(StringBuilder builder, CopyrightRecord record) -#else - private static void Print(StringBuilder builder, CopyrightRecord? record) -#endif - { - if (record == null) - return; - - builder.AppendLine($" Copyright: {record.Copyright ?? "[NULL]"}"); - } - #if NET6_0_OR_GREATER /// diff --git a/BinaryObjectScanner.Wrappers/BinaryObjectScanner.Wrappers.csproj b/BinaryObjectScanner.Wrappers/BinaryObjectScanner.Wrappers.csproj index bd865471..15849f8b 100644 --- a/BinaryObjectScanner.Wrappers/BinaryObjectScanner.Wrappers.csproj +++ b/BinaryObjectScanner.Wrappers/BinaryObjectScanner.Wrappers.csproj @@ -26,6 +26,7 @@ + diff --git a/BurnOutSharp.sln b/BurnOutSharp.sln index 5ea5021b..553d0851 100644 --- a/BurnOutSharp.sln +++ b/BurnOutSharp.sln @@ -36,6 +36,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BinaryObjectScanner.FileTyp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryObjectScanner.GameEngine", "BinaryObjectScanner.GameEngine\BinaryObjectScanner.GameEngine.csproj", "{8AFC9C4C-CC57-4382-8C32-F6B4C46E321A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryObjectScanner.Printing", "BinaryObjectScanner.Printing\BinaryObjectScanner.Printing.csproj", "{E01BAF82-F5BB-4CD0-A5C7-312EB4EEC82B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -90,6 +92,10 @@ Global {8AFC9C4C-CC57-4382-8C32-F6B4C46E321A}.Debug|Any CPU.Build.0 = Debug|Any CPU {8AFC9C4C-CC57-4382-8C32-F6B4C46E321A}.Release|Any CPU.ActiveCfg = Release|Any CPU {8AFC9C4C-CC57-4382-8C32-F6B4C46E321A}.Release|Any CPU.Build.0 = Release|Any CPU + {E01BAF82-F5BB-4CD0-A5C7-312EB4EEC82B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E01BAF82-F5BB-4CD0-A5C7-312EB4EEC82B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E01BAF82-F5BB-4CD0-A5C7-312EB4EEC82B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E01BAF82-F5BB-4CD0-A5C7-312EB4EEC82B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BurnOutSharp/BurnOutSharp.csproj b/BurnOutSharp/BurnOutSharp.csproj index 64d79bc5..258f426b 100644 --- a/BurnOutSharp/BurnOutSharp.csproj +++ b/BurnOutSharp/BurnOutSharp.csproj @@ -60,6 +60,10 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive all