dotscope 0.6.0

A high-performance, cross-platform framework for analyzing and reverse engineering .NET PE executables
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
//! .NET resource file parsing infrastructure.
//!
//! This module provides comprehensive parsing capabilities for .NET resource files,
//! implementing the full .NET `ResourceManager` and `RuntimeResourceReader` format
//! specifications. It handles both V1 and V2 resource formats with support for
//! debug builds and all standard resource types.
//!
//! # Resource Format Overview
//!
//! .NET resources use a complex binary format optimized for efficient lookup and
//! type-safe deserialization. The format consists of multiple sections:
//!
//! ## Header Structure
//! 1. **Resource Manager Header**: Contains magic number, version, and type information
//! 2. **Runtime Resource Reader Header**: Contains resource count, type table, and section offsets
//! 3. **Name Section**: Contains resource names and their data offsets
//! 4. **Data Section**: Contains the actual resource data with type information
//!
//! ## Format Versions
//! - **Version 1**: Standard release format
//! - **Version 2**: Enhanced format with optional debug information
//!
//! # Key Components
//!
//! - [`parse_dotnet_resource()`] - High-level parsing function for complete resource extraction
//! - [`Resource`] - Low-level parser that exposes all format details
//! - [`crate::metadata::resources::ResourceEntry`] - Individual resource representation
//! - [`crate::metadata::resources::ResourceType`] - Typed resource data representation
//!
//! # Usage Patterns
//!
//! ## High-Level Resource Parsing
//!
//! ```ignore
//! use dotscope::metadata::resources::parse_dotnet_resource;
//!
//! // Parse complete resource file
//! let resource_data = /* ... resource file bytes ... */;
//! let resources = parse_dotnet_resource(resource_data)?;
//!
//! for (name, entry) in resources {
//!     println!("Resource: {} (Hash: 0x{:X})", name, entry.name_hash);
//!     match entry.data {
//!         ResourceType::String(ref s) => println!("  String: {}", s),
//!         ResourceType::ByteArray(ref bytes) => println!("  Binary: {} bytes", bytes.len()),
//!         _ => println!("  Other type"),
//!     }
//! }
//! ```
//!
//! ## Low-Level Resource Analysis
//!
//! ```ignore
//! use dotscope::metadata::resources::Resource;
//!
//! // Parse resource header and examine structure
//! let resource_data = /* ... resource file bytes ... */;
//! let mut resource = Resource::parse(resource_data)?;
//!
//! println!("Resource Manager Version: {}", resource.res_mgr_header_version);
//! println!("Resource Reader Version: {}", resource.rr_version);
//! println!("Resource Count: {}", resource.resource_count);
//! println!("Type Count: {}", resource.type_names.len());
//! println!("Debug Build: {}", resource.is_debug);
//!
//! // Parse individual resources
//! let resources = resource.read_resources(resource_data)?;
//! ```
//!
//! # Error Handling
//!
//! The parser implements comprehensive validation:
//! - **Magic Number Verification**: Ensures correct file format
//! - **Bounds Checking**: All data access is bounds-checked
//! - **Format Validation**: Header consistency and section alignment checks
//! - **Type Safety**: Resource type validation during deserialization

use std::collections::BTreeMap;

use crate::{
    file::parser::Parser,
    metadata::resources::{
        ResourceEntry, ResourceEntryRef, ResourceType, ResourceTypeRef, RESOURCE_MAGIC,
    },
    Result,
};

/// Maximum number of resource types allowed in a resource file.
/// Real-world .NET resource files typically have < 50 types.
const MAX_RESOURCE_TYPES: u32 = 4096;

/// Maximum number of resources allowed in a resource file.
/// Real-world .NET resource files typically have < 10,000 resources.
const MAX_RESOURCES: u32 = 1_000_000;

/// Parse a complete .NET resource buffer into a collection of named resources.
///
/// This is the primary entry point for resource parsing, providing a high-level
/// interface that handles all the complexity of the .NET resource format. It
/// performs complete parsing and returns a map of resource names to their
/// corresponding data and metadata.
///
/// # Format Support
///
/// - **V1 Resources**: Standard release format
/// - **V2 Resources**: Enhanced format with optional debug information
/// - **All Resource Types**: Strings, primitives, byte arrays, and complex objects
///
/// # Arguments
///
/// * `data` - Complete resource file data starting with the resource header
///
/// # Returns
///
/// A `BTreeMap<String, ResourceEntry>` containing all parsed resources, sorted
/// by name for consistent iteration order.
///
/// # Errors
///
/// Returns an error if:
/// - The data is too small to contain a valid resource header
/// - The magic number doesn't match the expected value (0xBEEFCACE)
/// - Header versions are unsupported or malformed
/// - Resource data sections are truncated or corrupted
/// - Individual resource entries cannot be parsed
///
/// # Examples
///
/// ```ignore
/// use dotscope::metadata::resources::parse_dotnet_resource;
///
/// let resource_data = std::fs::read("MyApp.resources")?;
/// let resources = parse_dotnet_resource(&resource_data)?;
///
/// println!("Found {} resources:", resources.len());
/// for (name, entry) in &resources {
///     println!("  {}: {:?}", name, entry.data);
/// }
/// ```
pub fn parse_dotnet_resource(data: &[u8]) -> Result<BTreeMap<String, ResourceEntry>> {
    let mut resource = Resource::parse(data)?;
    resource.read_resources(data)
}

/// Parse a complete .NET resource buffer with zero-copy semantics.
///
/// This is the zero-copy variant of [`parse_dotnet_resource`]. Instead of allocating
/// owned copies of resource data, it returns borrowed slices directly into the source
/// data buffer. This is the recommended entry point when working with large embedded
/// resources (like ZIP archives) that could be hundreds of megabytes or gigabytes.
///
/// # Format Support
///
/// - **V1 Resources**: Standard release format
/// - **V2 Resources**: Enhanced format with optional debug information
/// - **All Resource Types**: Strings, primitives, byte arrays, and complex objects
/// - **Zero-Copy Data**: String and byte array resources borrow from source buffer
///
/// # Arguments
///
/// * `data` - Complete resource file data starting with the resource header
///
/// # Lifetime
///
/// The returned resources borrow from the `data` parameter. All borrowed resource data
/// (strings and byte arrays) will remain valid as long as `data` is valid.
///
/// # Returns
///
/// A `BTreeMap<String, ResourceEntryRef>` containing all parsed resources with borrowed
/// data, sorted by name for consistent iteration order.
///
/// # Errors
///
/// Returns an error if:
/// - The data is too small to contain a valid resource header
/// - The magic number doesn't match the expected value (0xBEEFCACE)
/// - Header versions are unsupported or malformed
/// - Resource data sections are truncated or corrupted
/// - Individual resource entries cannot be parsed
///
/// # Examples
///
/// ## Basic Usage
///
/// ```ignore
/// use dotscope::metadata::resources::parse_dotnet_resource_ref;
/// use dotscope::metadata::resources::ResourceTypeRef;
///
/// let resource_data = std::fs::read("MyApp.resources")?;
/// let resources = parse_dotnet_resource_ref(&resource_data)?;
///
/// println!("Found {} resources:", resources.len());
/// for (name, entry) in &resources {
///     match &entry.data {
///         ResourceTypeRef::ByteArray(bytes) => {
///             println!("  {}: {} bytes (no copy!)", name, bytes.len());
///         }
///         ResourceTypeRef::String(s) => {
///             println!("  {}: \"{}\"", name, s);
///         }
///         _ => {
///             println!("  {}: {:?}", name, entry.data);
///         }
///     }
/// }
/// # Ok::<(), dotscope::Error>(())
/// ```
///
/// ## Extracting Embedded ZIP Archives
///
/// ```ignore
/// use dotscope::metadata::resources::parse_dotnet_resource_ref;
/// use dotscope::metadata::resources::ResourceTypeRef;
///
/// let resource_data = std::fs::read("MyApp.resources")?;
/// let resources = parse_dotnet_resource_ref(&resource_data)?;
///
/// // Find and extract ZIP files without copying data
/// for (name, entry) in &resources {
///     if let ResourceTypeRef::ByteArray(bytes) = &entry.data {
///         if bytes.starts_with(b"PK\x03\x04") {
///             println!("Found ZIP: {} ({} bytes)", name, bytes.len());
///
///             // Process ZIP directly from borrowed slice - no allocation!
///             let mut archive = zip::ZipArchive::new(std::io::Cursor::new(bytes))?;
///             for i in 0..archive.len() {
///                 let file = archive.by_index(i)?;
///                 println!("  - {}", file.name());
///             }
///         }
///     }
/// }
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
/// For small resources or when data needs to outlive the source buffer, consider
/// using [`parse_dotnet_resource`] instead.
pub fn parse_dotnet_resource_ref(data: &[u8]) -> Result<BTreeMap<String, ResourceEntryRef<'_>>> {
    let mut resource = Resource::parse(data)?;
    resource.read_resources_ref(data)
}

/// Low-level parser for .NET `ResourceManager` format with complete format exposure.
///
/// This struct provides direct access to all aspects of the .NET resource format,
/// enabling detailed analysis and custom parsing scenarios. It implements the full
/// specification from `CoreCLR` for both V1 and V2 resource formats.
///
/// # Format Structure
///
/// The `Resource` parser exposes all sections of the .NET resource format:
///
/// ## Resource Manager Header
/// - Magic number validation (0xBEEFCACE)
/// - Version information and header sizing
/// - Type information for resource reader and resource set classes
///
/// ## Runtime Resource Reader Header  
/// - Resource reader version (1 or 2)
/// - Optional debug information for V2 debug builds
/// - Resource and type counts
/// - Type name table for all resource types used
///
/// ## Hash and Position Tables
/// - Pre-computed hash values for fast resource lookup
/// - Virtual offsets into the name section for each resource
/// - Data section absolute offset
///
/// ## Use Cases
///
/// - **Format Analysis**: Examining resource file structure and metadata
/// - **Custom Parsing**: Implementing specialized resource extraction logic
/// - **Debugging**: Investigating resource file corruption or format issues
/// - **Research**: Understanding .NET resource format implementation details
///
/// # Examples
///
/// ## Format Analysis
///
/// ```ignore
/// use dotscope::metadata::resources::Resource;
///
/// let resource_data = std::fs::read("MyApp.resources")?;
/// let resource = Resource::parse(&resource_data)?;
///
/// println!("=== Resource Format Analysis ===");
/// println!("Manager Version: {}", resource.res_mgr_header_version);
/// println!("Reader Version: {}", resource.rr_version);
/// println!("Header Size: {} bytes", resource.header_size);
/// println!("Debug Build: {}", resource.is_debug);
/// println!("Resources: {}", resource.resource_count);
/// println!("Types: {}", resource.type_names.len());
/// println!("Padding: {} bytes", resource.padding);
///
/// println!("\nType Table:");
/// for (i, type_name) in resource.type_names.iter().enumerate() {
///     println!("  [{}] {}", i, type_name);
/// }
/// ```
///
/// ## Custom Resource Processing
///
/// ```ignore
/// use dotscope::metadata::resources::Resource;
///
/// let resource_data = std::fs::read("MyApp.resources")?;
/// let mut resource = Resource::parse(&resource_data)?;
///
/// // Access hash table for fast lookups
/// for (i, hash) in resource.name_hashes.iter().enumerate() {
///     println!("Resource {}: Hash=0x{:08X}, Offset={}",
///              i, hash, resource.name_positions[i]);
/// }
///
/// // Parse all resources with full control
/// let resources = resource.read_resources(&resource_data)?;
/// ```
///
/// # Format Details from `CoreCLR`
///
/// From `CoreCLR` documentation, the system default file format (V1) is:
///
/// ```text
/// What                                               Type of Data
/// ====================================================   ===========
///
///                        Resource Manager header
/// Magic Number (0xBEEFCACE)                               Int32
/// Resource Manager header version                         Int32
/// Num bytes to skip from here to get past this header     Int32
/// Class name of IResourceReader to parse this file        String
/// Class name of ResourceSet to parse this file            String
///
///                       RuntimeResourceReader header
/// ResourceReader version number                           Int32
/// [Only in debug V2 builds - "***DEBUG***"]               String
/// Number of resources in the file                         Int32
/// Number of types in the type table                       Int32
/// Name of each type                                       Set of Strings
/// Padding bytes for 8-byte alignment (use PAD)            Bytes (0-7)
/// Hash values for each resource name                      Int32 array, sorted
/// Virtual offset of each resource name                    Int32 array, coupled with hash values
/// Absolute location of Data section                       Int32
///
///                     RuntimeResourceReader Name Section
/// Name & virtual offset of each resource                  Set of (UTF-16 String, Int32) pairs
///
///                     RuntimeResourceReader Data Section
/// Type and Value of each resource                         Set of (Int32, blob of bytes) pairs
/// ```
///
/// # Thread Safety
///
/// `Resource` is not thread-safe due to mutable parsing state. Create separate
/// instances for concurrent parsing operations.
///
/// # Memory Efficiency
///
/// The parser uses streaming techniques to minimize memory allocation:
/// - String data is parsed directly from source buffer when possible
/// - Binary data maintains references to original data
/// - Type information is stored efficiently in vectors
#[derive(Default)]
pub struct Resource {
    /// Resource Manager header version
    pub res_mgr_header_version: u32,
    /// Size of the header
    pub header_size: u32,
    /// Class name of `IResourceReader` to parse this file
    pub reader_type: String,
    /// Class name of `ResourceSet` to parse this file
    pub resource_set_type: String,
    /// Offset of the `ResourceReader` Header
    pub rr_header_offset: usize,
    /// `ResourceReader` version number
    pub rr_version: u32,
    /// Number of resources in the file
    pub resource_count: u32,
    /// The type table - names of the types used in resources
    pub type_names: Vec<String>,
    /// The amount of padding used
    pub padding: usize,
    /// The name hash table - for faster lookups of resources by name
    pub name_hashes: Vec<u32>,
    /// Virtual offset of each resource name (in `RuntimeResourceReader` Name Section)
    pub name_positions: Vec<u32>,
    /// Absolute location of Data section
    pub data_section_offset: usize,
    /// Beginning of the name section
    pub name_section_offset: usize,
    /// Is a debug build
    pub is_debug: bool,
    /// Is this an embedded resource (with size prefix) vs standalone .resources file
    pub is_embedded_resource: bool,
}

impl Resource {
    /// Parse resource header and structure from raw data with comprehensive validation.
    ///
    /// This method performs complete parsing of the resource file header structure,
    /// including all sections up to but not including the actual resource data.
    /// It validates the format, extracts metadata, and prepares for resource enumeration.
    ///
    /// # Parsing Process
    ///
    /// 1. **Size Validation**: Verifies the data buffer is large enough
    /// 2. **Magic Number Check**: Confirms the file is a valid .NET resource
    /// 3. **Header Parsing**: Extracts version and type information
    /// 4. **Structure Analysis**: Parses type tables, hash arrays, and section offsets
    /// 5. **Offset Calculation**: Determines positions for name and data sections
    ///
    /// # Arguments
    ///
    /// * `data` - Complete resource file data buffer starting with the size header
    ///
    /// # Returns
    ///
    /// A fully initialized `Resource` parser ready for resource enumeration via
    /// [`read_resources()`](Resource::read_resources).
    ///
    /// # Errors
    ///
    /// Returns an error if:
    /// - Data buffer is smaller than 12 bytes (minimum header size)
    /// - Size field indicates invalid or truncated data
    /// - Magic number is not 0xBEEFCACE
    /// - Header structure is malformed or truncated
    /// - Type table or hash array data is corrupted
    ///
    /// # Examples
    ///
    /// ```ignore
    /// use dotscope::metadata::resources::Resource;
    ///
    /// let resource_data = std::fs::read("MyApp.resources")?;
    /// let resource = Resource::parse(&resource_data)?;
    ///
    /// println!("Parsed resource file:");
    /// println!("  Manager Version: {}", resource.res_mgr_header_version);
    /// println!("  Reader Version: {}", resource.rr_version);
    /// println!("  Resource Count: {}", resource.resource_count);
    /// println!("  Type Count: {}", resource.type_names.len());
    /// println!("  Debug Build: {}", resource.is_debug);
    /// ```
    ///
    /// # Format Validation
    ///
    /// The parser performs extensive validation:
    /// - **Size Consistency**: Header size fields must be consistent with data length
    /// - **Magic Number**: Must be exactly 0xBEEFCACE for valid .NET resources
    /// - **Version Support**: Supports V1 and V2 resource reader formats
    /// - **Alignment Checks**: Validates padding and alignment requirements
    /// - **Array Bounds**: Ensures hash and position arrays match resource count
    pub fn parse(data: &[u8]) -> Result<Self> {
        if data.len() < 12 {
            return Err(malformed_error!("Resource data too small"));
        }

        let mut parser = Parser::new(data);

        // Step 1: Detect format and validate magic number
        let is_embedded_resource = Self::parse_and_validate_magic(&mut parser, data)?;

        // Step 2: Parse resource manager header
        let (res_mgr_header_version, header_size, reader_type, resource_set_type) =
            Self::parse_resource_manager_header(&mut parser)?;

        // Step 3: Initialize result struct with header data
        let mut res = Resource {
            res_mgr_header_version,
            header_size,
            reader_type,
            resource_set_type,
            is_embedded_resource,
            rr_header_offset: parser.pos(),
            ..Default::default()
        };

        // Step 4: Parse RuntimeResourceReader header
        Self::parse_runtime_reader_header(&mut parser, data, &mut res)?;

        // Step 5: Parse type table
        Self::parse_type_table(&mut parser, &mut res)?;

        // Step 6: Handle padding/alignment
        res.padding = Self::skip_padding(&mut parser, data)?;

        // Step 7: Parse hash and position tables
        Self::parse_lookup_tables(&mut parser, &mut res)?;

        // Step 8: Read data section offset and record name section start
        res.data_section_offset = parser.read_le::<u32>()? as usize;
        res.name_section_offset = parser.pos();

        Ok(res)
    }

    /// Detect resource format (embedded vs standalone) and validate magic number.
    ///
    /// .NET resources can appear in two formats:
    /// - **Embedded**: `[size: u32][magic: u32][header...]` - Used when resources are embedded in assemblies
    /// - **Standalone**: `[magic: u32][header...]` - Used for standalone `.resources` files
    ///
    /// This method reads the first 8 bytes to detect which format is being used and
    /// validates that the magic number (0xBEEFCACE) is present.
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned at the start of the resource data
    /// * `data` - Complete resource data buffer (used for size validation)
    ///
    /// # Returns
    ///
    /// * `Ok(true)` - Embedded resource format detected (parser positioned after magic)
    /// * `Ok(false)` - Standalone format detected (parser positioned after magic)
    ///
    /// # Errors
    ///
    /// Returns an error if:
    /// - Neither format's magic number is found at the expected position
    /// - Embedded format has invalid size (too large or too small)
    fn parse_and_validate_magic(parser: &mut Parser, data: &[u8]) -> Result<bool> {
        let first_u32 = parser.read_le::<u32>()?;
        let second_u32 = parser.read_le::<u32>()?;

        if second_u32 == RESOURCE_MAGIC {
            // Embedded resource format: [size][magic][header...]
            let size = first_u32 as usize;
            if size > (data.len() - 4) || size < 8 {
                return Err(malformed_error!("Invalid embedded resource size: {}", size));
            }
            Ok(true)
        } else if first_u32 == RESOURCE_MAGIC {
            // Standalone .resources file format: [magic][header...]
            parser.seek(4)?; // Reset to after magic number
            Ok(false)
        } else {
            Err(malformed_error!(
                "Invalid resource format - expected magic 0x{:08X}, found 0x{:08X}/0x{:08X}",
                RESOURCE_MAGIC,
                first_u32,
                second_u32
            ))
        }
    }

    /// Parse the Resource Manager header section.
    ///
    /// The Resource Manager header contains version information and type strings that
    /// identify the reader and resource set classes used to parse the file.
    ///
    /// # Header Format
    ///
    /// ```text
    /// [version: u32]           - Header version (1 = V1 format with type strings)
    /// [num_bytes_to_skip: u32] - For V1: ignored; For V2+: bytes to skip
    /// [reader_type: string]    - V1 only: IResourceReader implementation class name
    /// [resource_set_type: string] - V1 only: ResourceSet implementation class name
    /// ```
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned after the magic number
    ///
    /// # Returns
    ///
    /// A tuple of `(version, header_size, reader_type, resource_set_type)`.
    /// For V2+ formats, `reader_type` and `resource_set_type` will be empty strings.
    ///
    /// # Errors
    ///
    /// Returns an error if:
    /// - The skip bytes value exceeds 1GB (sanity check)
    /// - The reader type is not a supported implementation
    /// - String reading fails due to malformed data
    fn parse_resource_manager_header(parser: &mut Parser) -> Result<(u32, u32, String, String)> {
        let version = parser.read_le::<u32>()?;
        let num_bytes_to_skip = parser.read_le::<u32>()?;

        if version > 1 {
            // Future version: skip the specified number of bytes
            if num_bytes_to_skip > (1 << 30) {
                return Err(malformed_error!(
                    "Invalid skip bytes: {}",
                    num_bytes_to_skip
                ));
            }
            parser.advance_by(num_bytes_to_skip as usize)?;
            Ok((version, num_bytes_to_skip, String::new(), String::new()))
        } else {
            // V1 header: read reader type and resource set type
            let reader_type = parser.read_prefixed_string_utf8()?;
            let resource_set_type = parser.read_prefixed_string_utf8()?;

            if !Self::validate_reader_type(&reader_type) {
                return Err(malformed_error!("Unsupported reader type: {}", reader_type));
            }

            Ok((version, num_bytes_to_skip, reader_type, resource_set_type))
        }
    }

    /// Parse the `RuntimeResourceReader` header section.
    ///
    /// This section contains the resource reader version, optional debug information,
    /// and the total count of resources in the file.
    ///
    /// # Header Format
    ///
    /// ```text
    /// [rr_version: u32]        - RuntimeResourceReader version (1 or 2)
    /// ["***DEBUG***": string]  - V2 only, optional: Present in debug builds
    /// [resource_count: u32]    - Number of resources in this file
    /// ```
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned at the start of the RR header
    /// * `data` - Complete resource data buffer (used for bounds checking)
    /// * `res` - Resource struct to populate with parsed values
    ///
    /// # Errors
    ///
    /// Returns an error if:
    /// - The RR version is not 1 or 2
    /// - The resource count exceeds `MAX_RESOURCES` (1,000,000)
    fn parse_runtime_reader_header(
        parser: &mut Parser,
        data: &[u8],
        res: &mut Resource,
    ) -> Result<()> {
        res.rr_version = parser.read_le::<u32>()?;

        if res.rr_version != 1 && res.rr_version != 2 {
            return Err(malformed_error!(
                "Unsupported resource reader version: {}",
                res.rr_version
            ));
        }

        // Check for debug string in V2 debug builds ("***DEBUG***")
        if res.rr_version == 2 && (data.len() - parser.pos()) >= 11 {
            res.is_debug = Self::try_parse_debug_marker(parser);
        }

        res.resource_count = parser.read_le::<u32>()?;
        if res.resource_count > MAX_RESOURCES {
            return Err(malformed_error!(
                "Resource file has too many resources: {} (max: {})",
                res.resource_count,
                MAX_RESOURCES
            ));
        }

        Ok(())
    }

    /// Try to parse the optional `"***DEBUG***"` marker in V2 resources.
    ///
    /// In V2 debug builds, .NET includes a debug marker string immediately after the
    /// RR version number. This method attempts to read and identify this marker using
    /// a peek-and-restore pattern to avoid consuming data if the marker isn't present.
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned where the debug marker might be
    ///
    /// # Returns
    ///
    /// * `true` - Debug marker was found and consumed
    /// * `false` - No debug marker present (parser position restored)
    fn try_parse_debug_marker(parser: &mut Parser) -> bool {
        let result = parser.transactional(|p| {
            let s = p.read_prefixed_string_utf8()?;
            if s == "***DEBUG***" {
                Ok(true)
            } else {
                Err(malformed_error!("not a debug marker"))
            }
        });

        result.unwrap_or(false)
    }

    /// Parse the type name table.
    ///
    /// The type table contains fully-qualified .NET type names for all resource types
    /// used in this file. Resources reference these types by index when their type
    /// code indicates a user-defined type.
    ///
    /// # Table Format
    ///
    /// ```text
    /// [type_count: u32]        - Number of type names in the table
    /// [type_name: string]...   - Length-prefixed UTF-8 type names (repeated type_count times)
    /// ```
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned at the start of the type table
    /// * `res` - Resource struct to populate with parsed type names
    ///
    /// # Errors
    ///
    /// Returns an error if:
    /// - The type count exceeds `MAX_RESOURCE_TYPES` (4,096)
    /// - Any type name string is malformed
    fn parse_type_table(parser: &mut Parser, res: &mut Resource) -> Result<()> {
        let type_count = parser.read_le::<u32>()?;

        if type_count > MAX_RESOURCE_TYPES {
            return Err(malformed_error!(
                "Resource file has too many types: {} (max: {})",
                type_count,
                MAX_RESOURCE_TYPES
            ));
        }

        res.type_names.reserve(type_count as usize);
        for _ in 0..type_count {
            res.type_names.push(parser.read_prefixed_string_utf8()?);
        }

        Ok(())
    }

    /// Skip padding bytes to align to 8-byte boundary, plus any explicit PAD patterns.
    ///
    /// .NET resource files require 8-byte alignment after the type table before the
    /// hash/position arrays. Some implementations also include explicit "PAD" byte
    /// patterns for additional alignment or debugging purposes.
    ///
    /// # Alignment Strategy
    ///
    /// 1. First, skip bytes to reach 8-byte alignment boundary
    /// 2. Then, skip any explicit "PAD" patterns that may follow
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned after the type table
    /// * `data` - Complete resource data buffer (used for PAD pattern detection)
    ///
    /// # Returns
    ///
    /// The total number of padding bytes skipped (alignment + PAD patterns).
    fn skip_padding(parser: &mut Parser, data: &[u8]) -> Result<usize> {
        let mut padding_count = 0;

        // Standard 8-byte alignment
        let align_bytes = parser.pos() & 7;
        if align_bytes != 0 {
            let padding_to_skip = 8 - align_bytes;
            padding_count += padding_to_skip;
            parser.advance_by(padding_to_skip)?;
        }

        // Check for additional explicit PAD patterns (some .NET implementations add these)
        padding_count += Self::skip_pad_patterns(parser, data)?;

        Ok(padding_count)
    }

    /// Skip any explicit "PAD" byte patterns in the resource file.
    ///
    /// Some .NET resource file implementations include explicit "PAD" ASCII patterns
    /// beyond standard 8-byte alignment. This method detects and skips these patterns.
    ///
    /// # Supported Patterns
    ///
    /// - `"PAD"` (3 bytes) - Basic padding marker
    /// - `"PADP"` (4 bytes) - Extended padding with 'P' continuation
    /// - `"PAD\0"` (4 bytes) - Null-terminated padding marker
    ///
    /// Multiple consecutive PAD patterns are handled (the loop continues until
    /// a non-PAD sequence is encountered).
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned where PAD patterns might begin
    /// * `data` - Complete resource data buffer (used for pattern detection)
    ///
    /// # Returns
    ///
    /// The total number of PAD pattern bytes skipped.
    fn skip_pad_patterns(parser: &mut Parser, data: &[u8]) -> Result<usize> {
        let mut padding_count = 0;

        while parser.pos() + 4 <= data.len() {
            let pos = parser.pos();
            let remaining = data.len() - pos;

            // Need at least 3 bytes to check for "PAD"
            if remaining < 3 {
                break;
            }

            // Check for "PAD" pattern
            if data[pos] == b'P' && data[pos + 1] == b'A' && data[pos + 2] == b'D' {
                parser.advance_by(3)?;
                padding_count += 3;

                // Check for additional padding byte after PAD ('P' or '\0')
                if parser.pos() < data.len() {
                    let next_byte = data[parser.pos()];
                    if next_byte == b'P' || next_byte == 0 {
                        parser.advance()?;
                        padding_count += 1;
                    }
                }
            } else {
                break;
            }
        }

        Ok(padding_count)
    }

    /// Parse the name hash and position lookup tables.
    ///
    /// These tables enable efficient resource lookup by name. The hash table contains
    /// pre-computed hash values for each resource name, and the position table contains
    /// offsets into the name section where each resource's name and data pointer are stored.
    ///
    /// # Table Format
    ///
    /// ```text
    /// [name_hash: u32]...      - Hash values (repeated resource_count times)
    /// [name_position: u32]...  - Name section offsets (repeated resource_count times)
    /// ```
    ///
    /// # Arguments
    ///
    /// * `parser` - Parser positioned after padding, at the start of the hash table
    /// * `res` - Resource struct to populate with hash and position arrays
    ///
    /// # Notes
    ///
    /// The arrays are pre-allocated using `reserve()` to avoid reallocation during parsing.
    fn parse_lookup_tables(parser: &mut Parser, res: &mut Resource) -> Result<()> {
        let count = res.resource_count as usize;

        res.name_hashes.reserve(count);
        for _ in 0..count {
            res.name_hashes.push(parser.read_le::<u32>()?);
        }

        res.name_positions.reserve(count);
        for _ in 0..count {
            res.name_positions.push(parser.read_le::<u32>()?);
        }

        Ok(())
    }

    /// Parse all resources into a name-indexed collection with full type resolution.
    ///
    /// This method performs the actual resource data parsing, extracting resource names,
    /// types, and values from the name and data sections. It uses the hash table and
    /// position information parsed by [`parse()`](Resource::parse) to efficiently
    /// locate and decode each resource.
    ///
    /// # Parsing Process
    ///
    /// For each resource:
    /// 1. **Name Resolution**: Uses position table to locate UTF-16 resource name
    /// 2. **Offset Calculation**: Extracts data section offset for the resource
    /// 3. **Type Identification**: Reads type code and resolves to concrete type
    /// 4. **Data Extraction**: Parses typed resource data based on type information
    /// 5. **Entry Creation**: Creates complete `ResourceEntry` with metadata
    ///
    /// # Arguments
    ///
    /// * `data` - The same complete resource file data buffer used for parsing
    ///
    /// # Returns
    ///
    /// A `BTreeMap<String, ResourceEntry>` containing all resources indexed by name.
    /// The map maintains sorted order for consistent iteration and enables efficient
    /// lookups by resource name.
    ///
    /// # Errors
    ///
    /// Returns an error if:
    /// - Name section offsets point beyond the data buffer
    /// - UTF-16 resource names are malformed or truncated
    /// - Data section offsets are invalid or out of bounds
    /// - Resource type codes are unsupported or corrupted
    /// - Individual resource data cannot be parsed
    ///
    /// # Examples
    ///
    /// ```ignore
    /// use dotscope::metadata::resources::Resource;
    ///
    /// let resource_data = std::fs::read("MyApp.resources")?;
    /// let mut resource = Resource::parse(&resource_data)?;
    /// let resources = resource.read_resources(&resource_data)?;
    ///
    /// println!("Found {} resources:", resources.len());
    /// for (name, entry) in &resources {
    ///     println!("Resource: {} (Hash: 0x{:08X})", name, entry.name_hash);
    ///
    ///     match &entry.data {
    ///         ResourceType::String(s) => {
    ///             println!("  String: '{}'", s);
    ///         }
    ///         ResourceType::ByteArray(bytes) => {
    ///             println!("  Binary data: {} bytes", bytes.len());
    ///         }
    ///         ResourceType::Int32(value) => {
    ///             println!("  Integer: {}", value);
    ///         }
    ///         _ => {
    ///             println!("  Other type: {:?}", entry.data);
    ///         }
    ///     }
    /// }
    /// ```
    ///
    /// # Resource Types
    ///
    /// Supports all standard .NET resource types:
    /// - **Primitive Types**: `bool`, `byte`, `sbyte`, `char`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `single`, `double`, `decimal`
    /// - **String Types**: UTF-16 strings with length prefixes
    /// - **`DateTime`**: .NET `DateTime` binary format
    /// - **`TimeSpan`**: .NET `TimeSpan` binary format
    /// - **Byte Arrays**: Raw binary data with length prefixes
    /// - **Custom Objects**: Serialized .NET objects (parsing depends on type)
    pub fn read_resources(&mut self, data: &[u8]) -> Result<BTreeMap<String, ResourceEntry>> {
        let count = self.resource_count as usize;
        if self.name_hashes.len() != count || self.name_positions.len() != count {
            return Err(malformed_error!(
                "Resource count {} doesn't match hash/position array lengths ({}/{})",
                self.resource_count,
                self.name_hashes.len(),
                self.name_positions.len()
            ));
        }

        let mut resources = BTreeMap::new();
        let mut parser = Parser::new(data);

        for i in 0..count {
            let name_pos = self.name_section_offset + self.name_positions[i] as usize;
            parser.seek(name_pos)?;

            let name = parser.read_prefixed_string_utf16()?;
            let type_offset = parser.read_le::<u32>()?;

            let data_pos = if self.is_embedded_resource {
                // Embedded resources: offset calculated from magic number position, need +4 for size field
                self.data_section_offset + type_offset as usize + 4
            } else {
                // Standalone .resources files: use direct offset
                self.data_section_offset + type_offset as usize
            };

            // Validate data position bounds
            if data_pos >= data.len() {
                return Err(malformed_error!(
                    "Resource data offset {} is beyond file bounds",
                    data_pos
                ));
            }

            parser.seek(data_pos)?;

            let resource_data = if self.rr_version == 1 {
                // V1 format: type index (7-bit encoded) followed by data
                let type_index = parser.read_7bit_encoded_int()?;
                if type_index == u32::MAX {
                    // -1 encoded as 7-bit represents null
                    ResourceType::Null
                } else if (type_index as usize) < self.type_names.len() {
                    let type_name = &self.type_names[type_index as usize];
                    ResourceType::from_type_name(type_name, &mut parser)?
                } else {
                    return Err(malformed_error!("Invalid type index: {}", type_index));
                }
            } else {
                // V2 format: type code (7-bit encoded) followed by data
                #[allow(clippy::cast_possible_truncation)]
                let type_code = parser.read_7bit_encoded_int()? as u8;

                if self.type_names.is_empty() {
                    // No type table - this file uses only primitive types (direct type codes)
                    // Common in resource files that contain only strings/primitives
                    ResourceType::from_type_byte(type_code, &mut parser)?
                } else {
                    // Has type table - type code is an index into the type table
                    if (type_code as usize) < self.type_names.len() {
                        let type_name = &self.type_names[type_code as usize];
                        ResourceType::from_type_name(type_name, &mut parser)?
                    } else {
                        return Err(malformed_error!("Invalid type index: {}", type_code));
                    }
                }
            };

            let result = ResourceEntry {
                name: name.clone(),
                name_hash: self.name_hashes[i],
                data: resource_data,
            };

            resources.insert(name, result);
        }

        Ok(resources)
    }

    /// Parse all resources into a name-indexed collection with zero-copy semantics.
    ///
    /// This is the zero-copy variant of [`read_resources`](Resource::read_resources). Instead
    /// of allocating owned copies of resource data, it returns borrowed slices directly into
    /// the source data buffer. This is essential for efficient handling of large embedded
    /// resources like ZIP archives that could be hundreds of megabytes or gigabytes.
    ///
    /// # Parsing Process
    ///
    /// Identical to [`read_resources`](Resource::read_resources), but for each resource:
    /// - **String data**: Returns `&'a str` instead of allocating `String`
    /// - **Byte arrays**: Returns `&'a [u8]` instead of allocating `Vec<u8>`
    /// - **Primitive types**: Returned by value (no difference from owned variant)
    ///
    /// # Arguments
    ///
    /// * `data` - The complete resource file data buffer used for parsing. This is the same
    ///   buffer that was passed to [`parse`](Resource::parse).
    ///
    /// # Lifetime
    ///
    /// The returned resources borrow from the `data` parameter. All borrowed resource data
    /// (strings and byte arrays) will remain valid as long as `data` is valid.
    ///
    /// # Returns
    ///
    /// A `BTreeMap<String, ResourceEntryRef<'a>>` containing all resources indexed by name.
    /// The map maintains sorted order for consistent iteration and enables efficient lookups.
    /// Resource names are owned (String) for efficient map key usage, but resource data is borrowed.
    ///
    /// # Errors
    ///
    /// Returns an error if:
    /// - Name section offsets point beyond the data buffer
    /// - UTF-16 resource names are malformed or truncated
    /// - Data section offsets are invalid or out of bounds
    /// - Resource type codes are unsupported or corrupted
    /// - Individual resource data cannot be parsed
    ///
    /// # Examples
    ///
    /// ## Basic Zero-Copy Usage
    ///
    /// ```ignore
    /// use dotscope::metadata::resources::Resource;
    /// use dotscope::metadata::resources::ResourceTypeRef;
    ///
    /// let resource_data = std::fs::read("MyApp.resources")?;
    /// let mut resource = Resource::parse(&resource_data)?;
    /// let resources = resource.read_resources_ref(&resource_data)?;
    ///
    /// println!("Found {} resources:", resources.len());
    /// for (name, entry) in &resources {
    ///     println!("Resource: {} (Hash: 0x{:08X})", name, entry.name_hash);
    ///
    ///     match &entry.data {
    ///         ResourceTypeRef::ByteArray(bytes) => {
    ///             // Zero-copy access - no allocation!
    ///             println!("  Binary data: {} bytes (no copy!)", bytes.len());
    ///         }
    ///         ResourceTypeRef::String(s) => {
    ///             // Zero-copy string access
    ///             println!("  String: '{}'", s);
    ///         }
    ///         ResourceTypeRef::Int32(value) => {
    ///             println!("  Integer: {}", value);
    ///         }
    ///         _ => {
    ///             println!("  Other type: {:?}", entry.data);
    ///         }
    ///     }
    /// }
    /// # Ok::<(), dotscope::Error>(())
    /// ```
    ///
    /// ## Extracting Embedded ZIP Archives
    ///
    /// ```ignore
    /// use dotscope::metadata::resources::Resource;
    /// use dotscope::metadata::resources::ResourceTypeRef;
    ///
    /// let resource_data = std::fs::read("MyApp.resources")?;
    /// let mut resource = Resource::parse(&resource_data)?;
    /// let resources = resource.read_resources_ref(&resource_data)?;
    ///
    /// for (name, entry) in &resources {
    ///     if let ResourceTypeRef::ByteArray(bytes) = &entry.data {
    ///         // Check if this is a ZIP file (PK magic number)
    ///         if bytes.len() > 4 && &bytes[0..4] == b"PK\x03\x04" {
    ///             println!("Found embedded ZIP: {} ({} bytes)", name, bytes.len());
    ///
    ///             // Extract ZIP without copying the data
    ///             // Pass borrowed slice directly to ZIP library
    ///             let archive = zip::ZipArchive::new(std::io::Cursor::new(bytes))?;
    ///             println!("  Contains {} files", archive.len());
    ///         }
    ///     }
    /// }
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    ///
    /// Use [`read_resources`](Resource::read_resources) when:
    /// - Resource data needs to outlive the source buffer
    /// - Working with small resources where copy overhead is negligible
    /// - You prefer simpler APIs without lifetime parameters
    pub fn read_resources_ref<'a>(
        &mut self,
        data: &'a [u8],
    ) -> Result<BTreeMap<String, ResourceEntryRef<'a>>> {
        let count = self.resource_count as usize;
        if self.name_hashes.len() != count || self.name_positions.len() != count {
            return Err(malformed_error!(
                "Resource count {} doesn't match hash/position array lengths ({}/{})",
                self.resource_count,
                self.name_hashes.len(),
                self.name_positions.len()
            ));
        }

        let mut resources = BTreeMap::new();
        let mut parser = Parser::new(data);

        for i in 0..count {
            let name_pos = self.name_section_offset + self.name_positions[i] as usize;
            parser.seek(name_pos)?;

            let name = parser.read_prefixed_string_utf16()?;
            let type_offset = parser.read_le::<u32>()?;

            let data_pos = if self.is_embedded_resource {
                // Embedded resources: offset calculated from magic number position, need +4 for size field
                self.data_section_offset + type_offset as usize + 4
            } else {
                // Standalone .resources files: use direct offset
                self.data_section_offset + type_offset as usize
            };

            // Validate data position bounds
            if data_pos >= data.len() {
                return Err(malformed_error!(
                    "Resource data offset {} is beyond file bounds",
                    data_pos
                ));
            }

            parser.seek(data_pos)?;

            let resource_data = if self.rr_version == 1 {
                // V1 format: type index (7-bit encoded) followed by data
                let type_index = parser.read_7bit_encoded_int()?;
                if type_index == u32::MAX {
                    // -1 encoded as 7-bit represents null
                    ResourceTypeRef::Null
                } else if (type_index as usize) < self.type_names.len() {
                    let type_name = &self.type_names[type_index as usize];
                    ResourceTypeRef::from_type_name_ref(type_name, &mut parser, data)?
                } else {
                    return Err(malformed_error!("Invalid type index: {}", type_index));
                }
            } else {
                // V2 format: type code (7-bit encoded) followed by data
                #[allow(clippy::cast_possible_truncation)]
                let type_code = parser.read_7bit_encoded_int()? as u8;

                if self.type_names.is_empty() {
                    // No type table - this file uses only primitive types (direct type codes)
                    ResourceTypeRef::from_type_byte_ref(type_code, &mut parser, data)?
                } else {
                    // Has type table - type code is an index into the type table
                    if (type_code as usize) < self.type_names.len() {
                        let type_name = &self.type_names[type_code as usize];
                        ResourceTypeRef::from_type_name_ref(type_name, &mut parser, data)?
                    } else {
                        return Err(malformed_error!("Invalid type index: {}", type_code));
                    }
                }
            };

            let result = ResourceEntryRef {
                name: name.clone(),
                name_hash: self.name_hashes[i],
                data: resource_data,
            };

            resources.insert(name, result);
        }

        Ok(resources)
    }

    /// Validate that the reader type is supported by this parser.
    ///
    /// Based on .NET Framework validation, accepts:
    /// - System.Resources.ResourceReader (with or without assembly qualification)
    /// - System.Resources.Extensions.DeserializingResourceReader
    fn validate_reader_type(reader_type: &str) -> bool {
        match reader_type {
            "System.Resources.ResourceReader"
            | "System.Resources.Extensions.DeserializingResourceReader" => true,
            // Accept fully qualified names with mscorlib assembly info
            s if s.starts_with("System.Resources.ResourceReader,") => true,
            s if s.starts_with("System.Resources.Extensions.DeserializingResourceReader,") => true,
            _ => false,
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::test::verify_wbdll_resource_buffer;

    #[test]
    fn wb_example() {
        let data =
            include_bytes!("../../../tests/samples/WB_FxResources.WindowsBase.SR.resources.bin");
        verify_wbdll_resource_buffer(data);
    }
}