-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathNtUtils.MiniDumps.pas
665 lines (552 loc) · 18.9 KB
/
NtUtils.MiniDumps.pas
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
unit NtUtils.MiniDumps;
{
This module provides support for capturing and parsing minidump files.
}
interface
uses
Ntapi.WinNt, Ntapi.ntpsapi, Ntapi.ntioapi, Ntapi.ntdef, Ntapi.minidump,
Ntapi.ntmmapi, NtUtils, DelphiApi.Reflection, DelphiUtils.AutoObjects;
type
IMiniDump = IMemory<PMiniDumpHeader>;
TDmpxThread = record
ThreadId: TThreadId32;
SuspendCount: Cardinal;
PriorityClass: Cardinal;
Priority: Cardinal;
[Hex] Teb: UInt64; // VA in target's address space
[Hex] Stack: UInt64; // VA in target's address space
StackData: TMemory; // Raw data saved in the minidump
ThreadContext: TMemory; // Raw data saved in the minidump
end;
TDmpxModule = record
[Hex] BaseOfImage: UInt64;
[Bytes] SizeOfImage: Cardinal;
[Hex] CheckSum: Cardinal;
TimeDateStamp: TUnixTime;
ModuleName: String;
end;
TDmpxFullMemory = record
[Hex] StartOfMemoryRange: UInt64; // VA in target's address space
[Bytes] DataSize: UInt64;
Content: Pointer; // Raw data saved in the minidump
end;
TDmpxHandle = record
Handle: UInt64;
TypeName: String;
ObjectName: String;
Attributes: TObjectAttributesFlags;
GrantedAccess: TAccessMask;
HandleCount: Cardinal;
PointerCount: Cardinal;
end;
TDmpxMemoryInfo = record
[Hex] BaseAddress: UInt64;
[Hex] AllocationBase: UInt64;
AllocationProtect: TMemoryProtection;
[Bytes] RegionSize: UInt64;
State: TAllocationType;
Protect: TMemoryProtection;
MemoryType: TMemoryType;
end;
TDmpxThreadInfo = TMiniDumpThreadInfo;
TDmpxThreadName = record
ThreadId: TThreadId32;
ThreadName: String;
end;
// Write process's minidump into a file
function DmpxWriteMiniDump(
[Access(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ)] const hxProcess: IHandle;
[Access(FILE_WRITE_DATA)] const hxFile: IHandle;
DumpType: TMiniDumpType
): TNtxStatus;
// Find a specific stream directory in a minidump file
function DmpxFindStream(
const MiniDump: IMiniDump;
Stream: TMiniDumpStreamType;
out Directory: PMiniDumpDirectory
): TNtxStatus;
// Enumerate all streams in a minidump file
function DmpxEnumerateStreams(
const MiniDump: IMiniDump;
out Directories: TArray<PMiniDumpDirectory>
): TNtxStatus;
{ Stream content parsing }
// Retrieve thread information from a minidump file
function DmpxParseThreadStream(
const MiniDump: IMiniDump;
out Threads: TArray<TDmpxThread>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve module information from a minidump file
function DmpxParseModuleStream(
const MiniDump: IMiniDump;
out Modules: TArray<TDmpxModule>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve full memory information from a minidump file
function DmpxParseFullMemoryStream(
const MiniDump: IMiniDump;
out Regions: TArray<TDmpxFullMemory>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve wide command from a minidump file
function DmpxParseCommentWStream(
const MiniDump: IMiniDump;
out Comment: String;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve wide command from a minidump file
function DmpxParseHandleStream(
const MiniDump: IMiniDump;
out Handles: TArray<TDmpxHandle>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve the list of unloaded modules from a minidump file
function DmpxParseUnloadedModulesStream(
const MiniDump: IMiniDump;
out UnloadedModules: TArray<TDmpxModule>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve information about memory regions from a minidump file
function DmpxParseMemoryInfoStream(
const MiniDump: IMiniDump;
out Regions: TArray<TDmpxMemoryInfo>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve information about threads from a minidump file
function DmpxParseThreadInfoStream(
const MiniDump: IMiniDump;
out Threads: TArray<TDmpxThreadInfo>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
// Retrieve information about thread names from a minidump file
function DmpxParseThreadNamesStream(
const MiniDump: IMiniDump;
out ThreadNames: TArray<TDmpxThreadName>;
[in, opt] Stream: PMiniDumpDirectory = nil
): TNtxStatus;
implementation
uses
Ntapi.ntstatus, NtUtils.SysUtils;
{$BOOLEVAL OFF}
{$IFOPT R+}{$DEFINE R+}{$ENDIF}
{$IFOPT Q+}{$DEFINE Q+}{$ENDIF}
function DmpxWriteMiniDump;
begin
Result.Location := 'MiniDumpWriteDump';
Result.Win32Result := MiniDumpWriteDump(HandleOrDefault(hxProcess), 0,
HandleOrDefault(hxFile), DumpType, nil, nil, nil);
end;
function LocationInRange(
const MiniDump: IMiniDump;
const Location: TMiniDumpLocationDescriptor;
SkipCheckForZeroRva: Boolean = False
): Boolean;
begin
Result := (SkipCheckForZeroRva and (Location.Rva = 0)) or
(UInt64(Location.Rva) + Location.DataSize < MiniDump.Size);
end;
function DmpxValidateStreams(
const MiniDump: IMiniDump
): TNtxStatus;
var
Directories: ^TAnysizeArray<TMiniDumpDirectory>;
i: Integer;
begin
Result.Location := 'DmpxFindStream';
// Make sure the header fits
if MiniDump.Size < SizeOf(TMiniDumpHeader) then
begin
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
// Make sure we are parsing a mini-dump file
if (MiniDump.Data.Signature <> MINIDUMP_SIGNATURE) or
(MiniDump.Data.Version <> MINIDUMP_VERSION) then
begin
Result.Status := STATUS_UNKNOWN_REVISION;
Exit;
end;
// Validate overall stream directory size
if UInt64(MiniDump.Data.NumberOfStreams) * SizeOf(TMiniDumpDirectory) +
MiniDump.Data.StreamDirectoryRva >= MiniDump.Size then
begin
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
Directories := MiniDump.Offset(MiniDump.Data.StreamDirectoryRva);
// Validate each stream directory
for i := 0 to Integer(MiniDump.Data.NumberOfStreams) - 1 do
if not LocationInRange(MiniDump, Directories{$R-}[i]{$IFDEF R+}{$R+}{$ENDIF}
.Location) then
begin
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
Result.Status := STATUS_SUCCESS;
end;
function DmpxFindStream;
var
Directories: ^TAnysizeArray<TMiniDumpDirectory>;
i: Integer;
begin
Result := DmpxValidateStreams(MiniDump);
if not Result.IsSuccess then
Exit;
Directories := MiniDump.Offset(MiniDump.Data.StreamDirectoryRva);
for i := 0 to Integer(MiniDump.Data.NumberOfStreams) - 1 do
if Directories{$R-}[i]{$IFDEF R+}{$R+}{$ENDIF}.StreamType = Stream then
begin
Directory := @Directories{$R-}[i]{$IFDEF R+}{$R+}{$ENDIF};
Exit;
end;
Result.Location := 'DmpxFindStream';
Result.LastCall.UsesInfoClass(Stream, icRead);
Result.Status := STATUS_NOT_FOUND;
end;
function DmpxEnumerateStreams;
var
pDirectories: ^TAnysizeArray<TMiniDumpDirectory>;
i: Integer;
begin
Result := DmpxValidateStreams(MiniDump);
if not Result.IsSuccess then
Exit;
pDirectories := MiniDump.Offset(MiniDump.Data.StreamDirectoryRva);
SetLength(Directories, MiniDump.Data.NumberOfStreams);
for i := 0 to Integer(MiniDump.Data.NumberOfStreams) - 1 do
Directories[i] := @pDirectories{$R-}[i]{$IFDEF R+}{$R+}{$ENDIF};
end;
function DmpxFindOrCheckTypeStream(
const MiniDump: IMiniDump;
var Stream: PMiniDumpDirectory;
ExpectedType: TMiniDumpStreamType
): TNtxStatus;
begin
// Find the stream on demand
if not Assigned(Stream) then
begin
Result := DmpxFindStream(MiniDump, ExpectedType, Stream);
if not Result.IsSuccess then
Exit;
end
// Check the type of the supplied stream
else if Stream.StreamType <> ExpectedType then
begin
Result.Location := 'DmpxFindOrVerifyStream';
Result.LastCall.UsesInfoClass(ExpectedType, icRead);
Result.Status := STATUS_OBJECT_TYPE_MISMATCH;
end
else
Result := NtxSuccess;
end;
function GetString(
const MiniDump: IMiniDump;
const Rva: UInt64
): String;
var
StringData: PMiniDumpString;
MaxLength: Cardinal;
begin
if (Rva = 0) or (Rva + SizeOf(Cardinal) >= MiniDump.Size) then
Exit('');
MaxLength := MiniDump.Size - Rva;
StringData := MiniDump.Offset(Rva);
if StringData.Length < MaxLength then
MaxLength := StringData.Length;
Result := RtlxCaptureString(StringData.Buffer,
MaxLength div SizeOf(WideChar));
end;
{ Stream Parsing }
function DmpxParseThreadStream;
var
ThreadList: PMiniDumpThreadList;
ThreadInfo: PMiniDumpThread;
i: Integer;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.ThreadListStream);
if not Result.IsSuccess then
Exit;
ThreadList := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpThreadList) > Stream.Location.DataSize) or
(UInt64(ThreadList.NumberOfThreads) * SizeOf(TMiniDumpThread) +
SizeOf(TMiniDumpThreadList) - SizeOf(TMiniDumpThread) >
Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseThreadStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
ThreadInfo := @ThreadList.Threads[0];
SetLength(Threads, ThreadList.NumberOfThreads);
for i := 0 to High(Threads) do
begin
if not LocationInRange(MiniDump, ThreadInfo.Stack.Memory, True) or
not LocationInRange(MiniDump, ThreadInfo.ThreadContext, True) then
begin
Result.Location := 'DmpxParseThreadStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
Threads[i].ThreadId := ThreadInfo.ThreadId;
Threads[i].SuspendCount := ThreadInfo.SuspendCount;
Threads[i].PriorityClass := ThreadInfo.PriorityClass;
Threads[i].Priority := ThreadInfo.Priority;
Threads[i].Teb := ThreadInfo.Teb;
Threads[i].Stack := ThreadInfo.Stack.StartOfMemoryRange;
Threads[i].StackData.Size := ThreadInfo.Stack.Memory.DataSize;
Threads[i].ThreadContext.Size := ThreadInfo.ThreadContext.DataSize;
if ThreadInfo.Stack.Memory.Rva <> 0 then
Threads[i].StackData.Address := MiniDump.Offset(
ThreadInfo.Stack.Memory.Rva);
if ThreadInfo.ThreadContext.Rva <> 0 then
Threads[i].ThreadContext.Address := MiniDump.Offset(
ThreadInfo.ThreadContext.Rva);
Inc(ThreadInfo);
end;
end;
function DmpxParseModuleStream;
var
ModuleList: PMiniDumpModuleList;
ModuleInfo: PMiniDumpModule;
i: Integer;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.ModuleListStream);
if not Result.IsSuccess then
Exit;
ModuleList := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpModuleList) > Stream.Location.DataSize) or
(UInt64(ModuleList.NumberOfModules) * SizeOf(TMiniDumpModule) +
SizeOf(TMiniDumpModuleList) - SizeOf(TMiniDumpModule) >
Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseModuleStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
ModuleInfo := @ModuleList.Modules[0];
SetLength(Modules, ModuleList.NumberOfModules);
for i := 0 to High(Modules) do
begin
Modules[i].BaseOfImage := ModuleInfo.BaseOfImage;
Modules[i].SizeOfImage := ModuleInfo.SizeOfImage;
Modules[i].CheckSum := ModuleInfo.CheckSum;
Modules[i].TimeDateStamp := ModuleInfo.TimeDateStamp;
Modules[i].ModuleName := GetString(MiniDump,
ModuleInfo.ModuleNameRva);
Inc(ModuleInfo);
end;
end;
function DmpxParseFullMemoryStream;
var
Memory64List: PMiniDumpMemory64List;
Memory64: PMiniDumpMemoryDescriptor64;
i: Integer;
OffsetToRawData: UInt64;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.Memory64ListStream);
if not Result.IsSuccess then
Exit;
Memory64List := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpMemory64List) > Stream.Location.DataSize) or
(UInt64(Memory64List.NumberOfMemoryRanges) *
SizeOf(TMiniDumpMemoryDescriptor64) +
SizeOf(TMiniDumpMemory64List) - SizeOf(TMiniDumpMemoryDescriptor64) >
Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseFullMemoryStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
SetLength(Regions, Memory64List.NumberOfMemoryRanges);
OffsetToRawData := Memory64List.BaseRva;
for i := 0 to High(Regions) do
begin
Memory64 := @Memory64List.MemoryRanges{$R-}[i]{$IFDEF R+}{$R+}{$ENDIF};
Regions[i].StartOfMemoryRange := Memory64.StartOfMemoryRange;
Regions[i].DataSize := Memory64.DataSize;
if OffsetToRawData + Memory64.DataSize > MiniDump.Size then
begin
Result.Location := 'DmpxParseFullMemoryStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
Regions[i].Content := MiniDump.Offset(OffsetToRawData);
Inc(OffsetToRawData, Memory64.DataSize);
end;
end;
function DmpxParseCommentWStream;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.CommentStreamW);
if Result.IsSuccess then
Comment := RtlxCaptureString(MiniDump.Offset(Stream.Location.Rva),
Stream.Location.DataSize div SizeOf(WideChar));
end;
function DmpxParseHandleStream;
var
HandleList: PMiniDumpHandleDataStream;
HandleInfo: PMiniDumpHandleDescriptor2;
i: Integer;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.HandleDataStream);
if not Result.IsSuccess then
Exit;
HandleList := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpHandleDataStream) > Stream.Location.DataSize) or
(HandleList.SizeOfHeader < SizeOf(TMiniDumpHandleDataStream)) or
(HandleList.SizeOfDescriptor < SizeOf(TMiniDumpHandleDescriptor)) or
(UInt64(HandleList.NumberOfDescriptors) * HandleList.SizeOfDescriptor +
HandleList.SizeOfHeader > Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseHandleStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
PByte(HandleInfo) := PByte(HandleList) + HandleList.SizeOfHeader;
SetLength(Handles, HandleList.NumberOfDescriptors);
for i := 0 to High(Handles) do
begin
Handles[i].Handle := HandleInfo.V1.Handle;
Handles[i].TypeName := GetString(MiniDump, HandleInfo.V1.TypeNameRva);
Handles[i].ObjectName := GetString(MiniDump, HandleInfo.V1.ObjectNameRva);
Handles[i].Attributes := HandleInfo.V1.Attributes;
Handles[i].GrantedAccess := HandleInfo.V1.GrantedAccess;
Handles[i].HandleCount := HandleInfo.V1.HandleCount;
Handles[i].PointerCount := HandleInfo.V1.PointerCount;
Inc(PByte(HandleInfo), HandleList.SizeOfDescriptor);
end;
end;
function DmpxParseUnloadedModulesStream;
var
ModuleList: PMiniDumpUnloadedModuleList;
ModuleInfo: PMiniDumpUnloadedModule;
i: Integer;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.UnloadedModuleListStream);
if not Result.IsSuccess then
Exit;
ModuleList := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpUnloadedModuleList) > Stream.Location.DataSize) or
(ModuleList.SizeOfHeader < SizeOf(TMiniDumpUnloadedModuleList)) or
(ModuleList.SizeOfEntry < SizeOf(TMiniDumpUnloadedModule)) or
(UInt64(ModuleList.NumberOfEntries) * ModuleList.SizeOfEntry +
ModuleList.SizeOfHeader > Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseUnloadedModulesStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
PByte(ModuleInfo) := PByte(ModuleList) + ModuleList.SizeOfHeader;
SetLength(UnloadedModules, ModuleList.NumberOfEntries);
for i := 0 to High(UnloadedModules) do
begin
UnloadedModules[i].BaseOfImage := ModuleInfo.BaseOfImage;
UnloadedModules[i].SizeOfImage := ModuleInfo.SizeOfImage;
UnloadedModules[i].CheckSum := ModuleInfo.CheckSum;
UnloadedModules[i].TimeDateStamp := ModuleInfo.TimeDateStamp;
UnloadedModules[i].ModuleName := GetString(MiniDump,
ModuleInfo.ModuleNameRva);
Inc(PByte(ModuleInfo), ModuleList.SizeOfEntry);
end;
end;
function DmpxParseMemoryInfoStream;
var
MemoryList: PMiniDumpMemoryInfoList;
MemoryInfo: PMiniDumpMemoryInfo;
i: Integer;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.MemoryInfoListStream);
if not Result.IsSuccess then
Exit;
MemoryList := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpMemoryInfoList) > Stream.Location.DataSize) or
(MemoryList.SizeOfHeader < SizeOf(TMiniDumpMemoryInfoList)) or
(MemoryList.SizeOfEntry < SizeOf(TMiniDumpMemoryInfo)) or
(UInt64(MemoryList.NumberOfEntries) * MemoryList.SizeOfEntry +
MemoryList.SizeOfHeader > Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseMemoryInfoStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
PByte(MemoryInfo) := PByte(MemoryList) + MemoryList.SizeOfHeader;
SetLength(Regions, MemoryList.NumberOfEntries);
for i := 0 to High(Regions) do
begin
Regions[i].BaseAddress := MemoryInfo.BaseAddress;
Regions[i].AllocationBase := MemoryInfo.AllocationBase;
Regions[i].AllocationProtect := MemoryInfo.AllocationProtect;
Regions[i].RegionSize := MemoryInfo.RegionSize;
Regions[i].State := MemoryInfo.State;
Regions[i].Protect := MemoryInfo.Protect;
Regions[i].MemoryType := MemoryInfo.MemoryType;
Inc(PByte(MemoryInfo), MemoryList.SizeOfEntry);
end;
end;
function DmpxParseThreadInfoStream;
var
ThreadList: PMiniDumpThreadInfoList;
ThreadInfo: PMiniDumpThreadInfo;
i: Integer;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.ThreadInfoListStream);
if not Result.IsSuccess then
Exit;
ThreadList := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpThreadInfoList) > Stream.Location.DataSize) or
(ThreadList.SizeOfHeader < SizeOf(TMiniDumpThreadInfoList)) or
(ThreadList.SizeOfEntry < SizeOf(TMiniDumpThreadInfo)) or
(UInt64(ThreadList.NumberOfEntries) * ThreadList.SizeOfEntry +
ThreadList.SizeOfHeader > Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseThreadInfoStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
PByte(ThreadInfo) := PByte(ThreadList) + ThreadList.SizeOfHeader;
SetLength(Threads, ThreadList.NumberOfEntries);
for i := 0 to High(Threads) do
begin
Threads[i] := ThreadInfo^;
Inc(PByte(ThreadInfo), ThreadList.SizeOfEntry);
end;
end;
function DmpxParseThreadNamesStream;
var
ThreadList: PMiniDumpThreadNameList;
ThreadInfo: PMiniDumpThreadName;
i: Integer;
begin
Result := DmpxFindOrCheckTypeStream(MiniDump, Stream,
TMiniDumpStreamType.ThreadNamesStream);
if not Result.IsSuccess then
Exit;
ThreadList := MiniDump.Offset(Stream.Location.Rva);
if (SizeOf(TMiniDumpThreadNameList) > Stream.Location.DataSize) or
(UInt64(ThreadList.NumberOfThreadNames) * SizeOf(TMiniDumpThreadName) +
SizeOf(TMiniDumpThreadNameList) - SizeOf(TMiniDumpThreadName) >
Stream.Location.DataSize) then
begin
Result.Location := 'DmpxParseThreadNamesStream';
Result.Status := STATUS_INVALID_BUFFER_SIZE;
Exit;
end;
ThreadInfo := @ThreadList.ThreadNames[0];
SetLength(ThreadNames, ThreadList.NumberOfThreadNames);
for i := 0 to High(ThreadNames) do
begin
ThreadNames[i].ThreadId := ThreadInfo.ThreadId;
ThreadNames[i].ThreadName := GetString(MiniDump,
ThreadInfo.RvaOfThreadName);
Inc(ThreadInfo);
end;
end;
end.