diff --git a/.editorconfig b/.editorconfig index 9181fe501..25aaa3207 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,632 +1,216 @@ -root = true - [*] charset = utf-8 -next_line = crlf +end_of_line = lf +trim_trailing_whitespace = false insert_final_newline = false indent_style = space indent_size = 4 -# Generic non-language specific ones for Resharper and friends -brace_style = next_line -int_align = true -keep_existing_arrangement = false -place_simple_blocks_on_single_line = true -place_simple_declaration_blocks_on_single_line = true -place_attribute_on_same_line = false -space_after_unary_operator = false -space_after_comma = true -space_around_ternary_operator = true -space_around_binary_operator = true -space_around_member_access_operator = false -space_before_open_square_brackets = false -space_after_keywords_in_control_flow_statements = true -space_before_comma = false -space_between_method_call_name_and_opening_parenthesis = false -space_between_method_declaration_name_and_open_parenthesis = false -space_between_square_brackets = false -space_between_parentheses_of_control_flow_statements = false -accessor_owner_declaration_braces = next_line -accessor_declaration_braces = next_line -case_block_braces = next_line -initializer_braces = next_line -other_braces = next_line -allow_comment_after_lbrace = false -empty_block_style = together_same_line -braces_for_ifelse = not_required -braces_for_for = not_required -braces_for_foreach = not_required -braces_for_while = not_required -braces_for_dowhile = not_required -braces_for_using = not_required -braces_for_lock = not_required -braces_for_fixed = not_required -method_or_operator_body = expression_body -local_function_body = expression_body -constructor_or_destructor_body = expression_body -accessor_owner_body = expression_body -force_attribute_style = join -function_braces = next_line -force_control_statements_braces = always_remove -space_in_singleline_accessorholder = true -type_declaration_braces = next_line -invocable_declaration_braces = next_line -anonymous_method_declaration_braces = next_line -space_between_accessors_in_singleline_property = true -indent_nested_usings_stmt = true -space_within_empty_braces = false -indent_nested_fixed_stmt = true -indent_nested_lock_stmt = true -indent_nested_for_stmt = true -indent_nested_foreach_stmt = true -indent_nested_while_stmt = true -use_continuous_indent_inside_parens = true -indent_method_decl_pars = inside -indent_invocation_pars = inside -indent_statement_pars = inside -indent_typeparam_angles = inside -indent_typearg_angles = inside -indent_pars = inside -indent_preprocessor_if = outdent -indent_preprocessor_region = usual_indent -indent_preprocessor_other = usual_indent -indent_switch_labels = true -indent_type_constraints = true -stick_comment = false -alignment_tab_fill_style = use_spaces -align_multiline_parameter = true -align_multiline_extends_list = true -align_linq_query = true -align_multiline_binary_expressions_chain = true -outdent_binary_ops = true -align_multiline_calls_chain = true -outdent_dots = true -align_multiline_array_and_object_initializer = false -indent_anonymous_method_block = false -align_first_arg_by_paren = true -align_multiline_argument = true -align_tuple_components = true -align_multiline_expression = true -align_multiline_for_stmt = true -align_multiple_declaration = true -align_multline_type_parameter_list = true -align_multline_type_parameter_constrains = true -int_align_fields = true -int_align_properties = true -int_align_methods = true -int_align_parameters = false -int_align_variables = true -int_align_assignments = true -int_align_nested_ternary = true -int_align_invocations = false -int_align_binary_expressions = true -int_align_comments = true -int_align_switch_sections = true -keep_user_linebreaks = false -keep_existing_arrangement = false -keep_existing_linebreaks = false -max_line_length = 120 -wrap_before_comma = false -special_else_if_treatment = true -place_type_attribute_on_same_line = never -place_method_attribute_on_same_line = never -place_accessorholder_attribute_on_same_line = never -place_attribute_on_same_line = never -place_accessor_attribute_on_same_line = never -place_attribute_on_same_line = never -place_field_attribute_on_same_line = never -place_attribute_on_same_line = never -wrap_parameters_style = wrap_if_long -keep_existing_declaration_parens_arrangement = false -wrap_before_declaration_lpar = false -wrap_after_declaration_lpar = false -wrap_before_declaration_rpar = false -place_constructor_initializer_on_same_line = true -keep_existing_expr_member_arrangement = false -place_expr_method_on_single_line = true -place_expr_property_on_single_line = true -place_expr_accessor_on_single_line = true -wrap_before_arrow_with_expressions = false -place_type_constraints_on_same_line = true -wrap_before_first_type_parameter_constraint = true -wrap_multiple_type_parameter_constraints_style = wrap_if_long -wrap_before_type_parameter_langle = true -wrap_before_extends_colon = false -wrap_extends_list_style = wrap_if_long -keep_existing_declaration_block_arrangement = false -place_abstract_accessorholder_on_single_line = true -place_simple_accessorholder_on_single_line = false -place_accessor_with_attrs_holder_on_single_line = false -place_simple_accessor_on_single_line = true -place_simple_method_on_single_line = false -keep_existing_enum_arrangement = false -place_simple_enum_on_single_line = false -wrap_enum_declaration = wrap_if_long -new_line_before_else = true -new_line_before_while = false -wrap_for_stmt_header_style = wrap_if_long -wrap_multiple_declaration_style = wrap_if_long -keep_existing_embedded_arrangement = false -place_simple_embedded_statement_on_same_line = false -place_simple_case_statement_on_same_line = true -keep_existing_embedded_block_arrangement = false -place_simple_embedded_block_on_same_line = false -place_simple_anonymousmethod_on_single_line = false -keep_existing_initializer_arrangement = false -place_simple_initializer_on_single_line = false -wrap_object_and_collection_initializer_style = chop_always -wrap_array_initializer_style = wrap_if_long -wrap_arguments_style = wrap_if_long -keep_existing_invocation_parens_arrangement = false -wrap_after_invocation_lpar = false -wrap_before_invocation_rpar = false -wrap_after_dot_in_method_calls = true -wrap_chained_method_calls = wrap_if_long -wrap_before_binary_opsign = false -wrap_chained_binary_expressions = wrap_if_long -force_chop_compound_if_expression = true -force_chop_compound_while_expression = true -force_chop_compound_do_expression = true -wrap_before_ternary_opsigns = true -wrap_ternary_expr_style = wrap_if_long -nested_ternary_style = expanded -wrap_linq_expressions = wrap_if_long -wrap_before_linq_expression = false -place_linq_into_on_new_line = false -wrap_verbatim_interpolated_strings = wrap_if_long -extra_spaces = remove_all -space_after_keywords_in_control_flow_statements = false -space_between_method_call_name_and_opening_parenthesis = false -space_between_method_declaration_name_and_open_parenthesis = false -space_before_typeof_parentheses = false -space_before_checked_parentheses = false -space_before_sizeof_parentheses = false -space_before_nameof_parentheses = false -space_between_keyword_and_expression = true -space_between_keyword_and_type = true -space_around_assignment_op = true -space_around_logical_op = true -space_around_binary_operator = true -space_around_equality_op = true -space_around_relational_op = true -space_around_bitwise_op = true -space_around_additive_op = true -space_around_multiplicative_op = true -space_around_shift_op = true -space_around_nullcoalescing_op = true -space_around_arrow_op = false -space_after_logical_not_op = false -space_after_unary_operator = false -space_after_cast = false -space_around_dot = false -space_around_lambda_arrow = true -space_before_pointer_asterik_declaration = false -space_before_nullable_mark = false -blank_lines_around_class_definition = 1 -namespace_indentation = all -space_within_template_argument = false -align_union_type_usage = true -space_in_singleline_method = true -space_in_singleline_anonymous_method = true -space_within_single_line_array_initializer_braces = true -space_around_arrow_op = false - -# These are for markup languages (HTML, XML, etc) -spaces_around_eq_in_pi_attribute = false -space_after_last_pi_attribute = true -pi_attributes_indent = align_by_first_attribute -blank_line_after_pi = true -spaces_around_eq_in_attribute = false -space_after_last_attribute = false -space_before_self_closing = true -attribute_style = on_single_line -attribute_indent = align_by_first_attribute -sort_attributes = true -sort_class_selectors = true -max_blank_lines_between_tags = 0 -linebreak_before_all_elements = true -linebreak_before_multiline_elements = true -quote_style = doublequoted -delete_quotes_from_solid_values = false -normalize_tag_names = true - - -[{.babelrc,.stylelintrc,jest.config,.eslintrc,.prettierrc,*.json,*.jsb3,*.jsb2,*.bowerrc}] -indent_size = 2 - -[*.js.map] -indent_size = 2 - -[*.{css,scss}] -indent_size = 2 -declarations_style = separate_lines_for_nonsingle -media_query_style = separate_lines -selector_style = same_line -properties_style = separate_lines_for_nonsingle -brace_style = next_line - -[{.analysis_options,*.yml,*.yaml}] -indent_size = 2 - -# Xml project files -[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] -indent_size = 2 - -# Xml files -[*.{xml,stylecop,resx,ruleset}] -indent_size = 2 - -# Xml config files -[*.{props,targets,config,nuspec}] -indent_size = 2 - -# .net files -[*.{cs,vb}] -# These set the this. / Me. -dotnet_style_qualification_for_field = false:warning -dotnet_style_qualification_for_property = false:warning -dotnet_style_qualification_for_method = false:warning -dotnet_style_qualification_for_event = false:warning - -# These make it suggest Int32 instead of int, etc. +# Microsoft .NET properties +csharp_new_line_between_query_expression_clauses = false +csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion +csharp_prefer_braces = false:warning +csharp_space_after_keywords_in_control_flow_statements = false +csharp_style_var_elsewhere = false:suggestion +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_using_directive_placement = inside_namespace:silent +dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True +dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule.severity = warning +dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style +dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols +dotnet_naming_rule.unity_serialized_field_rule_1.import_to_resharper = True +dotnet_naming_rule.unity_serialized_field_rule_1.resharper_description = Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule_1.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule_1.severity = warning +dotnet_naming_rule.unity_serialized_field_rule_1.style = lower_camel_case_style +dotnet_naming_rule.unity_serialized_field_rule_1.symbols = unity_serialized_field_symbols_1 +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = * +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds = +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance +dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = * +dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds = +dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:warning +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:warning +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:warning dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion dotnet_style_predefined_type_for_member_access = true:suggestion - -# This controls implicit access modifiers +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion dotnet_style_require_accessibility_modifiers = never:suggestion -# Prefer non modified fields to be marked readonly -dotnet_style_readonly_field = true:warning +# ReSharper properties +resharper_align_first_arg_by_paren = true +resharper_align_linq_query = true +resharper_align_multiline_argument = true +resharper_align_multiline_binary_expressions_chain = true +resharper_align_multiline_binary_patterns = true +resharper_align_multiline_calls_chain = true +resharper_align_multiline_expression = true +resharper_align_multiline_extends_list = true +resharper_align_multiline_for_stmt = true +resharper_align_multiline_parameter = true +resharper_align_multiline_property_pattern = true +resharper_align_multiline_switch_expression = true +resharper_align_multiple_declaration = true +resharper_align_multline_type_parameter_constrains = true +resharper_align_multline_type_parameter_list = true +resharper_align_tuple_components = true +resharper_attribute_indent = align_by_first_attribute +resharper_attribute_style = on_single_line +resharper_autodetect_indent_settings = true +resharper_constructor_or_destructor_body = expression_body +resharper_cpp_brace_style = next_line +resharper_csharp_outdent_commas = true +resharper_default_value_when_type_not_evident = default_expression +resharper_empty_block_style = together_same_line +resharper_force_attribute_style = join +resharper_force_chop_compound_do_expression = true +resharper_force_chop_compound_if_expression = true +resharper_force_chop_compound_while_expression = true +resharper_for_built_in_types = use_var_when_evident +resharper_fsharp_type_declaration_braces = next_line +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_indent_preprocessor_if = outdent +resharper_indent_preprocessor_other = usual_indent +resharper_indent_switch_labels = true +resharper_int_align_assignments = true +resharper_int_align_binary_expressions = true +resharper_int_align_comments = true +resharper_int_align_fields = true +resharper_int_align_methods = true +resharper_int_align_nested_ternary = true +resharper_int_align_properties = true +resharper_int_align_property_patterns = true +resharper_int_align_switch_expressions = true +resharper_int_align_switch_sections = true +resharper_int_align_variables = true +resharper_keep_existing_arrangement = false +resharper_keep_user_linebreaks = false +resharper_linebreak_before_all_elements = true +resharper_local_function_body = expression_body +resharper_max_blank_lines_between_tags = 0 +resharper_max_enum_members_on_line = 1 +resharper_method_or_operator_body = expression_body +resharper_nested_ternary_style = expanded +resharper_new_line_before_while = false +resharper_normalize_tag_names = true +resharper_outdent_binary_ops = true +resharper_outdent_binary_pattern_ops = true +resharper_outdent_dots = true +resharper_outdent_statement_labels = true +resharper_place_attribute_on_same_line = false +resharper_place_expr_accessor_on_single_line = true +resharper_place_expr_method_on_single_line = true +resharper_place_expr_property_on_single_line = true +resharper_place_linq_into_on_new_line = false +resharper_place_simple_anonymousmethod_on_single_line = false +resharper_place_simple_case_statement_on_same_line = true +resharper_place_simple_embedded_statement_on_same_line = false +resharper_place_simple_initializer_on_single_line = false +resharper_place_simple_switch_expression_on_single_line = true +resharper_prefer_explicit_discard_declaration = true +resharper_qualified_using_at_nested_scope = true +resharper_show_autodetect_configure_formatting_tip = false +resharper_sort_attributes = true +resharper_sort_class_selectors = true +resharper_space_after_keywords_in_control_flow_statements = false +resharper_space_after_last_pi_attribute = true +resharper_space_after_unary_operator = false +resharper_space_around_binary_operator = true +resharper_space_before_self_closing = true +resharper_space_within_empty_braces = false +resharper_stick_comment = false +resharper_use_indent_from_vs = false +resharper_wrap_after_dot_in_method_calls = true +resharper_wrap_before_first_type_parameter_constraint = true +resharper_wrap_before_type_parameter_langle = true +resharper_wrap_enum_declaration = wrap_if_long +resharper_wrap_for_stmt_header_style = wrap_if_long +resharper_wrap_lines = true +resharper_wrap_multiple_declaration_style = wrap_if_long +resharper_wrap_multiple_type_parameter_constraints_style = wrap_if_long +resharper_wrap_object_and_collection_initializer_style = chop_always +resharper_wrap_ternary_expr_style = wrap_if_long +resharper_wrap_verbatim_interpolated_strings = wrap_if_long -# Parenthesis settings -dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_operators = always_for_clarity:warning +# ReSharper inspection severities +resharper_annotate_can_be_null_parameter_highlighting = warning +resharper_annotate_can_be_null_type_member_highlighting = warning +resharper_annotate_not_null_parameter_highlighting = warning +resharper_annotate_not_null_type_member_highlighting = warning +resharper_arrange_attributes_highlighting = hint +resharper_arrange_constructor_or_destructor_body_highlighting = warning +resharper_arrange_default_value_when_type_evident_highlighting = warning +resharper_arrange_default_value_when_type_not_evident_highlighting = warning +resharper_arrange_local_function_body_highlighting = warning +resharper_arrange_method_or_operator_body_highlighting = warning +resharper_arrange_object_creation_when_type_evident_highlighting = warning +resharper_arrange_object_creation_when_type_not_evident_highlighting = warning +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_this_qualifier_highlighting = hint +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_async_void_method_highlighting = warning +resharper_built_in_type_reference_style_for_member_access_highlighting = hint +resharper_built_in_type_reference_style_highlighting = hint +resharper_compare_non_constrained_generic_with_null_highlighting = warning +resharper_heap_view_boxing_allocation_highlighting = none +resharper_heap_view_delegate_allocation_highlighting = none +resharper_heap_view_object_allocation_evident_highlighting = none +resharper_heap_view_object_allocation_highlighting = none +resharper_inheritdoc_consider_usage_highlighting = warning +resharper_local_function_can_be_made_static_highlighting = warning +resharper_loop_can_be_partly_converted_to_query_highlighting = warning +resharper_member_can_be_internal_highlighting = warning +resharper_nullable_warning_suppression_is_used_highlighting = warning +resharper_redundant_base_qualifier_highlighting = warning +resharper_remove_constructor_invocation_highlighting = warning +resharper_separate_control_transfer_statement_highlighting = warning +resharper_string_ends_with_is_culture_specific_highlighting = warning +resharper_string_starts_with_is_culture_specific_highlighting = warning +resharper_struct_member_can_be_made_read_only_highlighting = warning +resharper_suggest_var_or_type_built_in_types_highlighting = hint +resharper_suggest_var_or_type_elsewhere_highlighting = hint +resharper_suggest_var_or_type_simple_types_highlighting = hint +resharper_tabs_are_disallowed_highlighting = warning +resharper_unnecessary_whitespace_highlighting = warning +resharper_use_nameof_expression_for_part_of_the_string_highlighting = warning +resharper_use_positional_deconstruction_pattern_highlighting = warning +resharper_web_config_module_not_resolved_highlighting = warning +resharper_web_config_type_not_resolved_highlighting = warning +resharper_web_config_wrong_module_highlighting = warning -dotnet_style_object_initializer = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_explicit_tuple_names = true:error -dotnet_style_prefer_inferred_tuple_names = true:warning -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning -dotnet_style_prefer_conditional_expression_over_return = true:warning -dotnet_style_coalesce_expression = true:warning -dotnet_style_null_propagation = true:error +[{*.har,*.inputactions,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config}] +indent_style = space +indent_size = 2 -dotnet_sort_system_directives_first = true +[{*.yaml,*.yml,.analysis_options}] +indent_style = space +indent_size = 2 -# Constants in C style, all-caps -dotnet_naming_rule.constant_fields_caps.symbols = constant_fields -dotnet_naming_rule.constant_fields_caps.severity = warning -dotnet_naming_rule.constant_fields_caps.style = caps_style -dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.required_modifiers = const -dotnet_naming_style.caps_style.capitalization = all_upper +[*.csv] +indent_style = tab +tab_width = 1 -# interfaces should be prefixed with I -dotnet_naming_rule.pascal_case_for_interface.severity = error -dotnet_naming_rule.pascal_case_for_interface.symbols = interfaces_fields -dotnet_naming_rule.pascal_case_for_interface.style = pascal_case_interface_style -dotnet_naming_symbols.interfaces_fields.applicable_kinds = interface -dotnet_naming_style.pascal_case_interface_style.required_prefix = I -dotnet_naming_style.pascal_case_interface_style.capitalization = pascal_case +[{*.bash,*.sh,*.tool,*.zsh}] +indent_style = space +indent_size = 2 -## internal and private fields should be _camelCase -dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning -dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style -dotnet_naming_symbols.private_internal_fields.applicable_kinds = field -dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal -dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case - -# 2018-12-07 NP: This is not yet working in VS2017 -# local variables should be camelCase -#dotnet_naming_rule.camel_case_for_locals.severity = suggestion -#dotnet_naming_rule.camel_case_for_locals.symbols = local_fields -#dotnet_naming_rule.camel_case_for_locals.style = camel_case_style -#dotnet_naming_symbols.local_fields.applicable_kinds = local -#dotnet_naming_style.camel_case_style.capitalization = camel_case - -[*.cs] -# var var var -csharp_style_var_for_built_in_types = false:warning -csharp_style_var_when_type_is_apparent = true:suggestion -csharp_style_var_elsewhere = false:warning - -csharp_style_expression_bodied_methods = when_on_single_line:suggestion -csharp_style_expression_bodied_constructors = when_on_single_line:suggestion -csharp_style_expression_bodied_operators = when_on_single_line:suggestion -csharp_style_expression_bodied_properties = when_on_single_line:suggestion -csharp_style_expression_bodied_indexers = when_on_single_line:suggestion -csharp_style_expression_bodied_accessors = when_on_single_line:suggestion - -csharp_style_pattern_matching_over_is_with_cast_check = true:warning -csharp_style_pattern_matching_over_as_with_null_check = when_on_single_line:warning - -csharp_style_inlined_variable_declaration = true:warning - -csharp_prefer_simple_default_expression = true:warning -csharp_style_deconstructed_variable_declaration = false:warning - -csharp_style_throw_expression = true:warning -csharp_style_conditional_delegate_call = true:warning - -csharp_prefer_braces = false - -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true -csharp_new_line_before_catch = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_between_query_expression_clauses = true - -csharp_indent_case_contents = true -csharp_indent_switch_labels = true -csharp_indent_labels = flush_left - -csharp_space_after_cast = false -csharp_space_after_keywords_in_control_flow_statements = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_parentheses = none -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_around_binary_operators = before_and_after -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false - -csharp_preserve_single_line_statements = false -csharp_preserve_single_line_blocks = true - -csharp_blank_lines_around_region = 0 -csharp_blank_lines_inside_region = 0 -csharp_blank_lines_before_single_line_comment = 1 -csharp_keep_blank_lines_in_declarations = 1 -csharp_remove_blank_lines_near_braces_in_declarations = true -csharp_blank_lines_after_start_comment = false -csharp_blank_lines_between_using_groups = 0 -csharp_blank_lines_after_using_list = 1 -csharp_blank_lines_around_namespace = 1 -csharp_blank_lines_inside_namespace = 0 -csharp_blank_lines_around_type = 1 -csharp_blank_lines_inside_type = 0 -csharp_blank_lines_around_field = 0 -csharp_blank_lines_around_single_line_field = 0 -csharp_blank_lines_around_property = 1 -csharp_blank_lines_around_single_line_property = 0 -csharp_blank_lines_around_auto_property = 0 -csharp_blank_lines_around_single_line_auto_property = 0 -csharp_blank_lines_around_invocable = 1 -csharp_blank_lines_around_single_line_invocable = 1 -csharp_keep_blank_lines_in_code = 1 -csharp_remove_blank_lines_near_braces_in_code = true -csharp_blank_lines_around_local_method = 1 -csharp_blank_lines_around_single_line_local_method = 1 -csharp_blank_lines_before_control_transfer_statements = 1 -csharp_blank_lines_after_control_transfer_statements = 1 -csharp_blank_lines_before_block_statements = 1 -csharp_blank_lines_after_block_statements = 1 -csharp_blank_lines_before_multiline_statements = 1 -csharp_blank_lines_after_multiline_statements = 1 - -csharp_type_declaration_braces = next_line -csharp_brace_style = next_line -csharp_indent_inside_namespace = true -csharp_invocable_declaration_braces = next_line -csharp_anonymous_method_declaration_braces = next_line -csharp_accessor_owner_declaration_braces = next_line -csharp_accessor_declaration_braces = next_line -csharp_case_block_braces = next_line -csharp_initializer_braces = next_line -csharp_other_braces = next_line -csharp_allow_comment_after_lbrace = false -csharp_empty_block_style = together_same_line - -csharp_for_built_in_types = use_explicit_type -csharp_for_simple_types = use_var_when_evident -csharp_for_other_types = use_explicit_type -csharp_prefer_separate_deconstructed_variables_declaration = true -csharp_prefer_explicit_discard_declaration = false - -csharp_instance_members_qualify_members = none -csharp_builtin_type_reference_style = use_keyword -csharp_prefer_qualified_reference = false -csharp_add_imports_to_deepest_scope = false -csharp_allow_alias = true -csharp_default_private_modifier = implicit -csharp_default_internal_modifier = explicit -csharp_arguments_literal = positional -csharp_arguments_string_literal = positional -csharp_arguments_named = positional -csharp_arguments_anonymous_function = positional -csharp_arguments_other = positional -csharp_braces_for_ifelse = not_required -csharp_braces_for_for = not_required -csharp_braces_for_foreach = not_required -csharp_braces_for_while = not_required -csharp_braces_for_dowhile = not_required -csharp_braces_for_using = not_required -csharp_braces_for_lock = not_required -csharp_braces_for_fixed = not_required -csharp_method_or_operator_body = expression_body -csharp_local_function_body = expression_body -csharp_constructor_or_destructor_body = expression_body -csharp_accessor_owner_body = expression_body -csharp_force_attribute_style = join -csharp_indent_nested_usings_stmt = true - -csharp_builtin_type_reference_for_member_access_style = use_keyword -csharp_indent_nested_fixed_stmt = true -csharp_indent_nested_lock_stmt = true -csharp_indent_nested_for_stmt = true -csharp_indent_nested_foreach_stmt = true -csharp_indent_nested_while_stmt = true -csharp_use_continuous_indent_inside_parens = true -csharp_indent_method_decl_pars = inside -csharp_indent_invocation_pars = inside -csharp_indent_statement_pars = inside -csharp_indent_typeparam_angles = inside -csharp_indent_typearg_angles = inside -csharp_indent_pars = inside -csharp_indent_preprocessor_if = outdent -csharp_indent_preprocessor_region = usual_indent -csharp_indent_preprocessor_other = usual_indent -csharp_indent_switch_labels = true -csharp_indent_type_constraints = true -csharp_stick_comment = false -csharp_alignment_tab_fill_style = use_spaces -csharp_align_multiline_parameter = true -csharp_align_multiline_extends_list = true -csharp_align_linq_query = true -csharp_align_multiline_binary_expressions_chain = true -csharp_outdent_binary_ops = true -csharp_align_multiline_calls_chain = true -csharp_outdent_dots = true -csharp_align_multiline_array_and_object_initializer = false -csharp_indent_anonymous_method_block = false -csharp_align_first_arg_by_paren = true -csharp_align_multiline_argument = true -csharp_align_tuple_components = true -csharp_align_multiline_expression = true -csharp_align_multiline_for_stmt = true -csharp_align_multiple_declaration = true -csharp_align_multline_type_parameter_list = true -csharp_align_multline_type_parameter_constrains = true -csharp_int_align_fields = true -csharp_int_align_properties = true -csharp_int_align_methods = true -csharp_int_align_parameters = false -csharp_int_align_variables = true -csharp_int_align_assignments = true -csharp_int_align_nested_ternary = true -csharp_int_align_invocations = false -csharp_int_align_binary_expressions = true -csharp_int_align_comments = true -csharp_int_align_switch_sections = true -csharp_int_align = true -csharp_keep_user_linebreaks = false -csharp_keep_existing_arrangement = false -csharp_keep_existing_linebreaks = false -csharp_max_line_length = 120 -csharp_wrap_before_comma = false -csharp_special_else_if_treatment = true -csharp_insert_final_newline = false -csharp_place_type_attribute_on_same_line = never -csharp_place_method_attribute_on_same_line = never -csharp_place_accessorholder_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_place_accessor_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_place_field_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_wrap_parameters_style = wrap_if_long -csharp_keep_existing_declaration_parens_arrangement = false -csharp_wrap_before_declaration_lpar = false -csharp_wrap_after_declaration_lpar = false -csharp_wrap_before_declaration_rpar = false -csharp_place_constructor_initializer_on_same_line = true -csharp_keep_existing_expr_member_arrangement = false -csharp_place_expr_method_on_single_line = true -csharp_place_expr_property_on_single_line = true -csharp_place_expr_accessor_on_single_line = true -csharp_wrap_before_arrow_with_expressions = false -csharp_place_type_constraints_on_same_line = true -csharp_wrap_before_first_type_parameter_constraint = true -csharp_wrap_multiple_type_parameter_constraints_style = wrap_if_long -csharp_wrap_before_type_parameter_langle = true -csharp_wrap_before_extends_colon = false -csharp_wrap_extends_list_style = wrap_if_long -csharp_keep_existing_declaration_block_arrangement = false -csharp_place_abstract_accessorholder_on_single_line = true -csharp_place_simple_accessorholder_on_single_line = false -csharp_place_accessor_with_attrs_holder_on_single_line = false -csharp_place_simple_accessor_on_single_line = true -csharp_place_simple_method_on_single_line = false -csharp_keep_existing_enum_arrangement = false -csharp_place_simple_enum_on_single_line = false -csharp_wrap_enum_declaration = wrap_if_long -csharp_new_line_before_else = true -csharp_new_line_before_while = false -csharp_wrap_for_stmt_header_style = wrap_if_long -csharp_wrap_multiple_declaration_style = wrap_if_long -csharp_keep_existing_embedded_arrangement = false -csharp_place_simple_embedded_statement_on_same_line = false -csharp_place_simple_case_statement_on_same_line = true -csharp_keep_existing_embedded_block_arrangement = false -csharp_place_simple_embedded_block_on_same_line = false -csharp_place_simple_anonymousmethod_on_single_line = false -csharp_keep_existing_initializer_arrangement = false -csharp_place_simple_initializer_on_single_line = false -csharp_wrap_object_and_collection_initializer_style = chop_always -csharp_wrap_array_initializer_style = wrap_if_long -csharp_wrap_arguments_style = wrap_if_long -csharp_keep_existing_invocation_parens_arrangement = false -csharp_wrap_after_invocation_lpar = false -csharp_wrap_before_invocation_rpar = false -csharp_wrap_after_dot_in_method_calls = true -csharp_wrap_chained_method_calls = wrap_if_long -csharp_wrap_before_binary_opsign = false -csharp_wrap_chained_binary_expressions = wrap_if_long -csharp_force_chop_compound_if_expression = true -csharp_force_chop_compound_while_expression = true -csharp_force_chop_compound_do_expression = true -csharp_wrap_before_ternary_opsigns = true -csharp_wrap_ternary_expr_style = wrap_if_long -csharp_nested_ternary_style = expanded -csharp_wrap_linq_expressions = wrap_if_long -csharp_wrap_before_linq_expression = false -csharp_place_linq_into_on_new_line = false -csharp_wrap_verbatim_interpolated_strings = wrap_if_long -csharp_extra_spaces = remove_all -csharp_space_after_keywords_in_control_flow_statements = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_before_typeof_parentheses = false -csharp_space_before_checked_parentheses = false -csharp_space_before_sizeof_parentheses = false -csharp_space_before_nameof_parentheses = false -csharp_space_between_keyword_and_expression = true -csharp_space_between_keyword_and_type = true -csharp_space_around_assignment_op = true -csharp_space_around_logical_op = true -csharp_space_around_binary_operator = true -csharp_space_around_equality_op = true -csharp_space_around_relational_op = true -csharp_space_around_bitwise_op = true -csharp_space_around_additive_op = true -csharp_space_around_multiplicative_op = true -csharp_space_around_shift_op = true -csharp_space_around_nullcoalescing_op = true -csharp_space_around_arrow_op = false -csharp_space_after_logical_not_op = false -csharp_space_after_unary_operator = false -csharp_space_after_cast = false -csharp_space_around_dot = false -csharp_space_around_lambda_arrow = true -csharp_space_before_pointer_asterik_declaration = false -csharp_space_before_nullable_mark = false - -[*.cshtml] -linebreaks_around_razor_statements = true -blank_lines_around_razor_functions = true -blank_lines_around_razor_helpers = true -blank_lines_around_razor_sections = true - -# C++ -[*.{cc,cpp,cxx,h,hpp,hxx}] -cpp_indent_access_specifiers_from_class = true -cpp_indent_wrapped_function_names = false -cpp_align_multiline_type_argument = true - -# C, C++ and ObjectiveC -[*.{c,h,cc,cpp,cxx,m,hpp,hxx}] -indent_preprocessor_directives = normal -indent_type_constraints = true - -# Javascript and Typescript -[*.{js,js.map,ts}] -quote_style = doublequoted -termination_style = ensure_semicolon \ No newline at end of file +[*.{appxmanifest,asax,ascx,aspx,axaml,build,cg,cginc,compute,cs,cshtml,dtd,fs,fsi,fsscript,fsx,hlsl,hlsli,hlslinc,master,ml,mli,nuspec,paml,razor,resw,resx,shader,skin,usf,ush,vb,xaml,xamlx,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 diff --git a/Aaru.Decryption.csproj b/Aaru.Decryption.csproj index 8112c1faf..c5d680ea1 100644 --- a/Aaru.Decryption.csproj +++ b/Aaru.Decryption.csproj @@ -1,63 +1,63 @@ - - Debug - AnyCPU - 2.0 - Library - Aaru.Decryption - Aaru.Decryption - $(Version) - true - 6.0.0-alpha8 - Claunia.com - Copyright © 2011-2022 Natalia Portillo - Aaru Data Preservation Suite - Aaru.Decryption - $(Version) - net6 - 10 - Decryption algorithms used by the Aaru Data Preservation Suite. - https://github.com/aaru-dps/ - MIT - https://github.com/aaru-dps/Aaru.Decryption - true - en-US - true - true - snupkg - Rebecca Wallander <sakcheen@gmail.com> - enable - true - - - $(Version)+{chash:8} - true - true - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - + + Debug + AnyCPU + 2.0 + Library + Aaru.Decryption + Aaru.Decryption + $(Version) + true + 6.0.0-alpha8 + Claunia.com + Copyright © 2011-2022 Natalia Portillo + Aaru Data Preservation Suite + Aaru.Decryption + $(Version) + net6 + 10 + Decryption algorithms used by the Aaru Data Preservation Suite. + https://github.com/aaru-dps/ + MIT + https://github.com/aaru-dps/Aaru.Decryption + true + en-US + true + true + snupkg + Rebecca Wallander <sakcheen@gmail.com> + enable + true + + + $(Version)+{chash:8} + true + true + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + - - - - - + + + + + diff --git a/DVD/CSS.cs b/DVD/CSS.cs index 4382d672b..3da1f517a 100644 --- a/DVD/CSS.cs +++ b/DVD/CSS.cs @@ -34,9 +34,7 @@ // Copyright © 2020-2022 Rebecca Wallander // ****************************************************************************/ -using System; -using System.Linq; -using Aaru.Decoders.DVD; + // Based on information gathered from: // ISO/IEC13818-1 Second Edition @@ -49,6 +47,10 @@ using Aaru.Decoders.DVD; namespace Aaru.Decryption.DVD; +using System; +using System.Linq; +using Aaru.Decoders.DVD; + public class CSS { static readonly byte[,] _playerKeys = @@ -350,12 +352,12 @@ public class CSS static readonly byte[,] _permutationVariant = { { - 0x0a, 0x08, 0x0e, 0x0c, 0x0b, 0x09, 0x0f, 0x0d, 0x1a, 0x18, 0x1e, 0x1c, 0x1b, 0x19, 0x1f, 0x1d, 0x02, - 0x00, 0x06, 0x04, 0x03, 0x01, 0x07, 0x05, 0x12, 0x10, 0x16, 0x14, 0x13, 0x11, 0x17, 0x15 + 0x0a, 0x08, 0x0e, 0x0c, 0x0b, 0x09, 0x0f, 0x0d, 0x1a, 0x18, 0x1e, 0x1c, 0x1b, 0x19, 0x1f, 0x1d, 0x02, 0x00, + 0x06, 0x04, 0x03, 0x01, 0x07, 0x05, 0x12, 0x10, 0x16, 0x14, 0x13, 0x11, 0x17, 0x15 }, { - 0x12, 0x1a, 0x16, 0x1e, 0x02, 0x0a, 0x06, 0x0e, 0x10, 0x18, 0x14, 0x1c, 0x00, 0x08, 0x04, 0x0c, 0x13, - 0x1b, 0x17, 0x1f, 0x03, 0x0b, 0x07, 0x0f, 0x11, 0x19, 0x15, 0x1d, 0x01, 0x09, 0x05, 0x0d + 0x12, 0x1a, 0x16, 0x1e, 0x02, 0x0a, 0x06, 0x0e, 0x10, 0x18, 0x14, 0x1c, 0x00, 0x08, 0x04, 0x0c, 0x13, 0x1b, + 0x17, 0x1f, 0x03, 0x0b, 0x07, 0x0f, 0x11, 0x19, 0x15, 0x1d, 0x01, 0x09, 0x05, 0x0d } }; @@ -386,7 +388,7 @@ public class CSS byte[] key = response.Skip(4).Take(2048).ToArray(); for(uint i = 0; i < key.Length; i++) - key[i] ^= busKey[4 - (i % busKey.Length)]; + key[i] ^= busKey[4 - i % busKey.Length]; return new CSS_CPRM.DiscKey { @@ -413,7 +415,7 @@ public class CSS byte[] key = response.Skip(5).Take(5).ToArray(); for(uint i = 0; i < key.Length; i++) - key[i] ^= busKey[4 - (i % busKey.Length)]; + key[i] ^= busKey[4 - i % busKey.Length]; return new CSS_CPRM.TitleKey { @@ -435,38 +437,38 @@ public class CSS /// The encrypted key. public static void EncryptKey(DvdCssKeyType keyType, uint variant, byte[] challenge, out byte[] key) { - byte[] bits = new byte[30]; - byte[] scratch = new byte[10]; - byte index = sizeof(byte) * 30; - byte[] temp1 = new byte[5]; - byte[] temp2 = new byte[5]; - byte carry = 0; + var bits = new byte[30]; + var scratch = new byte[10]; + byte index = sizeof(byte) * 30; + var temp1 = new byte[5]; + var temp2 = new byte[5]; + byte carry = 0; key = new byte[5]; - for(int i = 9; i >= 0; --i) + for(var i = 9; i >= 0; --i) scratch[i] = challenge[_permutationChallenge[(uint)keyType, i]]; - byte cssVariant = (byte)(keyType == 0 ? variant : _permutationVariant[(uint)keyType - 1, variant]); + var cssVariant = (byte)(keyType == 0 ? variant : _permutationVariant[(uint)keyType - 1, variant]); - for(int i = 5; --i >= 0;) + for(var i = 5; --i >= 0;) temp1[i] = (byte)(scratch[5 + i] ^ _secret[i] ^ _encryptTable2[i]); - uint lfsr0 = (uint)((temp1[0] << 17) | (temp1[1] << 9) | ((temp1[2] & ~7) << 1) | 8 | (temp1[2] & 7)); - uint lfsr1 = (uint)((temp1[3] << 9) | 0x100 | temp1[4]); + var lfsr0 = (uint)((temp1[0] << 17) | (temp1[1] << 9) | ((temp1[2] & ~7) << 1) | 8 | (temp1[2] & 7)); + var lfsr1 = (uint)((temp1[3] << 9) | 0x100 | temp1[4]); do { byte val = 0; - for(int bit = 0; bit < 8; ++bit) + for(var bit = 0; bit < 8; ++bit) { - byte oLfsr0 = (byte)(((lfsr0 >> 24) ^ (lfsr0 >> 21) ^ (lfsr0 >> 20) ^ (lfsr0 >> 12)) & 1); + var oLfsr0 = (byte)(((lfsr0 >> 24) ^ (lfsr0 >> 21) ^ (lfsr0 >> 20) ^ (lfsr0 >> 12)) & 1); lfsr0 = (lfsr0 << 1) | oLfsr0; - byte oLfsr1 = (byte)(((lfsr1 >> 16) ^ (lfsr1 >> 2)) & 1); + var oLfsr1 = (byte)(((lfsr1 >> 16) ^ (lfsr1 >> 2)) & 1); lfsr1 = (lfsr1 << 1) | oLfsr1; - byte combined = (byte)(Convert.ToByte(oLfsr1 == 0) + carry + Convert.ToByte(oLfsr0 == 0)); + var combined = (byte)(Convert.ToByte(oLfsr1 == 0) + carry + Convert.ToByte(oLfsr0 == 0)); carry = (byte)((combined >> 1) & 1); val |= (byte)((combined & 1) << bit); } @@ -474,10 +476,10 @@ public class CSS bits[--index] = val; } while(index > 0); - byte cse = (byte)(_variants[cssVariant] ^ _encryptTable2[cssVariant]); - int term = 0; + var cse = (byte)(_variants[cssVariant] ^ _encryptTable2[cssVariant]); + var term = 0; - for(int i = 5; --i >= 0; term = scratch[i]) + for(var i = 5; --i >= 0; term = scratch[i]) { index = (byte)(bits[25 + i] ^ scratch[i]); index = (byte)(_encryptTable1[index] ^ ~_encryptTable2[index] ^ cse); @@ -488,7 +490,7 @@ public class CSS temp1[4] ^= temp1[0]; term = 0; - for(int i = 5; --i >= 0; term = temp1[i]) + for(var i = 5; --i >= 0; term = temp1[i]) { index = (byte)(bits[20 + i] ^ temp1[i]); index = (byte)(_encryptTable1[index] ^ ~_encryptTable2[index] ^ cse); @@ -499,7 +501,7 @@ public class CSS temp2[4] ^= temp2[0]; term = 0; - for(int i = 5; --i >= 0; term = temp2[i]) + for(var i = 5; --i >= 0; term = temp2[i]) { index = (byte)(bits[15 + i] ^ temp2[i]); index = (byte)(_encryptTable1[index] ^ ~_encryptTable2[index] ^ cse); @@ -511,7 +513,7 @@ public class CSS temp1[4] ^= temp1[0]; term = 0; - for(int i = 5; --i >= 0; term = temp1[i]) + for(var i = 5; --i >= 0; term = temp1[i]) { index = (byte)(bits[10 + i] ^ temp1[i]); index = (byte)(_encryptTable1[index] ^ ~_encryptTable2[index] ^ cse); @@ -523,7 +525,7 @@ public class CSS temp2[4] ^= temp2[0]; term = 0; - for(int i = 5; --i >= 0; term = temp2[i]) + for(var i = 5; --i >= 0; term = temp2[i]) { index = (byte)(bits[5 + i] ^ temp2[i]); index = (byte)(_encryptTable1[index] ^ ~_encryptTable2[index] ^ cse); @@ -534,7 +536,7 @@ public class CSS temp1[4] ^= temp1[0]; term = 0; - for(int i = 5; --i >= 0; term = temp1[i]) + for(var i = 5; --i >= 0; term = temp1[i]) { index = (byte)(bits[i] ^ temp1[i]); index = (byte)(_encryptTable1[index] ^ ~_encryptTable2[index] ^ cse); @@ -551,13 +553,12 @@ public class CSS public static void DecryptKey(byte invert, byte[] cryptoKey, byte[] encryptedKey, out byte[] decryptedKey) { decryptedKey = new byte[5]; - byte[] k = new byte[5]; + var k = new byte[5]; - uint lfsr1Lo = (uint)(cryptoKey[0] | 0x100); + var lfsr1Lo = (uint)(cryptoKey[0] | 0x100); uint lfsr1Hi = cryptoKey[1]; - uint 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]); @@ -566,11 +567,11 @@ public class CSS for(uint i = 0; i < 5; i++) { - byte oLfsr1 = (byte)(_cssTable2[lfsr1Hi] ^ _cssTable3[lfsr1Lo]); + var oLfsr1 = (byte)(_cssTable2[lfsr1Hi] ^ _cssTable3[lfsr1Lo]); lfsr1Hi = lfsr1Lo >> 1; lfsr1Lo = ((lfsr1Lo & 1) << 8) ^ oLfsr1; oLfsr1 = _cssTable4[oLfsr1]; - byte oLfsr0 = (byte)(((((((lfsr0 >> 8) ^ lfsr0) >> 1) ^ lfsr0) >> 3) ^ lfsr0) >> 7); + var oLfsr0 = (byte)(((((((lfsr0 >> 8) ^ lfsr0) >> 1) ^ lfsr0) >> 3) ^ lfsr0) >> 7); lfsr0 = (lfsr0 >> 8) | ((uint)oLfsr0 << 24); combined += (uint)((oLfsr0 ^ invert) + oLfsr1); k[i] = (byte)(combined & 0xff); @@ -590,8 +591,7 @@ public class CSS decryptedKey[0] = (byte)(k[0] ^ _cssTable1[decryptedKey[0]]); } - public static void - DecryptTitleKey(byte invert, byte[] cryptoKey, byte[] encryptedKey, out byte[] decryptedKey) => + public static void DecryptTitleKey(byte invert, byte[] cryptoKey, byte[] encryptedKey, out byte[] decryptedKey) => DecryptKey(invert, cryptoKey, encryptedKey, out decryptedKey); /// Takes an bytearray of encrypted keys, decrypts them and returns the correctly decrypted key. @@ -616,9 +616,7 @@ public class CSS DecryptKey(0, decryptedKey, verificationKey, out byte[] verify); if(decryptedKey.SequenceEqual(verify)) - { return; - } } } @@ -640,7 +638,7 @@ public class CSS keyData.All(k => k == 0)) return sectorData; - byte[] decryptedBuffer = new byte[sectorData.Length]; + var decryptedBuffer = new byte[sectorData.Length]; for(uint j = 0; j < blocks; j++) { @@ -663,11 +661,11 @@ public class CSS uint lfsr1Lo = (uint)(currentKey[0] ^ currentSector[0x54]) | 0x100; uint lfsr1Hi = (uint)currentKey[1] ^ currentSector[0x55]; - uint lfsr0 = (uint)((currentKey[2] | (currentKey[3] << 8) | (currentKey[4] << 16)) ^ - (sectorData[0x56] | (sectorData[0x57] << 8) | (sectorData[0x58] << 16))); + var lfsr0 = (uint)((currentKey[2] | (currentKey[3] << 8) | (currentKey[4] << 16)) ^ + (sectorData[0x56] | (sectorData[0x57] << 8) | (sectorData[0x58] << 16))); uint oLfsr1 = lfsr0 & 7; - lfsr0 = (lfsr0 * 2) + 8 - oLfsr1; + lfsr0 = lfsr0 * 2 + 8 - oLfsr1; uint combined = 0; @@ -703,13 +701,13 @@ public class CSS cmi.RegionInformation == 0x00) return true; - return ((rpc.RegionMask & 0x01) == (cmi.RegionInformation & 0x01) && (rpc.RegionMask & 0x01) != 0x01) || - ((rpc.RegionMask & 0x02) == (cmi.RegionInformation & 0x02) && (rpc.RegionMask & 0x02) != 0x02) || - ((rpc.RegionMask & 0x04) == (cmi.RegionInformation & 0x04) && (rpc.RegionMask & 0x04) != 0x04) || - ((rpc.RegionMask & 0x08) == (cmi.RegionInformation & 0x08) && (rpc.RegionMask & 0x08) != 0x08) || - ((rpc.RegionMask & 0x10) == (cmi.RegionInformation & 0x10) && (rpc.RegionMask & 0x10) != 0x10) || - ((rpc.RegionMask & 0x20) == (cmi.RegionInformation & 0x20) && (rpc.RegionMask & 0x20) != 0x20) || - ((rpc.RegionMask & 0x40) == (cmi.RegionInformation & 0x40) && (rpc.RegionMask & 0x40) != 0x40) || - ((rpc.RegionMask & 0x80) == (cmi.RegionInformation & 0x80) && (rpc.RegionMask & 0x80) != 0x80); + return (rpc.RegionMask & 0x01) == (cmi.RegionInformation & 0x01) && (rpc.RegionMask & 0x01) != 0x01 || + (rpc.RegionMask & 0x02) == (cmi.RegionInformation & 0x02) && (rpc.RegionMask & 0x02) != 0x02 || + (rpc.RegionMask & 0x04) == (cmi.RegionInformation & 0x04) && (rpc.RegionMask & 0x04) != 0x04 || + (rpc.RegionMask & 0x08) == (cmi.RegionInformation & 0x08) && (rpc.RegionMask & 0x08) != 0x08 || + (rpc.RegionMask & 0x10) == (cmi.RegionInformation & 0x10) && (rpc.RegionMask & 0x10) != 0x10 || + (rpc.RegionMask & 0x20) == (cmi.RegionInformation & 0x20) && (rpc.RegionMask & 0x20) != 0x20 || + (rpc.RegionMask & 0x40) == (cmi.RegionInformation & 0x40) && (rpc.RegionMask & 0x40) != 0x40 || + (rpc.RegionMask & 0x80) == (cmi.RegionInformation & 0x80) && (rpc.RegionMask & 0x80) != 0x80; } } \ No newline at end of file diff --git a/DVD/Dump.cs b/DVD/Dump.cs index f600968fa..9a6e09540 100644 --- a/DVD/Dump.cs +++ b/DVD/Dump.cs @@ -34,14 +34,14 @@ // Copyright © 2020-2022 Rebecca Wallander // ****************************************************************************/ +namespace Aaru.Decryption.DVD; + using System; using System.Linq; using Aaru.Console; using Aaru.Decoders.DVD; using Aaru.Devices; -namespace Aaru.Decryption.DVD; - public sealed class Dump { const byte KEY_SIZE = 5; @@ -69,7 +69,7 @@ public sealed class Dump out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[8]; cdb[0] = (byte)ScsiCommands.ReportKey; @@ -78,12 +78,10 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((byte)CssReportKeyFormat.Asf ^ ((Agid & 0x03) << 6)); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); - AaruConsole.DebugWriteLine("SCSI Device", - "REPORT ASF (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", duration, - Agid, sense, _dev.LastError); + AaruConsole.DebugWriteLine("SCSI Device", "REPORT ASF (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", + duration, Agid, sense, _dev.LastError); return sense; } @@ -99,7 +97,7 @@ public sealed class Dump out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[8]; cdb[0] = (byte)ScsiCommands.ReportKey; @@ -108,12 +106,10 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((byte)CssReportKeyFormat.RpcState ^ ((Agid & 0x03) << 6)); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); - AaruConsole.DebugWriteLine("SCSI Device", - "REPORT ASF (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", duration, - Agid, sense, _dev.LastError); + AaruConsole.DebugWriteLine("SCSI Device", "REPORT ASF (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", + duration, Agid, sense, _dev.LastError); return sense; } @@ -129,7 +125,7 @@ public sealed class Dump out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = Array.Empty(); cdb[0] = (byte)ScsiCommands.ReportKey; @@ -138,12 +134,11 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((byte)CssReportKeyFormat.InvalidateAgid ^ ((Agid & 0x03) << 6)); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); AaruConsole.DebugWriteLine("SCSI Device", - "INVALIDATE AGID (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", - duration, Agid, sense, _dev.LastError); + "INVALIDATE AGID (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", duration, + Agid, sense, _dev.LastError); return sense; } @@ -159,7 +154,7 @@ public sealed class Dump out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[8]; cdb[0] = (byte)ScsiCommands.ReportKey; @@ -168,8 +163,7 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((byte)CssReportKeyFormat.AgidForCssCppm ^ ((Agid & 0x03) << 6)); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); AaruConsole.DebugWriteLine("SCSI Device", "REPORT AGID CSS/CPPM (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", @@ -189,7 +183,7 @@ public sealed class Dump out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[12]; cdb[0] = (byte)ScsiCommands.ReportKey; @@ -198,12 +192,10 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((byte)CssReportKeyFormat.Key1 ^ ((Agid & 0x03) << 6)); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); - AaruConsole.DebugWriteLine("SCSI Device", - "REPORT KEY1 (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", duration, - Agid, sense, _dev.LastError); + AaruConsole.DebugWriteLine("SCSI Device", "REPORT KEY1 (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", + duration, Agid, sense, _dev.LastError); return sense; } @@ -219,7 +211,7 @@ public sealed class Dump out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[16]; cdb[0] = (byte)ScsiCommands.ReportKey; @@ -228,12 +220,11 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((byte)CssReportKeyFormat.ChallengeKey ^ ((Agid & 0x03) << 6)); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); AaruConsole.DebugWriteLine("SCSI Device", - "REPORT CHALLENGE (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", - duration, Agid, sense, _dev.LastError); + "REPORT CHALLENGE (AGID: {1}, Sense: {2}, Last Error: {3}) took {0} ms.", duration, + Agid, sense, _dev.LastError); return sense; } @@ -246,11 +237,11 @@ public sealed class Dump /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. - public bool SendChallenge(out byte[] buffer, out byte[] senseBuffer, DvdCssKeyClass keyClass, - byte[] challengeKey, uint timeout, out double duration) + public bool SendChallenge(out byte[] buffer, out byte[] senseBuffer, DvdCssKeyClass keyClass, byte[] challengeKey, + uint timeout, out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[16]; cdb[0] = (byte)ScsiCommands.SendKey; @@ -289,11 +280,11 @@ public sealed class Dump /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. - public bool SendKey2(out byte[] buffer, out byte[] senseBuffer, DvdCssKeyClass keyClass, byte[] key2, - uint timeout, out double duration) + public bool SendKey2(out byte[] buffer, out byte[] senseBuffer, DvdCssKeyClass keyClass, byte[] key2, uint timeout, + out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[12]; cdb[0] = (byte)ScsiCommands.SendKey; @@ -328,7 +319,7 @@ public sealed class Dump public bool ReadDiscKey(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration) { senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[2052]; cdb[0] = (byte)ScsiCommands.ReadDiscStructure; @@ -339,8 +330,7 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((Agid & 0x03) << 6); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); return sense; } @@ -359,30 +349,25 @@ public sealed class Dump buffer = Array.Empty(); senseBuffer = new byte[64]; - bool sense = false; - byte[] challenge = new byte[CHALLENGE_SIZE]; - byte[] key1 = new byte[KEY_SIZE]; - byte variant = 0; + var sense = false; + var challenge = new byte[CHALLENGE_SIZE]; + var key1 = new byte[KEY_SIZE]; + byte variant = 0; for(byte i = 0; i < 4; i++) { // Invalidate AGID to reset any previous drive communications Agid = i; - sense = InvalidateAgid(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, - out duration); + sense = InvalidateAgid(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); // Get AGID if(protectionType == CopyrightType.CSS) - { sense = ReportAgidCssCppm(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); - } if(protectionType == CopyrightType.CPRM) - { throw new NotImplementedException(); - } if(!sense) { @@ -393,9 +378,7 @@ public sealed class Dump } if(sense) - { return true; - } for(byte i = 0; i < CHALLENGE_SIZE; i++) challenge[i] = i; @@ -404,16 +387,12 @@ public sealed class Dump out duration); if(sense) - { return true; - } sense = ReportKey1(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); if(sense) - { return true; - } for(byte i = 0; i < KEY_SIZE; i++) key1[i] = buffer[8 - i]; @@ -437,13 +416,10 @@ public sealed class Dump } } - sense = ReportChallenge(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, - out duration); + sense = ReportChallenge(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); if(sense) - { return true; - } for(byte i = 0; i < CHALLENGE_SIZE; i++) challenge[i] = buffer[13 - i]; @@ -453,9 +429,7 @@ public sealed class Dump sense = SendKey2(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, key2, timeout, out duration); if(sense) - { return true; - } key1.CopyTo(challenge, 0); key2.CopyTo(challenge, key1.Length); @@ -483,7 +457,7 @@ public sealed class Dump BusKey = buffer; senseBuffer = new byte[64]; - byte[] cdb = new byte[12]; + var cdb = new byte[12]; buffer = new byte[12]; cdb[0] = (byte)ScsiCommands.ReportKey; @@ -496,8 +470,7 @@ public sealed class Dump cdb[9] = (byte)(buffer.Length & 0xFF); cdb[10] = (byte)((byte)CssReportKeyFormat.TitleKey ^ ((Agid & 0x03) << 6)); - _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, - out bool sense); + _dev.SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); AaruConsole.DebugWriteLine("SCSI Device", "GET TITLE KEY (AGID: {1}, LBA: {2}, Sense: {3}) took {0} ms.", duration, Agid, address, sense); diff --git a/Enums.cs b/Enums.cs index dcf25baa0..ae59bb14f 100644 --- a/Enums.cs +++ b/Enums.cs @@ -2,10 +2,13 @@ namespace Aaru.Decryption; public enum DvdCssKeyClass : byte { - DvdCssCppmOrCprm = 0, RewritableSecurityServicesA = 1 + DvdCssCppmOrCprm = 0, + RewritableSecurityServicesA = 1 } public enum DvdCssKeyType { - Key1 = 0, Key2 = 1, BusKey = 2 + Key1 = 0, + Key2 = 1, + BusKey = 2 } \ No newline at end of file