vmi-os-windows 0.7.0

Windows OS specific code for VMI
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
mod directory;
mod file;
mod key;
mod object_type;
mod process;
mod section;
mod thread;
mod token;

use vmi_core::{
    Va, VmiError, VmiState, VmiVa,
    driver::VmiRead,
    os::{ProcessObject, ThreadObject},
};

pub use self::{
    directory::WindowsDirectoryObject,
    file::WindowsFileObject,
    key::WindowsKey,
    object_type::WindowsObjectType,
    process::WindowsProcess,
    section::WindowsSectionObject,
    thread::{WindowsThread, WindowsThreadState, WindowsThreadWaitReason},
    token::{
        WindowsImpersonationLevel, WindowsPrivilege, WindowsToken, WindowsTokenFlags,
        WindowsTokenPrivilege, WindowsTokenSource, WindowsTokenType,
    },
};
use super::WindowsObjectHeaderNameInfo;
use crate::{WindowsOs, WindowsOsExt, arch::ArchAdapter, offset, symbol};

/// Trait for types that can be converted from a [`WindowsObject`].
pub trait FromWindowsObject<'a, Driver>: Sized
where
    Driver: VmiRead,
    Driver::Architecture: ArchAdapter<Driver>,
{
    /// Attempts to convert a [`WindowsObject`] into a specific object type.
    fn from_object(object: WindowsObject<'a, Driver>) -> Result<Option<Self>, VmiError>;
}

/// A Windows object.
///
/// A Windows object is a kernel-managed entity that can be referenced
/// by handles or pointers. It includes processes, threads, files, and other
/// system resources managed by the Windows Object Manager.
///
/// # Implementation Details
///
/// Corresponds to `_OBJECT_HEADER.Body`.
pub struct WindowsObject<'a, Driver>
where
    Driver: VmiRead,
    Driver::Architecture: ArchAdapter<Driver>,
{
    /// The VMI state.
    vmi: VmiState<'a, WindowsOs<Driver>>,

    /// Address of the object.
    va: Va,
}

impl<'a, Driver> FromWindowsObject<'a, Driver> for WindowsObject<'a, Driver>
where
    Driver: VmiRead,
    Driver::Architecture: ArchAdapter<Driver>,
{
    fn from_object(object: WindowsObject<'a, Driver>) -> Result<Option<Self>, VmiError> {
        // Any object can be converted to itself.
        Ok(Some(object))
    }
}

impl<Driver> VmiVa for WindowsObject<'_, Driver>
where
    Driver: VmiRead,
    Driver::Architecture: ArchAdapter<Driver>,
{
    fn va(&self) -> Va {
        self.va
    }
}

impl<Driver> std::fmt::Debug for WindowsObject<'_, Driver>
where
    Driver: VmiRead,
    Driver::Architecture: ArchAdapter<Driver>,
{
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        let name_info = self.name_info();
        let typ = self.type_kind();

        f.debug_struct("WindowsObject")
            .field("typ", &typ)
            .field("name_info", &name_info)
            .finish()
    }
}

impl<'a, Driver> WindowsObject<'a, Driver>
where
    Driver: VmiRead,
    Driver::Architecture: ArchAdapter<Driver>,
{
    /// Creates a new Windows object.
    pub fn new(vmi: VmiState<'a, WindowsOs<Driver>>, va: Va) -> Self {
        Self { vmi, va }
    }

    /// Returns the virtual address of the `_OBJECT_HEADER` structure.
    ///
    /// # Implementation Details
    ///
    /// `_OBJECT_HEADER` is always at the beginning of the object.
    pub fn header(&self) -> Va {
        let OBJECT_HEADER = offset!(self.vmi, _OBJECT_HEADER);

        self.va - OBJECT_HEADER.Body.offset()
    }

    /// Returns the name information of the object.
    pub fn name_info(&self) -> Result<Option<WindowsObjectHeaderNameInfo<'a, Driver>>, VmiError> {
        let ObpInfoMaskToOffset = symbol!(self.vmi, ObpInfoMaskToOffset);
        let OBJECT_HEADER = offset!(self.vmi, _OBJECT_HEADER);

        let info_mask = self
            .vmi
            .read_u8(self.header() + OBJECT_HEADER.InfoMask.offset())?;

        bitflags::bitflags! {
            struct InfoFlags: u8 {
                const CREATOR_INFO = 0x01;
                const NAME_INFO = 0x02;
                const HANDLE_INFO = 0x04;
                const QUOTA_INFO = 0x08;
                const PROCESS_INFO = 0x10;
            }
        }

        let info_flags = InfoFlags::from_bits_truncate(info_mask);
        if !info_flags.contains(InfoFlags::NAME_INFO) {
            return Ok(None);
        }

        // Offset = ObpInfoMaskToOffset[OBJECT_HEADER->InfoMask & (DesiredHeaderBit | (DesiredHeaderBit-1))]

        let mask = info_mask & (InfoFlags::NAME_INFO.bits() | (InfoFlags::NAME_INFO.bits() - 1));
        let mask = mask as u64;

        let kernel_image_base = self.vmi.os().kernel_image_base()?;
        let offset = self
            .vmi
            .read_u8(kernel_image_base + ObpInfoMaskToOffset + mask)? as u64;

        Ok(Some(WindowsObjectHeaderNameInfo::new(
            self.vmi,
            self.header() - offset,
        )))
    }

    /// Returns the directory object associated with the object name.
    ///
    /// Shortcut for [`self.name_info()?.directory()`].
    ///
    /// [`self.name_info()?.directory()`]: WindowsObjectHeaderNameInfo::directory
    pub fn directory(&self) -> Result<Option<WindowsObject<'a, Driver>>, VmiError> {
        let name_info = match self.name_info()? {
            Some(name_info) => name_info,
            None => return Ok(None),
        };

        name_info.directory()
    }

    /// Returns the name of the object.
    ///
    /// Shortcut for [`self.name_info()?.name()`].
    ///
    /// [`self.name_info()?.name()`]: WindowsObjectHeaderNameInfo::name
    pub fn name(&self) -> Result<Option<String>, VmiError> {
        let name_info = match self.name_info()? {
            Some(name_info) => name_info,
            None => return Ok(None),
        };

        Ok(Some(name_info.name()?))
    }

    /// Constructs the full path of a named object from its name information.
    ///
    /// Shortcut for [`self.name_info()?.full_path()`].
    ///
    /// [`self.name_info()?.full_path()`]: WindowsObjectHeaderNameInfo::full_path
    pub fn full_path(&self) -> Result<Option<String>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::File(file)) => Ok(Some(file.full_path()?)),
            Some(WindowsObjectKind::Key(key)) => Ok(Some(key.full_path()?)),
            Some(WindowsObjectKind::Section(section)) => section.full_path(),
            _ => {
                let name_info = match self.name_info()? {
                    Some(name_info) => name_info,
                    None => return Ok(None),
                };

                Ok(Some(name_info.full_path()?))
            }
        }
    }

    /// Returns the type of a Windows kernel object.
    ///
    /// This method analyzes the object header of a kernel object and returns
    /// its type object (`_OBJECT_TYPE`). It handles the obfuscation introduced
    /// by the object header cookie, ensuring accurate type identification even
    /// on systems with this security feature enabled.
    pub fn object_type(&self) -> Result<WindowsObjectType<'a, Driver>, VmiError> {
        let ObTypeIndexTable = symbol!(self.vmi, ObTypeIndexTable);
        let OBJECT_HEADER = offset!(self.vmi, _OBJECT_HEADER);

        let object_header = self.va - OBJECT_HEADER.Body.offset();
        let type_index = self
            .vmi
            .read_u8(object_header + OBJECT_HEADER.TypeIndex.offset())?;

        let index = match self.vmi.os().object_header_cookie()? {
            Some(cookie) => {
                //
                // TypeIndex
                //     ^ 2nd least significate byte of OBJECT_HEADER address
                //     ^ nt!ObHeaderCookie
                // ref: https://medium.com/@ashabdalhalim/a-light-on-windows-10s-object-header-typeindex-value-e8f907e7073a
                //

                let salt = (object_header.0 >> 8) as u8;
                type_index ^ salt ^ cookie
            }
            None => type_index,
        };

        let index = index as u64;

        let kernel_image_base = self.vmi.os().kernel_image_base()?;
        let object_type = self.vmi.read_va_native(
            kernel_image_base + ObTypeIndexTable + index * 8, // REVIEW: replace 8 with registers.address_width()?
        )?;

        Ok(WindowsObjectType::new(self.vmi, object_type))
    }

    /// Returns the object type name.
    ///
    /// Shortcut for [`self.object_type()?.name()`].
    ///
    /// [`self.object_type()?.name()`]: WindowsObjectType::name
    pub fn type_name(&self) -> Result<String, VmiError> {
        self.object_type()?.name()
    }

    /// Returns the object type kind.
    ///
    /// Shortcut for [`self.object_type()?.kind()`].
    ///
    /// [`self.object_type()?.kind()`]: WindowsObjectType::kind
    pub fn type_kind(&self) -> Result<Option<WindowsObjectTypeKind>, VmiError> {
        self.object_type()?.kind()
    }

    /// Returns the specific kind of this object.
    pub fn kind(&self) -> Result<Option<WindowsObjectKind<'a, Driver>>, VmiError> {
        let result = match self.type_kind()? {
            Some(WindowsObjectTypeKind::Directory) => {
                WindowsObjectKind::Directory(WindowsDirectoryObject::new(self.vmi, self.va))
            }
            Some(WindowsObjectTypeKind::File) => {
                WindowsObjectKind::File(WindowsFileObject::new(self.vmi, self.va))
            }
            Some(WindowsObjectTypeKind::Key) => {
                WindowsObjectKind::Key(WindowsKey::new(self.vmi, self.va))
            }
            Some(WindowsObjectTypeKind::Process) => {
                WindowsObjectKind::Process(WindowsProcess::new(self.vmi, ProcessObject(self.va)))
            }
            Some(WindowsObjectTypeKind::Section) => {
                WindowsObjectKind::Section(WindowsSectionObject::new(self.vmi, self.va))
            }
            Some(WindowsObjectTypeKind::Thread) => {
                WindowsObjectKind::Thread(WindowsThread::new(self.vmi, ThreadObject(self.va)))
            }
            Some(WindowsObjectTypeKind::Token) => {
                WindowsObjectKind::Token(WindowsToken::new(self.vmi, self.va))
            }
            Some(WindowsObjectTypeKind::Type) => {
                WindowsObjectKind::Type(WindowsObjectType::new(self.vmi, self.va))
            }
            _ => return Ok(None),
        };

        Ok(Some(result))
    }

    /// Returns the object as a directory (`_OBJECT_DIRECTORY`).
    pub fn as_directory(&self) -> Result<Option<WindowsDirectoryObject<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::Directory(directory)) => Ok(Some(directory)),
            _ => Ok(None),
        }
    }

    /// Returns the object as a file (`_FILE_OBJECT`).
    pub fn as_file(&self) -> Result<Option<WindowsFileObject<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::File(file)) => Ok(Some(file)),
            _ => Ok(None),
        }
    }

    /// Returns the object as a key (`_CM_KEY_BODY`).
    pub fn as_key(&self) -> Result<Option<WindowsKey<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::Key(key)) => Ok(Some(key)),
            _ => Ok(None),
        }
    }

    /// Returns the object as a process (`_EPROCESS`).
    pub fn as_process(&self) -> Result<Option<WindowsProcess<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::Process(process)) => Ok(Some(process)),
            _ => Ok(None),
        }
    }

    /// Returns the object as a section (`_SECTION_OBJECT`).
    pub fn as_section(&self) -> Result<Option<WindowsSectionObject<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::Section(section)) => Ok(Some(section)),
            _ => Ok(None),
        }
    }

    /// Returns the object as a thread (`_ETHREAD`).
    pub fn as_thread(&self) -> Result<Option<WindowsThread<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::Thread(thread)) => Ok(Some(thread)),
            _ => Ok(None),
        }
    }

    /// Returns the object as a token (`_TOKEN`).
    pub fn as_token(&self) -> Result<Option<WindowsToken<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::Token(token)) => Ok(Some(token)),
            _ => Ok(None),
        }
    }

    /// Returns the object as an object type (`_OBJECT_TYPE`).
    pub fn as_type(&self) -> Result<Option<WindowsObjectType<'a, Driver>>, VmiError> {
        match self.kind()? {
            Some(WindowsObjectKind::Type(object_type)) => Ok(Some(object_type)),
            _ => Ok(None),
        }
    }
}

/// Identifies the type of a Windows kernel object.
///
/// Windows uses a object-based kernel architecture where various system
/// resources (processes, threads, files, etc.) are represented as kernel
/// objects. This enum identifies the different types of objects that can
/// be encountered during introspection.
///
/// Each variant corresponds to a specific object type string used internally
/// by the Windows kernel. For example, "Process" for process objects,
/// "Thread" for thread objects, etc.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum WindowsObjectTypeKind {
    /// Activation object.
    ///
    /// Has `ActivationObject` type name.
    ActivationObject,

    /// Activity reference object.
    ///
    /// Has `ActivityReference` type name.
    ActivityReference,

    /// Adapter object.
    ///
    /// Represented by `_ADAPTER_OBJECT` structure.
    /// Has `Adapter` type name.
    Adapter,

    /// ALPC Port object.
    ///
    /// Represented by `_ALPC_PORT` structure.
    /// Has `ALPC Port` type name.
    AlpcPort,

    /// Callback object.
    ///
    /// Has `Callback` type name.
    Callback,

    /// Composition object.
    ///
    /// Has `Composition` type name.
    Composition,

    /// Controller object.
    ///
    /// Has `Controller` type name.
    Controller,

    /// Core messaging object.
    ///
    /// Has `CoreMessaging` type name.
    CoreMessaging,

    /// Coverage sampler object.
    ///
    /// Has `CoverageSampler` type name.
    CoverageSampler,

    /// CPU partition object.
    ///
    /// Has `CpuPartition` type name.
    CpuPartition,

    /// Debug object.
    ///
    /// Represented by `_DEBUG_OBJECT` structure.
    /// Has `DebugObject` type name.
    DebugObject,

    /// Desktop object.
    ///
    /// Has `Desktop` type name.
    Desktop,

    /// Device object.
    ///
    /// Represented by `_DEVICE_OBJECT` structure.
    /// Has `Device` type name.
    Device,

    /// Directory object.
    ///
    /// Represented by `_OBJECT_DIRECTORY` structure.
    /// Has `Directory` type name.
    Directory,

    /// DMA adapter object.
    ///
    /// Has `DmaAdapter` type name.
    DmaAdapter,

    /// Driver object.
    ///
    /// Represented by `_DRIVER_OBJECT` structure.
    /// Has `Driver` type name.
    Driver,

    /// DX Composition object.
    ///
    /// Has `DxgkCompositionObject` type name.
    DxgkCompositionObject,

    /// DX Display Manager object.
    ///
    /// Has `DxgkDisplayManagerObject` type name.
    DxgkDisplayManagerObject,

    /// DX Shared Bundle object.
    ///
    /// Has `DxgkSharedBundleObject` type name.
    DxgkSharedBundleObject,

    /// DX Shared Keyed Mutex object.
    ///
    /// Has `DxgkSharedKeyedMutexObject` type name.
    DxgkSharedKeyedMutexObject,

    /// DX Shared Protected Session object.
    ///
    /// Has `DxgkSharedProtectedSessionObject` type name.
    DxgkSharedProtectedSessionObject,

    /// DX Shared Resource object.
    ///
    /// Has `DxgkSharedResource` type name.
    DxgkSharedResource,

    /// DX Shared Swap Chain object.
    ///
    /// Has `DxgkSharedSwapChainObject` type name.
    DxgkSharedSwapChainObject,

    /// DX Shared Sync object.
    ///
    /// Has `DxgkSharedSyncObject` type name.
    DxgkSharedSyncObject,

    /// Energy tracker object.
    ///
    /// Has `EnergyTracker` type name.
    EnergyTracker,

    /// ETW consumer object.
    ///
    /// Has `EtwConsumer` type name.
    EtwConsumer,

    /// ETW registration object.
    ///
    /// Has `EtwRegistration` type name.
    EtwRegistration,

    /// ETW session demux entry object.
    ///
    /// Has `EtwSessionDemuxEntry` type name.
    EtwSessionDemuxEntry,

    /// Event object.
    ///
    /// Represented by `_KEVENT` structure.
    /// Has `Event` type name.
    Event,

    /// File object.
    ///
    /// Represented by `_FILE_OBJECT` structure.
    /// Has `File` type name.
    File,

    /// Filter communication port object.
    ///
    /// Has `FilterCommunicationPort` type name.
    FilterCommunicationPort,

    /// Filter connection port object.
    ///
    /// Has `FilterConnectionPort` type name.
    FilterConnectionPort,

    /// I/O completion object.
    ///
    /// Has `IoCompletion` type name.
    IoCompletion,

    /// I/O completion reserve object.
    ///
    /// Has `IoCompletionReserve` type name.
    IoCompletionReserve,

    /// I/O ring object.
    ///
    /// Has `IoRing` type name.
    IoRing,

    /// IR timer object.
    ///
    /// Has `IRTimer` type name.
    IRTimer,

    /// Job object.
    ///
    /// Represented by `_EJOB` structure.
    /// Has `Job` type name.
    Job,

    /// Key object.
    ///
    /// Represented by `_CM_KEY_BODY` structure.
    /// Has `Key` type name.
    Key,

    /// Keyed event object.
    ///
    /// Has `KeyedEvent` type name.
    KeyedEvent,

    /// Mutant object.
    ///
    /// Represented by `_KMUTANT` structure.
    /// Has `Mutant` type name.
    Mutant,

    /// NDIS CM state object.
    ///
    /// Has `NdisCmState` type name.
    NdisCmState,

    /// Partition object.
    ///
    /// Has `Partition` type name.
    Partition,

    /// Performance counter object.
    ///
    /// Has `PcwObject` type name.
    PcwObject,

    /// Power request object.
    ///
    /// Has `PowerRequest` type name.
    PowerRequest,

    /// Port object.
    ///
    /// Represented by `_PORT_MESSAGE` structure.
    /// Has `Port` type name.
    Port,

    /// Process object.
    ///
    /// Represented by `_EPROCESS` structure.
    /// Has `Process` type name.
    Process,

    /// Process state change object.
    ///
    /// Has `ProcessStateChange` type name.
    ProcessStateChange,

    /// Profile object.
    ///
    /// Has `Profile` type name.
    Profile,

    /// Sile context (non-paged) object.
    ///
    /// Has `PsSiloContextNonPaged` type name.
    PsSiloContextNonPaged,

    /// Sile context (paged) object.
    ///
    /// Has `PsSiloContextPaged` type name.
    PsSiloContextPaged,

    /// Raw input manager object.
    ///
    /// Has `RawInputManager` type name.
    RawInputManager,

    /// Registry transaction object.
    ///
    /// Has `RegistryTransaction` type name.
    RegistryTransaction,

    /// Section object.
    ///
    /// Represented by `_SECTION` (or `_SECTION_OBJECT`) structure.
    /// Has `Section` type name.
    Section,

    /// Semaphore object.
    ///
    /// Represented by `_KSEMAPHORE` structure.
    /// Has `Semaphore` type name.
    Semaphore,

    /// Session object.
    ///
    /// Has `Session` type name.
    Session,

    /// Symbolic link object.
    ///
    /// Represented by `_OBJECT_SYMBOLIC_LINK` structure.
    /// Has `SymbolicLink` type name.
    SymbolicLink,

    /// Thread object.
    ///
    /// Represented by `_ETHREAD` structure.
    /// Has `Thread` type name.
    Thread,

    /// Thread state change object.
    ///
    /// Has `ThreadStateChange` type name.
    ThreadStateChange,

    /// Timer object.
    ///
    /// Represented by `_KTIMER` structure.
    /// Has `Timer` type name.
    Timer,

    /// Transaction manager (Enlistment) object.
    ///
    /// Has `TmEn` type name.
    TmEn,

    /// Transaction manager (Resource Manager) object.
    ///
    /// Has `TmRm` type name.
    TmRm,

    /// Transaction manager object.
    TmTm,

    /// Transaction object.
    TmTx,

    /// Token object.
    ///
    /// Represented by `_TOKEN` structure.
    /// Has `Token` type name.
    Token,

    /// Thread pool worker factory object.
    ///
    /// Has `TpWorkerFactory` type name.
    TpWorkerFactory,

    /// Type object.
    ///
    /// Represented by `_OBJECT_TYPE` structure.
    /// Has `Type` type name.
    Type,

    /// User APC reserve object.
    ///
    /// Has `UserApcReserve` type name.
    UserApcReserve,

    /// Wait completion packet object.
    ///
    /// Has `WaitCompletionPacket` type name.
    WaitCompletionPacket,

    /// Window station object.
    ///
    /// Has `WindowStation` type name.
    WindowStation,

    /// WMI GUID object.
    ///
    /// Has `WmiGuid` type name.
    WmiGuid,
}

/// Error parsing a Windows object type.
#[derive(Debug, PartialEq, Eq)]
pub struct ParseObjectTypeError;

impl std::str::FromStr for WindowsObjectTypeKind {
    type Err = ParseObjectTypeError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        use WindowsObjectTypeKind::*;

        match s {
            "ActivationObject" => Ok(ActivationObject),
            "ActivityReference" => Ok(ActivityReference),
            "Adapter" => Ok(Adapter),
            "ALPC Port" => Ok(AlpcPort),
            "Callback" => Ok(Callback),
            "Composition" => Ok(Composition),
            "Controller" => Ok(Controller),
            "CoreMessaging" => Ok(CoreMessaging),
            "CoverageSampler" => Ok(CoverageSampler),
            "CpuPartition" => Ok(CpuPartition),
            "DebugObject" => Ok(DebugObject),
            "Desktop" => Ok(Desktop),
            "Device" => Ok(Device),
            "Directory" => Ok(Directory),
            "DmaAdapter" => Ok(DmaAdapter),
            "Driver" => Ok(Driver),
            "DxgkCompositionObject" => Ok(DxgkCompositionObject),
            "DxgkDisplayManagerObject" => Ok(DxgkDisplayManagerObject),
            "DxgkSharedBundleObject" => Ok(DxgkSharedBundleObject),
            "DxgkSharedKeyedMutexObject" => Ok(DxgkSharedKeyedMutexObject),
            "DxgkSharedProtectedSessionObject" => Ok(DxgkSharedProtectedSessionObject),
            "DxgkSharedResource" => Ok(DxgkSharedResource),
            "DxgkSharedSwapChainObject" => Ok(DxgkSharedSwapChainObject),
            "DxgkSharedSyncObject" => Ok(DxgkSharedSyncObject),
            "EnergyTracker" => Ok(EnergyTracker),
            "EtwConsumer" => Ok(EtwConsumer),
            "EtwRegistration" => Ok(EtwRegistration),
            "EtwSessionDemuxEntry" => Ok(EtwSessionDemuxEntry),
            "Event" => Ok(Event),
            "File" => Ok(File),
            "FilterCommunicationPort" => Ok(FilterCommunicationPort),
            "FilterConnectionPort" => Ok(FilterConnectionPort),
            "IoCompletion" => Ok(IoCompletion),
            "IoCompletionReserve" => Ok(IoCompletionReserve),
            "IoRing" => Ok(IoRing),
            "IRTimer" => Ok(IRTimer),
            "Job" => Ok(Job),
            "Key" => Ok(Key),
            "KeyedEvent" => Ok(KeyedEvent),
            "Mutant" => Ok(Mutant),
            "NdisCmState" => Ok(NdisCmState),
            "Partition" => Ok(Partition),
            "PcwObject" => Ok(PcwObject),
            "PowerRequest" => Ok(PowerRequest),
            "Port" => Ok(Port),
            "Process" => Ok(Process),
            "ProcessStateChange" => Ok(ProcessStateChange),
            "Profile" => Ok(Profile),
            "PsSiloContextNonPaged" => Ok(PsSiloContextNonPaged),
            "PsSiloContextPaged" => Ok(PsSiloContextPaged),
            "RawInputManager" => Ok(RawInputManager),
            "RegistryTransaction" => Ok(RegistryTransaction),
            "Section" => Ok(Section),
            "Semaphore" => Ok(Semaphore),
            "Session" => Ok(Session),
            "SymbolicLink" => Ok(SymbolicLink),
            "Thread" => Ok(Thread),
            "ThreadStateChange" => Ok(ThreadStateChange),
            "Timer" => Ok(Timer),
            "TmEn" => Ok(TmEn),
            "TmRm" => Ok(TmRm),
            "TmTm" => Ok(TmTm),
            "TmTx" => Ok(TmTx),
            "Token" => Ok(Token),
            "TpWorkerFactory" => Ok(TpWorkerFactory),
            "Type" => Ok(Type),
            "UserApcReserve" => Ok(UserApcReserve),
            "WaitCompletionPacket" => Ok(WaitCompletionPacket),
            "WindowStation" => Ok(WindowStation),
            "WmiGuid" => Ok(WmiGuid),
            _ => Err(ParseObjectTypeError),
        }
    }
}

/// Represents a specific kind of Windows object.
pub enum WindowsObjectKind<'a, Driver>
where
    Driver: VmiRead,
    Driver::Architecture: ArchAdapter<Driver>,
{
    /// A directory object (`_OBJECT_DIRECTORY`).
    Directory(WindowsDirectoryObject<'a, Driver>),

    /// A file object (`_FILE_OBJECT`).
    File(WindowsFileObject<'a, Driver>),

    /// A registry key object (`_CM_KEY_BODY`).
    Key(WindowsKey<'a, Driver>),

    /// A process object (`_EPROCESS`).
    Process(WindowsProcess<'a, Driver>),

    /// A section object (`_SECTION_OBJECT`).
    Section(WindowsSectionObject<'a, Driver>),

    /// A thread object (`_ETHREAD`).
    Thread(WindowsThread<'a, Driver>),

    /// A token object (`_TOKEN`).
    Token(WindowsToken<'a, Driver>),

    /// An object type object (`_OBJECT_TYPE`).
    Type(WindowsObjectType<'a, Driver>),
}