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
//! High-level interface builder for creating .NET interface definitions.
//!
//! This module provides [`InterfaceBuilder`] for creating complete interface definitions
//! including method signatures, properties, and events. It orchestrates the existing
//! low-level builders to provide a fluent, high-level API for interface creation.

use crate::{
    cilassembly::{ChangeRefRc, CilAssembly},
    metadata::{
        method::{MethodAccessFlags, MethodModifiers},
        signatures::{encode_method_signature, SignatureMethod, SignatureParameter, TypeSignature},
        tables::{
            CodedIndex, CodedIndexType, InterfaceImplBuilder, MethodDefBuilder,
            MethodSemanticsAttributes, MethodSemanticsBuilder, TableId, TypeAttributes,
            TypeDefBuilder,
        },
    },
    Error, Result,
};

use super::property::PropertyBuilder;

/// Method signature definition for the interface builder.
struct InterfaceMethodDefinition {
    name: String,
    return_type: TypeSignature,
    parameters: Vec<(String, TypeSignature)>,
    attributes: u32,
}

/// Property definition for the interface builder.
struct InterfacePropertyDefinition {
    name: String,
    property_type: TypeSignature,
    has_getter: bool,
    has_setter: bool,
}

/// High-level builder for creating complete interface definitions.
///
/// `InterfaceBuilder` provides a fluent API for creating interfaces with method
/// signatures, properties, and events. It composes the existing low-level builders
/// to provide a convenient high-level interface for .NET interface creation.
///
/// # Design
///
/// The builder follows a composition approach:
/// - Uses existing `TypeDefBuilder` for the interface definition with INTERFACE flag
/// - Uses `MethodDefBuilder` for abstract method signatures
/// - Uses `PropertyBuilder` for property definitions
/// - Manages inheritance relationships between interfaces
/// - Validates interface constraints (no fields, only abstract methods)
///
/// # Examples
///
/// ## Simple Interface
///
/// ```rust,no_run
/// use dotscope::prelude::*;
///
/// # fn example() -> dotscope::Result<()> {
/// # let view = CilAssemblyView::from_path("test.dll")?;
/// # let mut assembly = CilAssembly::new(view);
/// let interface_token = InterfaceBuilder::new("ICalculator")
///     .public()
///     .method_signature("Add", TypeSignature::I4, vec![
///         ("a".to_string(), TypeSignature::I4),
///         ("b".to_string(), TypeSignature::I4)
///     ])
///     .method_signature("Subtract", TypeSignature::I4, vec![
///         ("a".to_string(), TypeSignature::I4),
///         ("b".to_string(), TypeSignature::I4)
///     ])
///     .build(&mut assembly)?;
/// # Ok(())
/// # }
/// ```
///
/// ## Interface with Properties
///
/// ```rust,no_run
/// use dotscope::prelude::*;
///
/// # fn example() -> dotscope::Result<()> {
/// # let view = CilAssemblyView::from_path("test.dll")?;
/// # let mut assembly = CilAssembly::new(view);
/// let interface_token = InterfaceBuilder::new("IRepository")
///     .public()
///     .property("Count", TypeSignature::I4, true, false) // getter only
///     .property("IsReadOnly", TypeSignature::Boolean, true, false)
///     .method_signature("GetItem", TypeSignature::Object, vec![
///         ("id".to_string(), TypeSignature::I4)
///     ])
///     .build(&mut assembly)?;
/// # Ok(())
/// # }
/// ```
///
/// ## Interface Inheritance
///
/// ```rust,no_run
/// use dotscope::prelude::*;
///
/// # fn example() -> dotscope::Result<()> {
/// # let view = CilAssemblyView::from_path("test.dll")?;
/// # let mut assembly = CilAssembly::new(view);
/// // First create the base interface
/// let base_interface_ref = InterfaceBuilder::new("ICalculator")
///     .public()
///     .build(&mut assembly)?;
///
/// // Then use its placeholder to reference it in the derived interface
/// let derived_interface = InterfaceBuilder::new("IAdvancedCalculator")
///     .public()
///     .extends_row(base_interface_ref.placeholder()) // Inherit from ICalculator
///     .method_signature("Power", TypeSignature::R8, vec![
///         ("base".to_string(), TypeSignature::R8),
///         ("exponent".to_string(), TypeSignature::R8)
///     ])
///     .build(&mut assembly)?;
/// # Ok(())
/// # }
/// ```
pub struct InterfaceBuilder {
    /// Interface name
    name: String,

    /// Namespace (optional)
    namespace: Option<String>,

    /// Interface visibility attributes
    visibility: u32,

    /// Additional interface attributes
    attributes: u32,

    /// Method signatures in this interface
    methods: Vec<InterfaceMethodDefinition>,

    /// Properties in this interface
    properties: Vec<InterfacePropertyDefinition>,

    /// Inherited interfaces
    extends: Vec<CodedIndex>,
}

impl InterfaceBuilder {
    /// Create a new interface builder with the given name.
    ///
    /// # Arguments
    ///
    /// * `name` - Interface name
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IMyInterface");
    /// ```
    #[must_use]
    pub fn new(name: &str) -> Self {
        Self {
            name: name.to_string(),
            namespace: None,
            visibility: TypeAttributes::PUBLIC,
            attributes: TypeAttributes::INTERFACE | TypeAttributes::ABSTRACT,
            methods: Vec::new(),
            properties: Vec::new(),
            extends: Vec::new(),
        }
    }

    /// Set the namespace for this interface.
    ///
    /// # Arguments
    ///
    /// * `namespace` - Namespace string
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IMyInterface")
    ///     .namespace("MyApp.Interfaces");
    /// ```
    #[must_use]
    pub fn namespace(mut self, namespace: &str) -> Self {
        self.namespace = Some(namespace.to_string());
        self
    }

    /// Make this interface public.
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IMyInterface")
    ///     .public();
    /// ```
    #[must_use]
    pub fn public(mut self) -> Self {
        self.visibility = TypeAttributes::PUBLIC;
        self
    }

    /// Make this interface internal (assembly visibility).
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IMyInterface")
    ///     .internal();
    /// ```
    #[must_use]
    pub fn internal(mut self) -> Self {
        self.visibility = TypeAttributes::NOT_PUBLIC;
        self
    }

    /// Add interface inheritance.
    ///
    /// # Arguments
    ///
    /// * `interface` - CodedIndex of the interface to extend
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// # let base_interface = CodedIndex::new(TableId::TypeRef, 1, CodedIndexType::TypeDefOrRef);
    /// let builder = InterfaceBuilder::new("IDerived")
    ///     .extends(base_interface);
    /// ```
    #[must_use]
    pub fn extends(mut self, interface: CodedIndex) -> Self {
        self.extends.push(interface);
        self
    }

    /// Add interface inheritance using a row index or placeholder.
    ///
    /// # Arguments
    ///
    /// * `interface_row` - Row index or placeholder of the interface to extend (use `placeholder()` from `ChangeRefRc`)
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// # fn example(base_ref: ChangeRefRc) {
    /// let builder = InterfaceBuilder::new("IDerived")
    ///     .extends_row(base_ref.placeholder());
    /// # }
    /// ```
    #[must_use]
    pub fn extends_row(mut self, interface_row: u32) -> Self {
        let coded_index = CodedIndex::new(
            TableId::TypeDef,
            interface_row,
            CodedIndexType::TypeDefOrRef,
        );
        self.extends.push(coded_index);
        self
    }

    /// Add a method signature to the interface.
    ///
    /// # Arguments
    ///
    /// * `name` - Method name
    /// * `return_type` - Method return type
    /// * `parameters` - Method parameters as (name, type) pairs
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("ICalculator")
    ///     .method_signature("Add", TypeSignature::I4, vec![
    ///         ("a".to_string(), TypeSignature::I4),
    ///         ("b".to_string(), TypeSignature::I4)
    ///     ]);
    /// ```
    #[must_use]
    pub fn method_signature(
        mut self,
        name: &str,
        return_type: TypeSignature,
        parameters: Vec<(String, TypeSignature)>,
    ) -> Self {
        self.methods.push(InterfaceMethodDefinition {
            name: name.to_string(),
            return_type,
            parameters,
            attributes: MethodModifiers::ABSTRACT.bits()
                | MethodAccessFlags::PUBLIC.bits()
                | MethodModifiers::HIDE_BY_SIG.bits(),
        });
        self
    }

    /// Add a simple method signature with no parameters.
    ///
    /// # Arguments
    ///
    /// * `name` - Method name
    /// * `return_type` - Method return type
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IService")
    ///     .simple_method("Start", TypeSignature::Void)
    ///     .simple_method("Stop", TypeSignature::Void);
    /// ```
    #[must_use]
    pub fn simple_method(self, name: &str, return_type: TypeSignature) -> Self {
        self.method_signature(name, return_type, vec![])
    }

    /// Add a property to the interface.
    ///
    /// # Arguments
    ///
    /// * `name` - Property name
    /// * `property_type` - Property type
    /// * `has_getter` - Whether the property has a getter
    /// * `has_setter` - Whether the property has a setter
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IRepository")
    ///     .property("Count", TypeSignature::I4, true, false); // read-only
    /// ```
    #[must_use]
    pub fn property(
        mut self,
        name: &str,
        property_type: TypeSignature,
        has_getter: bool,
        has_setter: bool,
    ) -> Self {
        self.properties.push(InterfacePropertyDefinition {
            name: name.to_string(),
            property_type,
            has_getter,
            has_setter,
        });
        self
    }

    /// Add a read-only property to the interface.
    ///
    /// # Arguments
    ///
    /// * `name` - Property name
    /// * `property_type` - Property type
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IRepository")
    ///     .readonly_property("Count", TypeSignature::I4);
    /// ```
    #[must_use]
    pub fn readonly_property(self, name: &str, property_type: TypeSignature) -> Self {
        self.property(name, property_type, true, false)
    }

    /// Add a read-write property to the interface.
    ///
    /// # Arguments
    ///
    /// * `name` - Property name
    /// * `property_type` - Property type
    ///
    /// # Examples
    ///
    /// ```rust,no_run
    /// use dotscope::prelude::*;
    ///
    /// let builder = InterfaceBuilder::new("IRepository")
    ///     .readwrite_property("IsEnabled", TypeSignature::Boolean);
    /// ```
    #[must_use]
    pub fn readwrite_property(self, name: &str, property_type: TypeSignature) -> Self {
        self.property(name, property_type, true, true)
    }

    /// Build the interface and add it to the assembly.
    ///
    /// This method creates:
    /// 1. TypeDef table entry with INTERFACE flag
    /// 2. Abstract method definitions for interface methods
    /// 3. Property definitions with abstract accessors
    /// 4. InterfaceImpl entries for inheritance
    ///
    /// # Arguments
    ///
    /// * `assembly` - CIL assembly for managing the metadata
    ///
    /// # Returns
    ///
    /// A token representing the newly created interface definition.
    ///
    /// # Errors
    ///
    /// Returns an error if interface creation fails at any step.
    pub fn build(self, assembly: &mut CilAssembly) -> Result<ChangeRefRc> {
        // Validate interface constraints
        if self.name.is_empty() {
            return Err(Error::ModificationInvalid(
                "Interface name cannot be empty".to_string(),
            ));
        }

        // Create the interface TypeDef entry
        let mut typedef_builder = TypeDefBuilder::new()
            .name(&self.name)
            .flags(self.visibility | self.attributes);

        if let Some(namespace) = &self.namespace {
            typedef_builder = typedef_builder.namespace(namespace);
        }

        let interface_ref = typedef_builder.build(assembly)?;

        // Create method signatures
        for method_def in self.methods {
            // Build method signature
            let signature_params: Vec<SignatureParameter> = method_def
                .parameters
                .iter()
                .map(|(_, param_type)| SignatureParameter {
                    modifiers: Vec::new(),
                    by_ref: false,
                    base: param_type.clone(),
                })
                .collect();

            let method_signature = SignatureMethod {
                has_this: true,
                explicit_this: false,
                default: true,
                vararg: false,
                cdecl: false,
                stdcall: false,
                thiscall: false,
                fastcall: false,
                param_count_generic: 0,
                param_count: u32::try_from(method_def.parameters.len())
                    .map_err(|_| malformed_error!("Method parameter count exceeds u32 range"))?,
                return_type: SignatureParameter {
                    modifiers: Vec::new(),
                    by_ref: false,
                    base: method_def.return_type.clone(),
                },
                params: signature_params,
                varargs: Vec::new(),
            };

            // Encode the signature
            let signature_bytes = encode_method_signature(&method_signature)?;

            MethodDefBuilder::new()
                .name(&method_def.name)
                .flags(method_def.attributes)
                .impl_flags(0x0000) // MANAGED | IL
                .signature(&signature_bytes)
                .build(assembly)?;
        }

        // Create properties with abstract accessors
        for prop_def in self.properties {
            let mut getter_placeholder: Option<u32> = None;
            let mut setter_placeholder: Option<u32> = None;

            if prop_def.has_getter {
                // Create abstract getter
                let getter_name = format!("get_{}", prop_def.name);

                // Create getter signature - no parameters, returns property type
                let getter_signature = SignatureMethod {
                    has_this: true,
                    explicit_this: false,
                    default: true,
                    vararg: false,
                    cdecl: false,
                    stdcall: false,
                    thiscall: false,
                    fastcall: false,
                    param_count_generic: 0,
                    param_count: 0,
                    return_type: SignatureParameter {
                        modifiers: Vec::new(),
                        by_ref: false,
                        base: prop_def.property_type.clone(),
                    },
                    params: Vec::new(),
                    varargs: Vec::new(),
                };
                let getter_signature_bytes = encode_method_signature(&getter_signature)?;

                let getter_ref = MethodDefBuilder::new()
                    .name(&getter_name)
                    .flags(
                        MethodModifiers::ABSTRACT.bits()
                            | MethodAccessFlags::PUBLIC.bits()
                            | MethodModifiers::HIDE_BY_SIG.bits()
                            | MethodModifiers::SPECIAL_NAME.bits(),
                    )
                    .impl_flags(0x0000) // MANAGED | IL
                    .signature(&getter_signature_bytes)
                    .build(assembly)?;

                getter_placeholder = Some(getter_ref.placeholder());
            }

            if prop_def.has_setter {
                // Create abstract setter
                let setter_name = format!("set_{}", prop_def.name);

                // Create setter signature - takes property type parameter, returns void
                let setter_signature = SignatureMethod {
                    has_this: true,
                    explicit_this: false,
                    default: true,
                    vararg: false,
                    cdecl: false,
                    stdcall: false,
                    thiscall: false,
                    fastcall: false,
                    param_count_generic: 0,
                    param_count: 1,
                    return_type: SignatureParameter {
                        modifiers: Vec::new(),
                        by_ref: false,
                        base: TypeSignature::Void,
                    },
                    params: vec![SignatureParameter {
                        modifiers: Vec::new(),
                        by_ref: false,
                        base: prop_def.property_type.clone(),
                    }],
                    varargs: Vec::new(),
                };
                let setter_signature_bytes = encode_method_signature(&setter_signature)?;

                let setter_ref = MethodDefBuilder::new()
                    .name(&setter_name)
                    .flags(
                        MethodModifiers::ABSTRACT.bits()
                            | MethodAccessFlags::PUBLIC.bits()
                            | MethodModifiers::HIDE_BY_SIG.bits()
                            | MethodModifiers::SPECIAL_NAME.bits(),
                    )
                    .impl_flags(0x0000) // MANAGED | IL
                    .signature(&setter_signature_bytes)
                    .build(assembly)?;

                setter_placeholder = Some(setter_ref.placeholder());
            }

            // Create property entry using PropertyBuilder
            let property_ref =
                PropertyBuilder::new(&prop_def.name, prop_def.property_type).build(assembly)?;

            let property_placeholder = property_ref.placeholder();

            if let Some(getter_row) = getter_placeholder {
                MethodSemanticsBuilder::new()
                    .semantics(MethodSemanticsAttributes::GETTER)
                    .method(getter_row)
                    .association_from_property(property_placeholder)
                    .build(assembly)?;
            }

            if let Some(setter_row) = setter_placeholder {
                MethodSemanticsBuilder::new()
                    .semantics(MethodSemanticsAttributes::SETTER)
                    .method(setter_row)
                    .association_from_property(property_placeholder)
                    .build(assembly)?;
            }
        }

        // Create InterfaceImpl entries for inheritance
        for interface_index in self.extends {
            InterfaceImplBuilder::new()
                .class(interface_ref.placeholder())
                .interface(interface_index)
                .build(assembly)?;
        }

        Ok(interface_ref)
    }
}

impl Default for InterfaceBuilder {
    fn default() -> Self {
        Self::new("DefaultInterface")
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        cilassembly::{ChangeRefKind, CilAssembly},
        metadata::{cilassemblyview::CilAssemblyView, signatures::TypeSignature, tables::TableId},
    };
    use std::path::PathBuf;

    fn get_test_assembly() -> Result<CilAssembly> {
        let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/samples/WindowsBase.dll");
        let view = CilAssemblyView::from_path(&path)?;
        Ok(CilAssembly::new(view))
    }

    #[test]
    fn test_simple_interface() -> Result<()> {
        let mut assembly = get_test_assembly()?;

        let interface_ref = InterfaceBuilder::new("ICalculator")
            .public()
            .namespace("MyApp.Interfaces")
            .method_signature(
                "Add",
                TypeSignature::I4,
                vec![
                    ("a".to_string(), TypeSignature::I4),
                    ("b".to_string(), TypeSignature::I4),
                ],
            )
            .build(&mut assembly)?;

        // Should create a valid TypeDef reference
        assert_eq!(
            interface_ref.kind(),
            ChangeRefKind::TableRow(TableId::TypeDef)
        );

        Ok(())
    }

    #[test]
    fn test_interface_with_properties() -> Result<()> {
        let mut assembly = get_test_assembly()?;

        let interface_ref = InterfaceBuilder::new("IRepository")
            .public()
            .readonly_property("Count", TypeSignature::I4)
            .readwrite_property("IsEnabled", TypeSignature::Boolean)
            .build(&mut assembly)?;

        assert_eq!(
            interface_ref.kind(),
            ChangeRefKind::TableRow(TableId::TypeDef)
        );

        Ok(())
    }

    #[test]
    fn test_interface_inheritance() -> Result<()> {
        let mut assembly = get_test_assembly()?;

        // Create base interface
        let base_ref = InterfaceBuilder::new("IBase")
            .public()
            .simple_method("BaseMethod", TypeSignature::Void)
            .build(&mut assembly)?;

        // Get placeholder for use in extends_row
        let base_placeholder = base_ref.placeholder();

        // Create derived interface
        let derived_ref = InterfaceBuilder::new("IDerived")
            .public()
            .extends_row(base_placeholder)
            .simple_method("DerivedMethod", TypeSignature::Void)
            .build(&mut assembly)?;

        assert_eq!(base_ref.kind(), ChangeRefKind::TableRow(TableId::TypeDef));
        assert_eq!(
            derived_ref.kind(),
            ChangeRefKind::TableRow(TableId::TypeDef)
        );

        Ok(())
    }

    #[test]
    fn test_internal_interface() -> Result<()> {
        let mut assembly = get_test_assembly()?;

        let interface_ref = InterfaceBuilder::new("IInternalInterface")
            .internal()
            .simple_method("InternalMethod", TypeSignature::Void)
            .build(&mut assembly)?;

        assert_eq!(
            interface_ref.kind(),
            ChangeRefKind::TableRow(TableId::TypeDef)
        );

        Ok(())
    }

    #[test]
    fn test_empty_interface() -> Result<()> {
        let mut assembly = get_test_assembly()?;

        let interface_ref = InterfaceBuilder::new("IMarker")
            .public()
            .build(&mut assembly)?;

        assert_eq!(
            interface_ref.kind(),
            ChangeRefKind::TableRow(TableId::TypeDef)
        );

        Ok(())
    }

    #[test]
    fn test_empty_name_fails() {
        let mut assembly = get_test_assembly().unwrap();

        let result = InterfaceBuilder::new("").public().build(&mut assembly);

        assert!(result.is_err());
    }
}