wdext 0.1.0

A DbgEng wrapper framework
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
// SPDX-FileCopyrightText: 2026 takubokudori
// SPDX-License-Identifier: MIT OR Apache-2.0
#![allow(non_snake_case, clippy::missing_safety_doc)]

use crate::ttd::raw::bindings::*;
use core::{ffi::c_void, mem::MaybeUninit};
use windows_core::GUID;

/// Native TTD interface.
///
/// Unlike [`windows_core::Interface`], these interfaces are not COM objects:
/// they do not provide `IUnknown`, `QueryInterface`, `AddRef`, or `Release`.
///
/// # Safety
///
/// Implementors must associate the correct IID with the exact native vtable
/// layout represented by the implementing type.
pub(crate) unsafe trait TtdTargetInterface: Sized {
    const IID: GUID;

    /// Wraps a non-null interface pointer returned by TTD.
    ///
    /// # Safety
    ///
    /// `raw` must point to the native interface identified by [`Self::IID`]
    /// and must remain valid for every use of the returned wrapper.
    unsafe fn from_target_raw(raw: *mut c_void) -> Self;
}

unsafe impl TtdTargetInterface for ICursorView {
    const IID: GUID = IID_ICURSOR_VIEW;

    #[inline]
    unsafe fn from_target_raw(raw: *mut c_void) -> Self { Self(raw) }
}

unsafe impl TtdTargetInterface for IReplayEngineView {
    const IID: GUID = IID_IREPLAY_ENGINE_VIEW;

    #[inline]
    unsafe fn from_target_raw(raw: *mut c_void) -> Self { Self(raw) }
}

macro_rules! impl_view_traits {
    ($ty:ty) => {
        impl core::fmt::Debug for $ty {
            fn fmt(
                &self,
                f: &mut core::fmt::Formatter<'_>,
            ) -> core::fmt::Result {
                f.debug_tuple(stringify!($ty)).field(&self.0).finish()
            }
        }
        impl PartialEq for $ty {
            #[inline]
            fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
        }
        impl Eq for $ty {}
    };
}

impl_view_traits!(ICursorView);
impl_view_traits!(IReplayEngineView);

impl IThreadView {
    pub unsafe fn from_raw(raw: *const c_void) -> Option<Self> {
        if raw.is_null() {
            None
        } else {
            Some(Self(raw as *mut c_void))
        }
    }

    #[inline]
    unsafe fn vtable(&self) -> &IThreadView_Vtbl {
        unsafe { &**(self.0 as *const *const IThreadView_Vtbl) }
    }
    #[inline]
    fn as_raw(&self) -> *mut c_void { self.0 }

    pub unsafe fn GetThreadInfo(&self) -> &ThreadInfo {
        unsafe { &*(self.vtable().GetThreadInfo)(self.as_raw()) }
    }
    pub unsafe fn GetTebAddress(&self) -> GuestAddress {
        unsafe { (self.vtable().GetTebAddress)(self.as_raw()) }
    }
    pub unsafe fn GetPosition(&self) -> &Position {
        unsafe { &*(self.vtable().GetPosition)(self.as_raw()) }
    }
    pub unsafe fn GetPreviousPosition(&self) -> Position {
        unsafe {
            let mut out = MaybeUninit::uninit();
            (self.vtable().GetPreviousPosition)(
                self.as_raw(),
                out.as_mut_ptr(),
            );
            out.assume_init()
        }
    }
    pub unsafe fn GetProgramCounter(&self) -> GuestAddress {
        unsafe { (self.vtable().GetProgramCounter)(self.as_raw()) }
    }
    pub unsafe fn GetStackPointer(&self) -> GuestAddress {
        unsafe { (self.vtable().GetStackPointer)(self.as_raw()) }
    }
    pub unsafe fn GetFramePointer(&self) -> GuestAddress {
        unsafe { (self.vtable().GetFramePointer)(self.as_raw()) }
    }
    pub unsafe fn GetBasicReturnValue(&self) -> u64 {
        unsafe { (self.vtable().GetBasicReturnValue)(self.as_raw()) }
    }
    pub unsafe fn GetCrossPlatformContext(&self) -> RegisterContext {
        unsafe {
            let mut out = MaybeUninit::uninit();
            (self.vtable().GetCrossPlatformContext)(
                self.as_raw(),
                out.as_mut_ptr(),
            );
            out.assume_init()
        }
    }
    pub unsafe fn GetAvxExtendedContext(&self) -> ExtendedRegisterContext {
        unsafe {
            let mut out = MaybeUninit::uninit();
            (self.vtable().GetAvxExtendedContext)(
                self.as_raw(),
                out.as_mut_ptr(),
            );
            out.assume_init()
        }
    }
    pub unsafe fn QueryMemoryRange(
        &self,
        address: GuestAddress,
    ) -> MemoryRange {
        unsafe {
            let mut out = MaybeUninit::uninit();
            (self.vtable().QueryMemoryRange)(
                self.as_raw(),
                out.as_mut_ptr(),
                address,
            );
            out.assume_init()
        }
    }
    pub unsafe fn QueryMemoryBuffer(
        &self,
        address: GuestAddress,
        buffer: BufferView,
    ) -> MemoryBuffer {
        unsafe {
            let mut out = MaybeUninit::uninit();
            #[cfg(target_arch = "x86")]
            (self.vtable().QueryMemoryBuffer)(
                self.as_raw(),
                out.as_mut_ptr(),
                address,
                buffer,
            );
            #[cfg(target_arch = "x86_64")]
            (self.vtable().QueryMemoryBuffer)(
                self.as_raw(),
                out.as_mut_ptr(),
                address,
                &buffer,
            );
            out.assume_init()
        }
    }
    pub unsafe fn QueryMemoryBufferWithRanges(
        &self,
        address: GuestAddress,
        buffer: BufferView,
        ranges: &mut [MemoryRange],
    ) -> MemoryBufferWithRanges {
        unsafe {
            let mut out = MaybeUninit::uninit();
            #[cfg(target_arch = "x86")]
            (self.vtable().QueryMemoryBufferWithRanges)(
                self.as_raw(),
                out.as_mut_ptr(),
                address,
                buffer,
                ranges.len(),
                ranges.as_mut_ptr(),
            );
            #[cfg(target_arch = "x86_64")]
            (self.vtable().QueryMemoryBufferWithRanges)(
                self.as_raw(),
                out.as_mut_ptr(),
                address,
                &buffer,
                ranges.len(),
                ranges.as_mut_ptr(),
            );
            out.assume_init()
        }
    }
}

impl ICursorView {
    #[inline]
    unsafe fn vtable(&self) -> &ICursorView_Vtbl {
        unsafe { &**(self.0 as *const *const ICursorView_Vtbl) }
    }

    #[inline]
    fn as_raw(&self) -> *mut c_void { self.0 }

    pub unsafe fn QueryMemoryRange(
        &self,
        address: GuestAddress,
        policy: QueryMemoryPolicy,
    ) -> MemoryRange {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            (self.vtable().QueryMemoryRange)(
                self.as_raw(),
                result__.as_mut_ptr(),
                address,
                policy,
            );
            result__.assume_init()
        }
    }
    pub unsafe fn QueryMemoryBuffer(
        &self,
        address: GuestAddress,
        buffer: BufferView,
        policy: QueryMemoryPolicy,
    ) -> MemoryBuffer {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            #[cfg(target_arch = "x86")]
            (self.vtable().QueryMemoryBuffer)(
                self.as_raw(),
                result__.as_mut_ptr(),
                address,
                buffer,
                policy,
            );
            #[cfg(target_arch = "x86_64")]
            (self.vtable().QueryMemoryBuffer)(
                self.as_raw(),
                result__.as_mut_ptr(),
                address,
                &buffer,
                policy,
            );
            result__.assume_init()
        }
    }
    pub unsafe fn QueryMemoryBufferWithRanges(
        &self,
        address: GuestAddress,
        buffer: BufferView,
        ranges: &mut [MemoryRange],
        policy: QueryMemoryPolicy,
    ) -> MemoryBufferWithRanges {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            #[cfg(target_arch = "x86")]
            (self.vtable().QueryMemoryBufferWithRanges)(
                self.as_raw(),
                result__.as_mut_ptr(),
                address,
                buffer,
                ranges.len(),
                ranges.as_mut_ptr(),
                policy,
            );
            #[cfg(target_arch = "x86_64")]
            (self.vtable().QueryMemoryBufferWithRanges)(
                self.as_raw(),
                result__.as_mut_ptr(),
                address,
                &buffer,
                ranges.len(),
                ranges.as_mut_ptr(),
                policy,
            );
            result__.assume_init()
        }
    }
    pub unsafe fn SetDefaultMemoryPolicy(&self, policy: QueryMemoryPolicy) {
        unsafe { (self.vtable().SetDefaultMemoryPolicy)(self.as_raw(), policy) }
    }
    pub unsafe fn GetDefaultMemoryPolicy(&self) -> QueryMemoryPolicy {
        unsafe { (self.vtable().GetDefaultMemoryPolicy)(self.as_raw()) }
    }
    pub unsafe fn UnsafeGetReplayEngine(
        &self,
        iid: &windows::core::GUID,
    ) -> *mut c_void {
        unsafe { (self.vtable().UnsafeGetReplayEngine)(self.as_raw(), iid) }
    }
    pub unsafe fn UnsafeAsInterface(
        &self,
        iid: &windows::core::GUID,
    ) -> *mut c_void {
        unsafe { (self.vtable().UnsafeAsInterface)(self.as_raw(), iid) }
    }
    pub unsafe fn UnsafeAsInterfaceConst(
        &self,
        iid: &windows::core::GUID,
    ) -> *const c_void {
        unsafe { (self.vtable().UnsafeAsInterfaceConst)(self.as_raw(), iid) }
    }
    pub unsafe fn GetThreadInfo(&self, thread_id: ThreadId) -> &ThreadInfo {
        unsafe { &*(self.vtable().GetThreadInfo)(self.as_raw(), thread_id) }
    }
    pub unsafe fn GetTebAddress(&self, thread_id: ThreadId) -> GuestAddress {
        unsafe { (self.vtable().GetTebAddress)(self.as_raw(), thread_id) }
    }
    pub unsafe fn GetPosition(&self, thread_id: ThreadId) -> &Position {
        unsafe { &*(self.vtable().GetPosition)(self.as_raw(), thread_id) }
    }
    pub unsafe fn GetPreviousPosition(&self, thread_id: ThreadId) -> &Position {
        unsafe {
            &*(self.vtable().GetPreviousPosition)(self.as_raw(), thread_id)
        }
    }
    pub unsafe fn GetProgramCounter(
        &self,
        thread_id: ThreadId,
    ) -> GuestAddress {
        unsafe { (self.vtable().GetProgramCounter)(self.as_raw(), thread_id) }
    }
    pub unsafe fn GetStackPointer(&self, thread_id: ThreadId) -> GuestAddress {
        unsafe { (self.vtable().GetStackPointer)(self.as_raw(), thread_id) }
    }
    pub unsafe fn GetFramePointer(&self, thread_id: ThreadId) -> GuestAddress {
        unsafe { (self.vtable().GetFramePointer)(self.as_raw(), thread_id) }
    }
    pub unsafe fn GetBasicReturnValue(&self, thread_id: ThreadId) -> u64 {
        unsafe { (self.vtable().GetBasicReturnValue)(self.as_raw(), thread_id) }
    }
    pub unsafe fn GetCrossPlatformContext(
        &self,
        thread_id: ThreadId,
    ) -> RegisterContext {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            (self.vtable().GetCrossPlatformContext)(
                self.as_raw(),
                result__.as_mut_ptr(),
                thread_id,
            );
            result__.assume_init()
        }
    }
    pub unsafe fn GetAvxExtendedContext(
        &self,
        thread_id: ThreadId,
    ) -> ExtendedRegisterContext {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            (self.vtable().GetAvxExtendedContext)(
                self.as_raw(),
                result__.as_mut_ptr(),
                thread_id,
            );
            result__.assume_init()
        }
    }
    pub unsafe fn GetModuleCount(&self) -> usize {
        unsafe { (self.vtable().GetModuleCount)(self.as_raw()) }
    }
    pub unsafe fn GetModuleList(&self) -> *const ModuleInstance {
        unsafe { (self.vtable().GetModuleList)(self.as_raw()) }
    }
    pub unsafe fn GetThreadCount(&self) -> usize {
        unsafe { (self.vtable().GetThreadCount)(self.as_raw()) }
    }
    pub unsafe fn GetThreadList(&self) -> *const ActiveThreadInfo {
        unsafe { (self.vtable().GetThreadList)(self.as_raw()) }
    }
    pub unsafe fn SetEventMask(&self, mask: EventMask) {
        unsafe { (self.vtable().SetEventMask)(self.as_raw(), mask) }
    }
    pub unsafe fn GetEventMask(&self) -> EventMask {
        unsafe { (self.vtable().GetEventMask)(self.as_raw()) }
    }
    pub unsafe fn SetGapKindMask(&self, mask: GapKindMask) {
        unsafe { (self.vtable().SetGapKindMask)(self.as_raw(), mask) }
    }
    pub unsafe fn GetGapKindMask(&self) -> GapKindMask {
        unsafe { (self.vtable().GetGapKindMask)(self.as_raw()) }
    }
    pub unsafe fn SetGapEventMask(&self, mask: GapEventMask) {
        unsafe { (self.vtable().SetGapEventMask)(self.as_raw(), mask) }
    }
    pub unsafe fn GetGapEventMask(&self) -> GapEventMask {
        unsafe { (self.vtable().GetGapEventMask)(self.as_raw()) }
    }
    pub unsafe fn SetExceptionMask(&self, mask: ExceptionMask) {
        unsafe { (self.vtable().SetExceptionMask)(self.as_raw(), mask) }
    }
    pub unsafe fn GetExceptionMask(&self) -> ExceptionMask {
        unsafe { (self.vtable().GetExceptionMask)(self.as_raw()) }
    }
    pub unsafe fn SetReplayFlags(&self, flags: ReplayFlags) {
        unsafe { (self.vtable().SetReplayFlags)(self.as_raw(), flags) }
    }
    pub unsafe fn GetReplayFlags(&self) -> ReplayFlags {
        unsafe { (self.vtable().GetReplayFlags)(self.as_raw()) }
    }
    pub unsafe fn AddMemoryWatchpoint(
        &self,
        data: &MemoryWatchpointData,
    ) -> bool {
        unsafe { (self.vtable().AddMemoryWatchpoint)(self.as_raw(), data) != 0 }
    }
    pub unsafe fn RemoveMemoryWatchpoint(
        &self,
        data: &MemoryWatchpointData,
    ) -> bool {
        unsafe {
            (self.vtable().RemoveMemoryWatchpoint)(self.as_raw(), data) != 0
        }
    }
    pub unsafe fn AddPositionWatchpoint(
        &self,
        data: &PositionWatchpointData,
    ) -> bool {
        unsafe {
            (self.vtable().AddPositionWatchpoint)(self.as_raw(), data) != 0
        }
    }
    pub unsafe fn RemovePositionWatchpoint(
        &self,
        data: &PositionWatchpointData,
    ) -> bool {
        unsafe {
            (self.vtable().RemovePositionWatchpoint)(self.as_raw(), data) != 0
        }
    }
    pub unsafe fn Clear(&self) {
        unsafe { (self.vtable().Clear)(self.as_raw()) }
    }
    pub unsafe fn SetPosition(&self, position: Position) {
        unsafe { (self.vtable().SetPosition)(self.as_raw(), &position) }
    }
    pub unsafe fn SetPositionOnThread(
        &self,
        thread_id: UniqueThreadId,
        position: Position,
    ) {
        unsafe {
            (self.vtable().SetPositionOnThread)(
                self.as_raw(),
                thread_id,
                &position,
            )
        }
    }
    pub unsafe fn SetMemoryWatchpointCallback(
        &self,
        callback: MemoryWatchpointCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetMemoryWatchpointCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetPositionWatchpointCallback(
        &self,
        callback: PositionWatchpointCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetPositionWatchpointCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetGapEventCallback(
        &self,
        callback: GapEventCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetGapEventCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetThreadContinuityBreakCallback(
        &self,
        callback: ThreadContinuityBreakCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetThreadContinuityBreakCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetReplayProgressCallback(
        &self,
        callback: ReplayProgressCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetReplayProgressCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetFallbackCallback(
        &self,
        callback: FallbackCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetFallbackCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetCallReturnCallback(
        &self,
        callback: CallReturnCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetCallReturnCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetIndirectJumpCallback(
        &self,
        callback: IndirectJumpCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetIndirectJumpCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn SetRegisterChangedCallback(
        &self,
        callback: RegisterChangedCallback,
        context: usize,
    ) {
        unsafe {
            (self.vtable().SetRegisterChangedCallback)(
                self.as_raw(),
                callback,
                context,
            )
        }
    }
    pub unsafe fn ReplayForward(
        &self,
        limit: Position,
        step_count: StepCount,
    ) -> ReplayResult {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            #[cfg(target_arch = "x86")]
            (self.vtable().ReplayForward)(
                self.as_raw(),
                result__.as_mut_ptr(),
                limit,
                step_count,
            );
            #[cfg(target_arch = "x86_64")]
            (self.vtable().ReplayForward)(
                self.as_raw(),
                result__.as_mut_ptr(),
                &limit,
                step_count,
            );
            result__.assume_init()
        }
    }
    pub unsafe fn ReplayBackward(
        &self,
        limit: Position,
        step_count: StepCount,
    ) -> ReplayResult {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            #[cfg(target_arch = "x86")]
            (self.vtable().ReplayBackward)(
                self.as_raw(),
                result__.as_mut_ptr(),
                limit,
                step_count,
            );
            #[cfg(target_arch = "x86_64")]
            (self.vtable().ReplayBackward)(
                self.as_raw(),
                result__.as_mut_ptr(),
                &limit,
                step_count,
            );
            result__.assume_init()
        }
    }
    pub unsafe fn InterruptReplay(&self) {
        unsafe { (self.vtable().InterruptReplay)(self.as_raw()) }
    }
    pub unsafe fn GetInternals(&self) -> *mut ICursorInternals {
        unsafe { (self.vtable().GetInternals)(self.as_raw()) }
    }
    pub unsafe fn GetInternalsConst(&self) -> *const ICursorInternals {
        unsafe { (self.vtable().GetInternalsConst)(self.as_raw()) }
    }
    pub unsafe fn GetInternalData(
        &self,
        id: InternalDataId,
        buffer: *mut c_void,
        buffer_size_in_bytes: usize,
    ) -> usize {
        unsafe {
            (self.vtable().GetInternalData)(
                self.as_raw(),
                id,
                buffer,
                buffer_size_in_bytes,
            )
        }
    }
}

impl ICursor {
    #[inline]
    unsafe fn vtable(&self) -> &ICursor_Vtbl {
        unsafe { &**(self.0 as *const *const ICursor_Vtbl) }
    }
    #[inline]
    pub fn as_raw(&self) -> *mut c_void { self.0 }
    #[inline]
    pub unsafe fn as_view(&self) -> &ICursorView {
        unsafe { &*(self as *const ICursor as *const ICursorView) }
    }
    #[inline]
    pub unsafe fn as_view_mut(&mut self) -> &mut ICursorView {
        unsafe { &mut *(self as *mut ICursor as *mut ICursorView) }
    }
    pub unsafe fn Destroy(&self) { unsafe { (self.vtable().Destroy)(self.0) } }
}

impl IReplayEngineView {
    #[inline]
    unsafe fn vtable(&self) -> &IReplayEngineView_Vtbl {
        unsafe { &**(self.0 as *const *const IReplayEngineView_Vtbl) }
    }

    #[inline]
    fn as_raw(&self) -> *mut c_void { self.0 }

    pub unsafe fn UnsafeAsInterface(
        &self,
        iid: &windows::core::GUID,
    ) -> *mut c_void {
        unsafe { (self.vtable().UnsafeAsInterface)(self.as_raw(), iid) }
    }
    pub unsafe fn UnsafeAsInterfaceConst(
        &self,
        iid: &windows::core::GUID,
    ) -> *const c_void {
        unsafe { (self.vtable().UnsafeAsInterfaceConst)(self.as_raw(), iid) }
    }
    pub unsafe fn GetPebAddress(&self) -> GuestAddress {
        unsafe { (self.vtable().GetPebAddress)(self.as_raw()) }
    }
    pub unsafe fn GetSystemInfo(&self) -> &SystemInfo {
        unsafe { &*(self.vtable().GetSystemInfo)(self.as_raw()) }
    }
    pub unsafe fn GetFirstPosition(&self) -> &Position {
        unsafe { &*(self.vtable().GetFirstPosition)(self.as_raw()) }
    }
    pub unsafe fn GetLastPosition(&self) -> &Position {
        unsafe { &*(self.vtable().GetLastPosition)(self.as_raw()) }
    }
    pub unsafe fn GetLifetime(&self) -> &PositionRange {
        unsafe { &*(self.vtable().GetLifetime)(self.as_raw()) }
    }
    pub unsafe fn GetRecordingType(&self) -> RecordingType {
        unsafe { (self.vtable().GetRecordingType)(self.as_raw()) }
    }
    pub unsafe fn GetThreadInfo(
        &self,
        unique_thread_id: UniqueThreadId,
    ) -> &ThreadInfo {
        unsafe {
            &*(self.vtable().GetThreadInfo)(self.as_raw(), unique_thread_id)
        }
    }
    pub unsafe fn GetThreadCount(&self) -> usize {
        unsafe { (self.vtable().GetThreadCount)(self.as_raw()) }
    }
    pub unsafe fn GetThreadList(&self) -> *const ThreadInfo {
        unsafe { (self.vtable().GetThreadList)(self.as_raw()) }
    }
    pub unsafe fn GetThreadFirstPositionIndex(&self) -> *const usize {
        unsafe { (self.vtable().GetThreadFirstPositionIndex)(self.as_raw()) }
    }
    pub unsafe fn GetThreadLastPositionIndex(&self) -> *const usize {
        unsafe { (self.vtable().GetThreadLastPositionIndex)(self.as_raw()) }
    }
    pub unsafe fn GetThreadLifetimeFirstPositionIndex(&self) -> *const usize {
        unsafe {
            (self.vtable().GetThreadLifetimeFirstPositionIndex)(self.as_raw())
        }
    }
    pub unsafe fn GetThreadLifetimeLastPositionIndex(&self) -> *const usize {
        unsafe {
            (self.vtable().GetThreadLifetimeLastPositionIndex)(self.as_raw())
        }
    }
    pub unsafe fn GetThreadCreatedEventCount(&self) -> usize {
        unsafe { (self.vtable().GetThreadCreatedEventCount)(self.as_raw()) }
    }
    pub unsafe fn GetThreadCreatedEventList(
        &self,
    ) -> *const ThreadCreatedEvent {
        unsafe { (self.vtable().GetThreadCreatedEventList)(self.as_raw()) }
    }
    pub unsafe fn GetThreadTerminatedEventCount(&self) -> usize {
        unsafe { (self.vtable().GetThreadTerminatedEventCount)(self.as_raw()) }
    }
    pub unsafe fn GetThreadTerminatedEventList(
        &self,
    ) -> *const ThreadTerminatedEvent {
        unsafe { (self.vtable().GetThreadTerminatedEventList)(self.as_raw()) }
    }
    pub unsafe fn GetModuleCount(&self) -> usize {
        unsafe { (self.vtable().GetModuleCount)(self.as_raw()) }
    }
    pub unsafe fn GetModuleList(&self) -> *const Module {
        unsafe { (self.vtable().GetModuleList)(self.as_raw()) }
    }
    pub unsafe fn GetModuleInstanceCount(&self) -> usize {
        unsafe { (self.vtable().GetModuleInstanceCount)(self.as_raw()) }
    }
    pub unsafe fn GetModuleInstanceList(&self) -> *const ModuleInstance {
        unsafe { (self.vtable().GetModuleInstanceList)(self.as_raw()) }
    }
    pub unsafe fn GetModuleInstanceUnloadIndex(&self) -> *const usize {
        unsafe { (self.vtable().GetModuleInstanceUnloadIndex)(self.as_raw()) }
    }
    pub unsafe fn GetModuleLoadedEventCount(&self) -> usize {
        unsafe { (self.vtable().GetModuleLoadedEventCount)(self.as_raw()) }
    }
    pub unsafe fn GetModuleLoadedEventList(&self) -> *const ModuleLoadedEvent {
        unsafe { (self.vtable().GetModuleLoadedEventList)(self.as_raw()) }
    }
    pub unsafe fn GetModuleUnloadedEventCount(&self) -> usize {
        unsafe { (self.vtable().GetModuleUnloadedEventCount)(self.as_raw()) }
    }
    pub unsafe fn GetModuleUnloadedEventList(
        &self,
    ) -> *const ModuleUnloadedEvent {
        unsafe { (self.vtable().GetModuleUnloadedEventList)(self.as_raw()) }
    }
    pub unsafe fn GetExceptionEventCount(&self) -> usize {
        unsafe { (self.vtable().GetExceptionEventCount)(self.as_raw()) }
    }
    pub unsafe fn GetExceptionEventList(&self) -> *const ExceptionEvent {
        unsafe { (self.vtable().GetExceptionEventList)(self.as_raw()) }
    }
    pub unsafe fn GetExceptionAtOrAfterPosition(
        &self,
        position: Position,
    ) -> *const ExceptionEvent {
        unsafe {
            (self.vtable().GetExceptionAtOrAfterPosition)(
                self.as_raw(),
                &position,
            )
        }
    }
    pub unsafe fn GetKeyframeCount(&self) -> usize {
        unsafe { (self.vtable().GetKeyframeCount)(self.as_raw()) }
    }
    pub unsafe fn GetKeyframeList(&self) -> *const Position {
        unsafe { (self.vtable().GetKeyframeList)(self.as_raw()) }
    }
    pub unsafe fn GetRecordClientCount(&self) -> usize {
        unsafe { (self.vtable().GetRecordClientCount)(self.as_raw()) }
    }
    pub unsafe fn GetRecordClientList(&self) -> *const RecordClient {
        unsafe { (self.vtable().GetRecordClientList)(self.as_raw()) }
    }
    pub unsafe fn GetRecordClient(
        &self,
        id: RecordClientId,
    ) -> *const RecordClient {
        unsafe { (self.vtable().GetRecordClient)(self.as_raw(), id) }
    }
    pub unsafe fn GetCustomEventCount(&self) -> usize {
        unsafe { (self.vtable().GetCustomEventCount)(self.as_raw()) }
    }
    pub unsafe fn GetCustomEventList(&self) -> *const CustomEvent {
        unsafe { (self.vtable().GetCustomEventList)(self.as_raw()) }
    }
    pub unsafe fn GetActivityCount(&self) -> usize {
        unsafe { (self.vtable().GetActivityCount)(self.as_raw()) }
    }
    pub unsafe fn GetActivityList(&self) -> *const Activity {
        unsafe { (self.vtable().GetActivityList)(self.as_raw()) }
    }
    pub unsafe fn GetIslandCount(&self) -> usize {
        unsafe { (self.vtable().GetIslandCount)(self.as_raw()) }
    }
    pub unsafe fn GetIslandList(&self) -> *const Island {
        unsafe { (self.vtable().GetIslandList)(self.as_raw()) }
    }
    pub unsafe fn NewCursor(&self) -> *mut ICursor {
        unsafe { (self.vtable().NewCursor)(self.as_raw(), &IID_ICURSOR_VIEW) }
    }
    pub unsafe fn BuildIndex(
        &self,
        report_progress: IndexBuildProgressCallback,
        caller_context: *const c_void,
        flags: IndexBuildFlags,
    ) -> IndexStatus {
        unsafe {
            (self.vtable().BuildIndex)(
                self.as_raw(),
                report_progress,
                caller_context,
                flags,
            )
        }
    }
    pub unsafe fn GetIndexStatus(&self) -> IndexStatus {
        unsafe { (self.vtable().GetIndexStatus)(self.as_raw()) }
    }
    pub unsafe fn GetIndexFileStats(&self) -> IndexFileStats {
        unsafe {
            let mut result__ = MaybeUninit::uninit();
            (self.vtable().GetIndexFileStats)(
                self.as_raw(),
                result__.as_mut_ptr(),
            );
            result__.assume_init()
        }
    }
    pub unsafe fn RegisterDebugModeAndLogging(
        &self,
        debug_mode: DebugModeType,
        error_reporting: *mut ErrorReporting,
    ) {
        unsafe {
            (self.vtable().RegisterDebugModeAndLogging)(
                self.as_raw(),
                debug_mode,
                error_reporting,
            )
        }
    }
    pub unsafe fn GetInternals(&self) -> *mut IEngineInternals {
        unsafe { (self.vtable().GetInternals)(self.as_raw()) }
    }
    pub unsafe fn GetInternalsConst(&self) -> *const IEngineInternals {
        unsafe { (self.vtable().GetInternalsConst)(self.as_raw()) }
    }
}