forked from gentilkiwi/mimikatz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DbgHelp.h
4594 lines (3978 loc) · 126 KB
/
DbgHelp.h
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
/*++ BUILD Version: 0000 Increment this if a change has global effects
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
dbghelp.h
Abstract:
This module defines the prototypes and constants required for the image
help routines.
Contains debugging support routines that are redistributable.
Revision History:
--*/
#ifndef _DBGHELP_
#define _DBGHELP_
#if _MSC_VER > 1020
#pragma once
#endif
// As a general principal always call the 64 bit version
// of every API, if a choice exists. The 64 bit version
// works great on 32 bit platforms, and is forward
// compatible to 64 bit platforms.
#ifdef _WIN64
#ifndef _IMAGEHLP64
#define _IMAGEHLP64
#endif
#endif
#include <pshpack8.h>
// For those without specstrings.h
// Since there are different versions of this header, I need to
// individually test each item and define it if it is not around.
#ifndef __in
#define __in
#endif
#ifndef __out
#define __out
#endif
#ifndef __inout
#define __inout
#endif
#ifndef __in_opt
#define __in_opt
#endif
#ifndef __out_opt
#define __out_opt
#endif
#ifndef __inout_opt
#define __inout_opt
#endif
#ifndef __in_ecount
#define __in_ecount(x)
#endif
#ifndef __out_ecount
#define __out_ecount(x)
#endif
#ifndef __inout_ecount
#define __inout_ecount(x)
#endif
#ifndef __in_bcount
#define __in_bcount(x)
#endif
#ifndef __out_bcount
#define __out_bcount(x)
#endif
#ifndef __inout_bcount
#define __inout_bcount(x)
#endif
#ifndef __out_xcount
#define __out_xcount(x)
#endif
#ifndef __deref_opt_out
#define __deref_opt_out
#endif
#ifndef __deref_out
#define __deref_out
#endif
#ifndef __out_ecount_opt
#define __out_ecount_opt(x)
#endif
#ifndef __in_bcount_opt
#define __in_bcount_opt(x)
#endif
#ifndef __out_bcount_opt
#define __out_bcount_opt(x)
#endif
#ifndef __deref_out_opt
#define __deref_out_opt
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _IMAGEHLP_SOURCE_
#define IMAGEAPI __stdcall
#define DBHLP_DEPRECIATED
#else
#define IMAGEAPI DECLSPEC_IMPORT __stdcall
#if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
#define DBHLP_DEPRECIATED __declspec(deprecated)
#else
#define DBHLP_DEPRECIATED
#endif
#endif
#define DBHLPAPI IMAGEAPI
#define IMAGE_SEPARATION (64*1024)
// Observant readers may notice that 2 new fields,
// 'fReadOnly' and 'Version' have been added to
// the LOADED_IMAGE structure after 'fDOSImage'.
// This does not change the size of the structure
// from previous headers. That is because while
// 'fDOSImage' is a byte, it is padded by the
// compiler to 4 bytes. So the 2 new fields are
// slipped into the extra space.
typedef struct _LOADED_IMAGE {
PSTR ModuleName;
HANDLE hFile;
PUCHAR MappedAddress;
#ifdef _IMAGEHLP64
PIMAGE_NT_HEADERS64 FileHeader;
#else
PIMAGE_NT_HEADERS32 FileHeader;
#endif
PIMAGE_SECTION_HEADER LastRvaSection;
ULONG NumberOfSections;
PIMAGE_SECTION_HEADER Sections;
ULONG Characteristics;
BOOLEAN fSystemImage;
BOOLEAN fDOSImage;
BOOLEAN fReadOnly;
UCHAR Version;
LIST_ENTRY Links;
ULONG SizeOfImage;
} LOADED_IMAGE, *PLOADED_IMAGE;
#define MAX_SYM_NAME 2000
// Error codes set by dbghelp functions. Call GetLastError
// to see them.
// Dbghelp also sets error codes found in winerror.h
#define ERROR_IMAGE_NOT_STRIPPED 0x8800 // the image is not stripped. No dbg file available.
#define ERROR_NO_DBG_POINTER 0x8801 // image is stripped but there is no pointer to a dbg file
#define ERROR_NO_PDB_POINTER 0x8802 // image does not point to a pdb file
typedef BOOL
(CALLBACK *PFIND_DEBUG_FILE_CALLBACK)(
__in HANDLE FileHandle,
__in PCSTR FileName,
__in PVOID CallerData
);
HANDLE
IMAGEAPI
SymFindDebugInfoFile(
__in HANDLE hProcess,
__in PCSTR FileName,
__out_ecount(MAX_PATH + 1) PSTR DebugFilePath,
__in_opt PFIND_DEBUG_FILE_CALLBACK Callback,
__in_opt PVOID CallerData
);
typedef BOOL
(CALLBACK *PFIND_DEBUG_FILE_CALLBACKW)(
__in HANDLE FileHandle,
__in PCWSTR FileName,
__in PVOID CallerData
);
HANDLE
IMAGEAPI
SymFindDebugInfoFileW(
__in HANDLE hProcess,
__in PCWSTR FileName,
__out_ecount(MAX_PATH + 1) PWSTR DebugFilePath,
__in_opt PFIND_DEBUG_FILE_CALLBACKW Callback,
__in_opt PVOID CallerData
);
HANDLE
IMAGEAPI
FindDebugInfoFile (
__in PCSTR FileName,
__in PCSTR SymbolPath,
__out_ecount(MAX_PATH + 1) PSTR DebugFilePath
);
HANDLE
IMAGEAPI
FindDebugInfoFileEx (
__in PCSTR FileName,
__in PCSTR SymbolPath,
__out_ecount(MAX_PATH + 1) PSTR DebugFilePath,
__in_opt PFIND_DEBUG_FILE_CALLBACK Callback,
__in_opt PVOID CallerData
);
HANDLE
IMAGEAPI
FindDebugInfoFileExW (
__in PCWSTR FileName,
__in PCWSTR SymbolPath,
__out_ecount(MAX_PATH + 1) PWSTR DebugFilePath,
__in_opt PFIND_DEBUG_FILE_CALLBACKW Callback,
__in_opt PVOID CallerData
);
typedef BOOL
(CALLBACK *PFINDFILEINPATHCALLBACK)(
__in PCSTR filename,
__in PVOID context
);
BOOL
IMAGEAPI
SymFindFileInPath(
__in HANDLE hprocess,
__in_opt PCSTR SearchPath,
__in PCSTR FileName,
__in_opt PVOID id,
__in DWORD two,
__in DWORD three,
__in DWORD flags,
__out_ecount(MAX_PATH + 1) PSTR FoundFile,
__in_opt PFINDFILEINPATHCALLBACK callback,
__in_opt PVOID context
);
typedef BOOL
(CALLBACK *PFINDFILEINPATHCALLBACKW)(
__in PCWSTR filename,
__in PVOID context
);
BOOL
IMAGEAPI
SymFindFileInPathW(
__in HANDLE hprocess,
__in_opt PCWSTR SearchPath,
__in PCWSTR FileName,
__in_opt PVOID id,
__in DWORD two,
__in DWORD three,
__in DWORD flags,
__out_ecount(MAX_PATH + 1) PWSTR FoundFile,
__in_opt PFINDFILEINPATHCALLBACKW callback,
__in_opt PVOID context
);
typedef BOOL
(CALLBACK *PFIND_EXE_FILE_CALLBACK)(
__in HANDLE FileHandle,
__in PCSTR FileName,
__in_opt PVOID CallerData
);
HANDLE
IMAGEAPI
SymFindExecutableImage(
__in HANDLE hProcess,
__in PCSTR FileName,
__out_ecount(MAX_PATH + 1) PSTR ImageFilePath,
__in PFIND_EXE_FILE_CALLBACK Callback,
__in PVOID CallerData
);
typedef BOOL
(CALLBACK *PFIND_EXE_FILE_CALLBACKW)(
__in HANDLE FileHandle,
__in PCWSTR FileName,
__in_opt PVOID CallerData
);
HANDLE
IMAGEAPI
SymFindExecutableImageW(
__in HANDLE hProcess,
__in PCWSTR FileName,
__out_ecount(MAX_PATH + 1) PWSTR ImageFilePath,
__in PFIND_EXE_FILE_CALLBACKW Callback,
__in PVOID CallerData
);
HANDLE
IMAGEAPI
FindExecutableImage(
__in PCSTR FileName,
__in PCSTR SymbolPath,
__out_ecount(MAX_PATH + 1) PSTR ImageFilePath
);
HANDLE
IMAGEAPI
FindExecutableImageEx(
__in PCSTR FileName,
__in PCSTR SymbolPath,
__out_ecount(MAX_PATH + 1) PSTR ImageFilePath,
__in_opt PFIND_EXE_FILE_CALLBACK Callback,
__in_opt PVOID CallerData
);
HANDLE
IMAGEAPI
FindExecutableImageExW(
__in PCWSTR FileName,
__in PCWSTR SymbolPath,
__out_ecount(MAX_PATH + 1) PWSTR ImageFilePath,
__in_opt PFIND_EXE_FILE_CALLBACKW Callback,
__in PVOID CallerData
);
PIMAGE_NT_HEADERS
IMAGEAPI
ImageNtHeader (
__in PVOID Base
);
PVOID
IMAGEAPI
ImageDirectoryEntryToDataEx (
__in PVOID Base,
__in BOOLEAN MappedAsImage,
__in USHORT DirectoryEntry,
__out PULONG Size,
__out_opt PIMAGE_SECTION_HEADER *FoundHeader
);
PVOID
IMAGEAPI
ImageDirectoryEntryToData (
__in PVOID Base,
__in BOOLEAN MappedAsImage,
__in USHORT DirectoryEntry,
__out PULONG Size
);
PIMAGE_SECTION_HEADER
IMAGEAPI
ImageRvaToSection(
__in PIMAGE_NT_HEADERS NtHeaders,
__in PVOID Base,
__in ULONG Rva
);
PVOID
IMAGEAPI
ImageRvaToVa(
__in PIMAGE_NT_HEADERS NtHeaders,
__in PVOID Base,
__in ULONG Rva,
__in_opt OUT PIMAGE_SECTION_HEADER *LastRvaSection
);
#ifndef _WIN64
// This api won't be ported to Win64 - Fix your code.
typedef struct _IMAGE_DEBUG_INFORMATION {
LIST_ENTRY List;
DWORD ReservedSize;
PVOID ReservedMappedBase;
USHORT ReservedMachine;
USHORT ReservedCharacteristics;
DWORD ReservedCheckSum;
DWORD ImageBase;
DWORD SizeOfImage;
DWORD ReservedNumberOfSections;
PIMAGE_SECTION_HEADER ReservedSections;
DWORD ReservedExportedNamesSize;
PSTR ReservedExportedNames;
DWORD ReservedNumberOfFunctionTableEntries;
PIMAGE_FUNCTION_ENTRY ReservedFunctionTableEntries;
DWORD ReservedLowestFunctionStartingAddress;
DWORD ReservedHighestFunctionEndingAddress;
DWORD ReservedNumberOfFpoTableEntries;
PFPO_DATA ReservedFpoTableEntries;
DWORD SizeOfCoffSymbols;
PIMAGE_COFF_SYMBOLS_HEADER CoffSymbols;
DWORD ReservedSizeOfCodeViewSymbols;
PVOID ReservedCodeViewSymbols;
PSTR ImageFilePath;
PSTR ImageFileName;
PSTR ReservedDebugFilePath;
DWORD ReservedTimeDateStamp;
BOOL ReservedRomImage;
PIMAGE_DEBUG_DIRECTORY ReservedDebugDirectory;
DWORD ReservedNumberOfDebugDirectories;
DWORD ReservedOriginalFunctionTableBaseAddress;
DWORD Reserved[ 2 ];
} IMAGE_DEBUG_INFORMATION, *PIMAGE_DEBUG_INFORMATION;
PIMAGE_DEBUG_INFORMATION
IMAGEAPI
MapDebugInformation(
__in_opt HANDLE FileHandle,
__in PCSTR FileName,
__in_opt PCSTR SymbolPath,
__in ULONG ImageBase
);
BOOL
IMAGEAPI
UnmapDebugInformation(
__out_xcount(unknown) PIMAGE_DEBUG_INFORMATION DebugInfo
);
#endif
BOOL
IMAGEAPI
SearchTreeForFile(
__in PCSTR RootPath,
__in PCSTR InputPathName,
__out_ecount(MAX_PATH + 1) PSTR OutputPathBuffer
);
BOOL
IMAGEAPI
SearchTreeForFileW(
__in PCWSTR RootPath,
__in PCWSTR InputPathName,
__out_ecount(MAX_PATH + 1) PWSTR OutputPathBuffer
);
typedef BOOL
(CALLBACK *PENUMDIRTREE_CALLBACK)(
__in PCSTR FilePath,
__in_opt PVOID CallerData
);
BOOL
IMAGEAPI
EnumDirTree(
__in_opt HANDLE hProcess,
__in PCSTR RootPath,
__in PCSTR InputPathName,
__out_ecount_opt(MAX_PATH + 1) PSTR OutputPathBuffer,
__in_opt PENUMDIRTREE_CALLBACK cb,
__in_opt PVOID data
);
typedef BOOL
(CALLBACK *PENUMDIRTREE_CALLBACKW)(
__in PCWSTR FilePath,
__in_opt PVOID CallerData
);
BOOL
IMAGEAPI
EnumDirTreeW(
__in_opt HANDLE hProcess,
__in PCWSTR RootPath,
__in PCWSTR InputPathName,
__out_ecount_opt(MAX_PATH + 1) PWSTR OutputPathBuffer,
__in_opt PENUMDIRTREE_CALLBACKW cb,
__in_opt PVOID data
);
BOOL
IMAGEAPI
MakeSureDirectoryPathExists(
__in PCSTR DirPath
);
//
// UnDecorateSymbolName Flags
//
#define UNDNAME_COMPLETE (0x0000) // Enable full undecoration
#define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) // Remove leading underscores from MS extended keywords
#define UNDNAME_NO_MS_KEYWORDS (0x0002) // Disable expansion of MS extended keywords
#define UNDNAME_NO_FUNCTION_RETURNS (0x0004) // Disable expansion of return type for primary declaration
#define UNDNAME_NO_ALLOCATION_MODEL (0x0008) // Disable expansion of the declaration model
#define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010) // Disable expansion of the declaration language specifier
#define UNDNAME_NO_MS_THISTYPE (0x0020) // NYI Disable expansion of MS keywords on the 'this' type for primary declaration
#define UNDNAME_NO_CV_THISTYPE (0x0040) // NYI Disable expansion of CV modifiers on the 'this' type for primary declaration
#define UNDNAME_NO_THISTYPE (0x0060) // Disable all modifiers on the 'this' type
#define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) // Disable expansion of access specifiers for members
#define UNDNAME_NO_THROW_SIGNATURES (0x0100) // Disable expansion of 'throw-signatures' for functions and pointers to functions
#define UNDNAME_NO_MEMBER_TYPE (0x0200) // Disable expansion of 'static' or 'virtual'ness of members
#define UNDNAME_NO_RETURN_UDT_MODEL (0x0400) // Disable expansion of MS model for UDT returns
#define UNDNAME_32_BIT_DECODE (0x0800) // Undecorate 32-bit decorated names
#define UNDNAME_NAME_ONLY (0x1000) // Crack only the name for primary declaration;
// return just [scope::]name. Does expand template params
#define UNDNAME_NO_ARGUMENTS (0x2000) // Don't undecorate arguments to function
#define UNDNAME_NO_SPECIAL_SYMS (0x4000) // Don't undecorate special names (v-table, vcall, vector xxx, metatype, etc)
DWORD
IMAGEAPI
WINAPI
UnDecorateSymbolName(
__in PCSTR name,
__out_ecount(maxStringLength) PSTR outputString,
__in DWORD maxStringLength,
__in DWORD flags
);
DWORD
IMAGEAPI
WINAPI
UnDecorateSymbolNameW(
__in PCWSTR name,
__out_ecount(maxStringLength) PWSTR outputString,
__in DWORD maxStringLength,
__in DWORD flags
);
//
// these values are used for synthesized file types
// that can be passed in as image headers instead of
// the standard ones from ntimage.h
//
#define DBHHEADER_DEBUGDIRS 0x1
#define DBHHEADER_CVMISC 0x2
#define DBHHEADER_PDBGUID 0x3
typedef struct _MODLOAD_DATA {
DWORD ssize; // size of this struct
DWORD ssig; // signature identifying the passed data
PVOID data; // pointer to passed data
DWORD size; // size of passed data
DWORD flags; // options
} MODLOAD_DATA, *PMODLOAD_DATA;
typedef struct _MODLOAD_CVMISC {
DWORD oCV; // ofset to the codeview record
size_t cCV; // size of the codeview record
DWORD oMisc; // offset to the misc record
size_t cMisc; // size of the misc record
DWORD dtImage; // datetime stamp of the image
DWORD cImage; // size of the image
} MODLOAD_CVMISC, *PMODLOAD_CVMISC;
typedef struct _MODLOAD_PDBGUID_PDBAGE {
GUID PdbGuid; // Pdb Guid
DWORD PdbAge; // Pdb Age
} MODLOAD_PDBGUID_PDBAGE, *PMODLOAD_PDBGUID_PDBAGE;
//
// StackWalking API
//
typedef enum {
AddrMode1616,
AddrMode1632,
AddrModeReal,
AddrModeFlat
} ADDRESS_MODE;
typedef struct _tagADDRESS64 {
DWORD64 Offset;
WORD Segment;
ADDRESS_MODE Mode;
} ADDRESS64, *LPADDRESS64;
#if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
#define ADDRESS ADDRESS64
#define LPADDRESS LPADDRESS64
#else
typedef struct _tagADDRESS {
DWORD Offset;
WORD Segment;
ADDRESS_MODE Mode;
} ADDRESS, *LPADDRESS;
__inline
void
Address32To64(
__in LPADDRESS a32,
__out LPADDRESS64 a64
)
{
a64->Offset = (ULONG64)(LONG64)(LONG)a32->Offset;
a64->Segment = a32->Segment;
a64->Mode = a32->Mode;
}
__inline
void
Address64To32(
__in LPADDRESS64 a64,
__out LPADDRESS a32
)
{
a32->Offset = (ULONG)a64->Offset;
a32->Segment = a64->Segment;
a32->Mode = a64->Mode;
}
#endif
//
// This structure is included in the STACKFRAME structure,
// and is used to trace through usermode callbacks in a thread's
// kernel stack. The values must be copied by the kernel debugger
// from the DBGKD_GET_VERSION and WAIT_STATE_CHANGE packets.
//
//
// New KDHELP structure for 64 bit system support.
// This structure is preferred in new code.
//
typedef struct _KDHELP64 {
//
// address of kernel thread object, as provided in the
// WAIT_STATE_CHANGE packet.
//
DWORD64 Thread;
//
// offset in thread object to pointer to the current callback frame
// in kernel stack.
//
DWORD ThCallbackStack;
//
// offset in thread object to pointer to the current callback backing
// store frame in kernel stack.
//
DWORD ThCallbackBStore;
//
// offsets to values in frame:
//
// address of next callback frame
DWORD NextCallback;
// address of saved frame pointer (if applicable)
DWORD FramePointer;
//
// Address of the kernel function that calls out to user mode
//
DWORD64 KiCallUserMode;
//
// Address of the user mode dispatcher function
//
DWORD64 KeUserCallbackDispatcher;
//
// Lowest kernel mode address
//
DWORD64 SystemRangeStart;
//
// Address of the user mode exception dispatcher function.
// Added in API version 10.
//
DWORD64 KiUserExceptionDispatcher;
//
// Stack bounds, added in API version 11.
//
DWORD64 StackBase;
DWORD64 StackLimit;
DWORD64 Reserved[5];
} KDHELP64, *PKDHELP64;
#if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
#define KDHELP KDHELP64
#define PKDHELP PKDHELP64
#else
typedef struct _KDHELP {
//
// address of kernel thread object, as provided in the
// WAIT_STATE_CHANGE packet.
//
DWORD Thread;
//
// offset in thread object to pointer to the current callback frame
// in kernel stack.
//
DWORD ThCallbackStack;
//
// offsets to values in frame:
//
// address of next callback frame
DWORD NextCallback;
// address of saved frame pointer (if applicable)
DWORD FramePointer;
//
// Address of the kernel function that calls out to user mode
//
DWORD KiCallUserMode;
//
// Address of the user mode dispatcher function
//
DWORD KeUserCallbackDispatcher;
//
// Lowest kernel mode address
//
DWORD SystemRangeStart;
//
// offset in thread object to pointer to the current callback backing
// store frame in kernel stack.
//
DWORD ThCallbackBStore;
//
// Address of the user mode exception dispatcher function.
// Added in API version 10.
//
DWORD KiUserExceptionDispatcher;
//
// Stack bounds, added in API version 11.
//
DWORD StackBase;
DWORD StackLimit;
DWORD Reserved[5];
} KDHELP, *PKDHELP;
__inline
void
KdHelp32To64(
__in PKDHELP p32,
__out PKDHELP64 p64
)
{
p64->Thread = p32->Thread;
p64->ThCallbackStack = p32->ThCallbackStack;
p64->NextCallback = p32->NextCallback;
p64->FramePointer = p32->FramePointer;
p64->KiCallUserMode = p32->KiCallUserMode;
p64->KeUserCallbackDispatcher = p32->KeUserCallbackDispatcher;
p64->SystemRangeStart = p32->SystemRangeStart;
p64->KiUserExceptionDispatcher = p32->KiUserExceptionDispatcher;
p64->StackBase = p32->StackBase;
p64->StackLimit = p32->StackLimit;
}
#endif
typedef struct _tagSTACKFRAME64 {
ADDRESS64 AddrPC; // program counter
ADDRESS64 AddrReturn; // return address
ADDRESS64 AddrFrame; // frame pointer
ADDRESS64 AddrStack; // stack pointer
ADDRESS64 AddrBStore; // backing store pointer
PVOID FuncTableEntry; // pointer to pdata/fpo or NULL
DWORD64 Params[4]; // possible arguments to the function
BOOL Far; // WOW far call
BOOL Virtual; // is this a virtual frame?
DWORD64 Reserved[3];
KDHELP64 KdHelp;
} STACKFRAME64, *LPSTACKFRAME64;
#if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
#define STACKFRAME STACKFRAME64
#define LPSTACKFRAME LPSTACKFRAME64
#else
typedef struct _tagSTACKFRAME {
ADDRESS AddrPC; // program counter
ADDRESS AddrReturn; // return address
ADDRESS AddrFrame; // frame pointer
ADDRESS AddrStack; // stack pointer
PVOID FuncTableEntry; // pointer to pdata/fpo or NULL
DWORD Params[4]; // possible arguments to the function
BOOL Far; // WOW far call
BOOL Virtual; // is this a virtual frame?
DWORD Reserved[3];
KDHELP KdHelp;
ADDRESS AddrBStore; // backing store pointer
} STACKFRAME, *LPSTACKFRAME;
#endif
typedef
BOOL
(__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)(
__in HANDLE hProcess,
__in DWORD64 qwBaseAddress,
__out_bcount(nSize) PVOID lpBuffer,
__in DWORD nSize,
__out LPDWORD lpNumberOfBytesRead
);
typedef
PVOID
(__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)(
__in HANDLE ahProcess,
__in DWORD64 AddrBase
);
typedef
DWORD64
(__stdcall *PGET_MODULE_BASE_ROUTINE64)(
__in HANDLE hProcess,
__in DWORD64 Address
);
typedef
DWORD64
(__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)(
__in HANDLE hProcess,
__in HANDLE hThread,
__in LPADDRESS64 lpaddr
);
BOOL
IMAGEAPI
StackWalk64(
__in DWORD MachineType,
__in HANDLE hProcess,
__in HANDLE hThread,
__inout LPSTACKFRAME64 StackFrame,
__inout PVOID ContextRecord,
__in_opt PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
__in_opt PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
__in_opt PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
__in_opt PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress
);
#if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64)
#define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64
#define PFUNCTION_TABLE_ACCESS_ROUTINE PFUNCTION_TABLE_ACCESS_ROUTINE64
#define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64
#define PTRANSLATE_ADDRESS_ROUTINE PTRANSLATE_ADDRESS_ROUTINE64
#define StackWalk StackWalk64
#else
typedef
BOOL
(__stdcall *PREAD_PROCESS_MEMORY_ROUTINE)(
__in HANDLE hProcess,
__in DWORD lpBaseAddress,
__out_bcount(nSize) PVOID lpBuffer,
__in DWORD nSize,
__out PDWORD lpNumberOfBytesRead
);
typedef
PVOID
(__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE)(
__in HANDLE hProcess,
__in DWORD AddrBase
);
typedef
DWORD
(__stdcall *PGET_MODULE_BASE_ROUTINE)(
__in HANDLE hProcess,
__in DWORD Address
);
typedef
DWORD
(__stdcall *PTRANSLATE_ADDRESS_ROUTINE)(
__in HANDLE hProcess,
__in HANDLE hThread,
__out LPADDRESS lpaddr
);
BOOL
IMAGEAPI
StackWalk(
DWORD MachineType,
__in HANDLE hProcess,
__in HANDLE hThread,
__inout LPSTACKFRAME StackFrame,
__inout PVOID ContextRecord,
__in_opt PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
__in_opt PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
__in_opt PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
__in_opt PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
);
#endif
#define API_VERSION_NUMBER 11
typedef struct API_VERSION {
USHORT MajorVersion;
USHORT MinorVersion;
USHORT Revision;
USHORT Reserved;
} API_VERSION, *LPAPI_VERSION;
LPAPI_VERSION
IMAGEAPI
ImagehlpApiVersion(
VOID
);
LPAPI_VERSION
IMAGEAPI
ImagehlpApiVersionEx(
__in LPAPI_VERSION AppVersion
);
DWORD
IMAGEAPI
GetTimestampForLoadedLibrary(
__in HMODULE Module
);
//
// typedefs for function pointers
//
typedef BOOL
(CALLBACK *PSYM_ENUMMODULES_CALLBACK64)(
__in PCSTR ModuleName,
__in DWORD64 BaseOfDll,
__in_opt PVOID UserContext
);
typedef BOOL
(CALLBACK *PSYM_ENUMMODULES_CALLBACKW64)(
__in PCWSTR ModuleName,
__in DWORD64 BaseOfDll,
__in_opt PVOID UserContext
);
typedef BOOL
(CALLBACK *PENUMLOADED_MODULES_CALLBACK64)(
__in PCSTR ModuleName,
__in DWORD64 ModuleBase,
__in ULONG ModuleSize,
__in_opt PVOID UserContext
);
typedef BOOL
(CALLBACK *PENUMLOADED_MODULES_CALLBACKW64)(
__in PCWSTR ModuleName,
__in DWORD64 ModuleBase,
__in ULONG ModuleSize,
__in_opt PVOID UserContext
);
typedef BOOL
(CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64)(
__in PCSTR SymbolName,
__in DWORD64 SymbolAddress,
__in ULONG SymbolSize,
__in_opt PVOID UserContext
);
typedef BOOL
(CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64W)(
__in PCWSTR SymbolName,
__in DWORD64 SymbolAddress,
__in ULONG SymbolSize,
__in_opt PVOID UserContext
);
typedef BOOL
(CALLBACK *PSYMBOL_REGISTERED_CALLBACK64)(
__in HANDLE hProcess,
__in ULONG ActionCode,
__in_opt ULONG64 CallbackData,
__in_opt ULONG64 UserContext
);