diff --git a/.editorconfig b/.editorconfig index 71a0517..103a5d9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -83,7 +83,7 @@ resharper_braces_for_ifelse resharper_braces_for_while = required_for_multiline resharper_builtin_type_apply_to_native_integer = false resharper_constructor_or_destructor_body = expression_body -resharper_csharp_align_first_arg_by_paren = false +resharper_csharp_align_first_arg_by_paren = true resharper_csharp_empty_block_style = together_same_line resharper_csharp_place_comments_at_first_column = true resharper_csharp_prefer_qualified_reference = false @@ -108,6 +108,7 @@ resharper_int_align_enum_initializers resharper_int_align_eq = true resharper_keep_existing_embedded_arrangement = false resharper_keep_existing_initializer_arrangement = false +resharper_keep_existing_linebreaks = false resharper_keep_existing_list_patterns_arrangement = false resharper_keep_existing_property_patterns_arrangement = false resharper_keep_existing_switch_expression_arrangement = false @@ -125,6 +126,7 @@ resharper_outdent_statement_labels resharper_parentheses_redundancy_style = remove resharper_place_attribute_on_same_line = false resharper_place_simple_embedded_statement_on_same_line = false +resharper_place_simple_initializer_on_single_line = false resharper_qualified_using_at_nested_scope = true resharper_show_autodetect_configure_formatting_tip = false resharper_simple_block_style = on_single_line @@ -146,6 +148,8 @@ resharper_use_indent_from_vs resharper_wrap_after_dot_in_method_calls = true resharper_wrap_base_clause_style = chop_if_long resharper_wrap_braced_init_list_style = chop_if_long +resharper_wrap_chained_binary_expressions = chop_if_long +resharper_wrap_chained_method_calls = chop_if_long resharper_wrap_ctor_initializer_style = chop_if_long resharper_wrap_lines = true resharper_xmldoc_attribute_indent = align_by_first_attribute diff --git a/DVD/CSS.cs b/DVD/CSS.cs index 08f84c1..787eb9c 100644 --- a/DVD/CSS.cs +++ b/DVD/CSS.cs @@ -58,17 +58,99 @@ public class CSS { static readonly byte[,] _playerKeys = { - { 0x01, 0xaf, 0xe3, 0x12, 0x80 }, { 0x12, 0x11, 0xca, 0x04, 0x3b }, { 0x14, 0x0c, 0x9e, 0xd0, 0x09 }, - { 0x14, 0x71, 0x35, 0xba, 0xe2 }, { 0x1a, 0xa4, 0x33, 0x21, 0xa6 }, { 0x26, 0xec, 0xc4, 0xa7, 0x4e }, - { 0x2c, 0xb2, 0xc1, 0x09, 0xee }, { 0x2f, 0x25, 0x9e, 0x96, 0xdd }, { 0x33, 0x2f, 0x49, 0x6c, 0xe0 }, - { 0x35, 0x5b, 0xc1, 0x31, 0x0f }, { 0x36, 0x67, 0xb2, 0xe3, 0x85 }, { 0x39, 0x3d, 0xf1, 0xf1, 0xbd }, - { 0x3b, 0x31, 0x34, 0x0d, 0x91 }, { 0x45, 0xed, 0x28, 0xeb, 0xd3 }, { 0x48, 0xb7, 0x6c, 0xce, 0x69 }, - { 0x4b, 0x65, 0x0d, 0xc1, 0xee }, { 0x4c, 0xbb, 0xf5, 0x5b, 0x23 }, { 0x51, 0x67, 0x67, 0xc5, 0xe0 }, - { 0x53, 0x94, 0xe1, 0x75, 0xbf }, { 0x57, 0x2c, 0x8b, 0x31, 0xae }, { 0x63, 0xdb, 0x4c, 0x5b, 0x4a }, - { 0x7b, 0x1e, 0x5e, 0x2b, 0x57 }, { 0x85, 0xf3, 0x85, 0xa0, 0xe0 }, { 0xab, 0x1e, 0xe7, 0x7b, 0x72 }, - { 0xab, 0x36, 0xe3, 0xeb, 0x76 }, { 0xb1, 0xb8, 0xf9, 0x38, 0x03 }, { 0xb8, 0x5d, 0xd8, 0x53, 0xbd }, - { 0xbf, 0x92, 0xc3, 0xb0, 0xe2 }, { 0xcf, 0x1a, 0xb2, 0xf8, 0x0a }, { 0xec, 0xa0, 0xcf, 0xb3, 0xff }, - { 0xfc, 0x95, 0xa9, 0x87, 0x35 } + { + 0x01, 0xaf, 0xe3, 0x12, 0x80 + }, + { + 0x12, 0x11, 0xca, 0x04, 0x3b + }, + { + 0x14, 0x0c, 0x9e, 0xd0, 0x09 + }, + { + 0x14, 0x71, 0x35, 0xba, 0xe2 + }, + { + 0x1a, 0xa4, 0x33, 0x21, 0xa6 + }, + { + 0x26, 0xec, 0xc4, 0xa7, 0x4e + }, + { + 0x2c, 0xb2, 0xc1, 0x09, 0xee + }, + { + 0x2f, 0x25, 0x9e, 0x96, 0xdd + }, + { + 0x33, 0x2f, 0x49, 0x6c, 0xe0 + }, + { + 0x35, 0x5b, 0xc1, 0x31, 0x0f + }, + { + 0x36, 0x67, 0xb2, 0xe3, 0x85 + }, + { + 0x39, 0x3d, 0xf1, 0xf1, 0xbd + }, + { + 0x3b, 0x31, 0x34, 0x0d, 0x91 + }, + { + 0x45, 0xed, 0x28, 0xeb, 0xd3 + }, + { + 0x48, 0xb7, 0x6c, 0xce, 0x69 + }, + { + 0x4b, 0x65, 0x0d, 0xc1, 0xee + }, + { + 0x4c, 0xbb, 0xf5, 0x5b, 0x23 + }, + { + 0x51, 0x67, 0x67, 0xc5, 0xe0 + }, + { + 0x53, 0x94, 0xe1, 0x75, 0xbf + }, + { + 0x57, 0x2c, 0x8b, 0x31, 0xae + }, + { + 0x63, 0xdb, 0x4c, 0x5b, 0x4a + }, + { + 0x7b, 0x1e, 0x5e, 0x2b, 0x57 + }, + { + 0x85, 0xf3, 0x85, 0xa0, 0xe0 + }, + { + 0xab, 0x1e, 0xe7, 0x7b, 0x72 + }, + { + 0xab, 0x36, 0xe3, 0xeb, 0x76 + }, + { + 0xb1, 0xb8, 0xf9, 0x38, 0x03 + }, + { + 0xb8, 0x5d, 0xd8, 0x53, 0xbd + }, + { + 0xbf, 0x92, 0xc3, 0xb0, 0xe2 + }, + { + 0xcf, 0x1a, 0xb2, 0xf8, 0x0a + }, + { + 0xec, 0xa0, 0xcf, 0xb3, 0xff + }, + { + 0xfc, 0x95, 0xa9, 0x87, 0x35 + } }; static readonly byte[] _cssTable1 = @@ -259,7 +341,15 @@ public class CSS static readonly byte[,] _permutationChallenge = { - { 1, 3, 0, 7, 5, 2, 9, 6, 4, 8 }, { 6, 1, 9, 3, 8, 5, 7, 4, 0, 2 }, { 4, 0, 3, 5, 7, 2, 8, 6, 1, 9 } + { + 1, 3, 0, 7, 5, 2, 9, 6, 4, 8 + }, + { + 6, 1, 9, 3, 8, 5, 7, 4, 0, 2 + }, + { + 4, 0, 3, 5, 7, 2, 8, 6, 1, 9 + } }; static readonly byte[,] _permutationVariant = @@ -280,7 +370,10 @@ public class CSS 0xF2, 0x2A, 0x79, 0x52, 0xFF, 0x1B, 0x7A, 0x11, 0xCA, 0x1A, 0x9B, 0x40, 0xAD, 0x01 }; - static readonly byte[] _secret = { 0x55, 0xD6, 0xC4, 0xC5, 0x28 }; + static readonly byte[] _secret = + { + 0x55, 0xD6, 0xC4, 0xC5, 0x28 + }; /// /// The disc key returned by the logical unit is encoded with the bus key to prevent man-in-the-middle attacks. @@ -291,8 +384,7 @@ public class CSS /// A DiscKey struct with the decoded key. public static CSS_CPRM.DiscKey? DecodeDiscKey(byte[] response, byte[] busKey) { - if(response.Length != 2052 || - busKey.Length != 5) + if(response.Length != 2052 || busKey.Length != 5) return null; byte[] key = response.Skip(4).Take(2048).ToArray(); @@ -318,8 +410,7 @@ public class CSS /// A TitleKey struct with the decoded key. public static CSS_CPRM.TitleKey? DecodeTitleKey(byte[] response, byte[] busKey) { - if(response.Length != 12 || - busKey.Length != 5) + if(response.Length != 12 || busKey.Length != 5) return null; byte[] key = response.Skip(5).Take(5).ToArray(); @@ -468,11 +559,12 @@ public class CSS var lfsr1Lo = (uint)(cryptoKey[0] | 0x100); uint lfsr1Hi = cryptoKey[1]; - var lfsr0 = (uint)((cryptoKey[4] << 17 | cryptoKey[3] << 9 | cryptoKey[2] << 1) + 8 - - (cryptoKey[2] & 7)); + var lfsr0 = (uint)((cryptoKey[4] << 17 | cryptoKey[3] << 9 | cryptoKey[2] << 1) + 8 - (cryptoKey[2] & 7)); - lfsr0 = (uint)(_cssTable4[lfsr0 & 0xff] << 24 | _cssTable4[lfsr0 >> 8 & 0xff] << 16 | - _cssTable4[lfsr0 >> 16 & 0xff] << 8 | _cssTable4[lfsr0 >> 24 & 0xff]); + lfsr0 = (uint)(_cssTable4[lfsr0 & 0xff] << 24 | + _cssTable4[lfsr0 >> 8 & 0xff] << 16 | + _cssTable4[lfsr0 >> 16 & 0xff] << 8 | + _cssTable4[lfsr0 >> 24 & 0xff]); uint combined = 0; @@ -515,8 +607,8 @@ public class CSS for(uint n = 0; n < _playerKeys.GetLength(0); n++) { - byte[] currentPlayerKey = Enumerable.Range(0, _playerKeys.GetLength(1)).Select(x => _playerKeys[n, x]). - ToArray(); + byte[] currentPlayerKey = + Enumerable.Range(0, _playerKeys.GetLength(1)).Select(x => _playerKeys[n, x]).ToArray(); for(uint i = 1; i < 409; i++) { @@ -546,8 +638,7 @@ public class CSS uint blockSize = 2048) { // None of the sectors are encrypted - if(cmiData != null && cmiData.All(static cmi => (cmi & 0x80) >> 7 == 0) || - keyData.All(static k => k == 0)) + if(cmiData != null && cmiData.All(static cmi => (cmi & 0x80) >> 7 == 0) || keyData.All(static k => k == 0)) return sectorData; var decryptedBuffer = new byte[sectorData.Length]; @@ -582,8 +673,7 @@ public class CSS long lfsr1Lo = key[0] ^ sector[0x54] | 0x100; long lfsr1Hi = key[1] ^ sector[0x55]; - long lfsr0 = (key[2] | key[3] << 8 | key[4] << 16) ^ - (sector[0x56] | sector[0x57] << 8 | sector[0x58] << 16); + long lfsr0 = (key[2] | key[3] << 8 | key[4] << 16) ^ (sector[0x56] | sector[0x57] << 8 | sector[0x58] << 16); long oLfsr1 = lfsr0 & 7; lfsr0 = lfsr0 * 2 + 8 - oLfsr1; @@ -635,13 +725,11 @@ public class CSS return false; // The CMI tells us the sector is not encrypted. - if(cmi != null && - (cmi & 0x80) >> 7 == 0) + if(cmi != null && (cmi & 0x80) >> 7 == 0) return false; // We have the key but it's all zeroes, so sector is unencrypted. - if(key != null && - key.All(static k => k == 0)) + if(key != null && key.All(static k => k == 0)) return false; // These packet types cannot be encrypted @@ -703,9 +791,7 @@ public class CSS } // If we found an adequate pattern. - if(bestPattern <= 0 || - bestPatternLength <= 3 || - bestPatternLength / bestPattern < 2) + if(bestPattern <= 0 || bestPatternLength <= 3 || bestPatternLength / bestPattern < 2) return false; var offset = (int)(0x80 - bestPatternLength / bestPattern * bestPattern); @@ -890,8 +976,7 @@ public class CSS if(fs.OpenDir("VIDEO_TS", out IDirNode node) == ErrorNumber.NoError) { - while(fs.ReadDir(node, out string entry) == ErrorNumber.NoError && - entry is not null) + while(fs.ReadDir(node, out string entry) == ErrorNumber.NoError && entry is not null) { if(!entry.ToLower().EndsWith(".vob")) continue; diff --git a/DVD/Dump.cs b/DVD/Dump.cs index 3a1b8b0..a68c25f 100644 --- a/DVD/Dump.cs +++ b/DVD/Dump.cs @@ -73,8 +73,8 @@ public sealed class Dump(Device dev) dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); - AaruConsole.DebugWriteLine(MODULE_NAME, Localization.REPORT_ASF_AGID_1_Sense_2_Last_Error_3_took_0_ms, - duration, Agid, sense, dev.LastError); + AaruConsole.DebugWriteLine(MODULE_NAME, Localization.REPORT_ASF_AGID_1_Sense_2_Last_Error_3_took_0_ms, duration, + Agid, sense, dev.LastError); return sense; } @@ -101,8 +101,8 @@ public sealed class Dump(Device dev) dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); - AaruConsole.DebugWriteLine(MODULE_NAME, Localization.REPORT_ASF_AGID_1_Sense_2_Last_Error_3_took_0_ms, - duration, Agid, sense, dev.LastError); + AaruConsole.DebugWriteLine(MODULE_NAME, Localization.REPORT_ASF_AGID_1_Sense_2_Last_Error_3_took_0_ms, duration, + Agid, sense, dev.LastError); return sense; } @@ -157,9 +157,8 @@ public sealed class Dump(Device dev) dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); - AaruConsole.DebugWriteLine(MODULE_NAME, - Localization.REPORT_AGID_CSS_CPPM_AGID_1_Sense_2_Last_Error_3_took_0_ms, duration, - Agid, sense, dev.LastError); + AaruConsole.DebugWriteLine(MODULE_NAME, Localization.REPORT_AGID_CSS_CPPM_AGID_1_Sense_2_Last_Error_3_took_0_ms, + duration, Agid, sense, dev.LastError); return sense; } @@ -253,8 +252,7 @@ public sealed class Dump(Device dev) buffer[12] = challengeKey[1]; buffer[13] = challengeKey[0]; - dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration, - out bool sense); + dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration, out bool sense); AaruConsole.DebugWriteLine(MODULE_NAME, Localization.SEND_CHALLENGE_AGID_1_Challenge_2_Sense_3_Last_Error_4_took_0_ms, @@ -291,8 +289,7 @@ public sealed class Dump(Device dev) buffer[7] = key2[1]; buffer[8] = key2[0]; - dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration, - out bool sense); + dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration, out bool sense); AaruConsole.DebugWriteLine(MODULE_NAME, Localization.SEND_CHALLENGE_AGID_1_KEY2_2_Sense_3_Last_Error_4_took_0_ms, duration, diff --git a/DVD/MPEG.cs b/DVD/MPEG.cs index e3081d6..cceac4d 100644 --- a/DVD/MPEG.cs +++ b/DVD/MPEG.cs @@ -127,7 +127,10 @@ public class MPEG #endregion - static readonly byte[] _mpeg2PackHeaderStartCode = { 0x0, 0x0, 0x1 }; + static readonly byte[] _mpeg2PackHeaderStartCode = + { + 0x0, 0x0, 0x1 + }; public static bool ContainsMpegPackets(byte[] sectorData, uint blocks = 1, uint blockSize = 2048) {