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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
|
/*++
Copyright (c) 1989-2002 Microsoft Corporation
Module Name:
mspyLog.c
Abstract:
This module contains functions used to retrieve and see the log records
recorded by MiniSpy.sys.
Environment:
User mode
--*/
#include <DriverSpecs.h>
_Analysis_mode_(_Analysis_code_type_user_code_)
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <winioctl.h>
#include "mspyLog.h"
#define TIME_BUFFER_LENGTH 20
#define TIME_ERROR "time error"
#define POLL_INTERVAL 200 // 200 milliseconds
BOOLEAN
TranslateFileTag(
_In_ PLOG_RECORD logRecord
)
/*++
Routine Description:
If this is a mount point reparse point, move the given name string to the
correct position in the log record structure so it will be displayed
by the common routines.
Arguments:
logRecord - The log record to update
Return Value:
TRUE - if this is a mount point reparse point
FALSE - otherwise
--*/
{
PFLT_TAG_DATA_BUFFER TagData;
ULONG Length;
//
// The reparse data structure starts in the NAME field, point to it.
//
TagData = (PFLT_TAG_DATA_BUFFER) &logRecord->Name[0];
//
// See if MOUNT POINT tag
//
if (TagData->FileTag == IO_REPARSE_TAG_MOUNT_POINT) {
//
// calculate how much to copy
//
Length = min( MAX_NAME_SPACE - sizeof(UNICODE_NULL), TagData->MountPointReparseBuffer.SubstituteNameLength );
//
// Position the reparse name at the proper position in the buffer.
// Note that we are doing an overlapped copy
//
MoveMemory( &logRecord->Name[0],
TagData->MountPointReparseBuffer.PathBuffer,
Length );
logRecord->Name[Length/sizeof(WCHAR)] = UNICODE_NULL;
return TRUE;
}
return FALSE;
}
DWORD
WINAPI
RetrieveLogRecords(
_In_ LPVOID lpParameter
)
/*++
Routine Description:
This runs as a separate thread. Its job is to retrieve log records
from the filter and then output them
Arguments:
lpParameter - Contains context structure for synchronizing with the
main program thread.
Return Value:
The thread successfully terminated
--*/
{
PLOG_CONTEXT context = (PLOG_CONTEXT)lpParameter;
DWORD bytesReturned = 0;
DWORD used;
PVOID alignedBuffer[BUFFER_SIZE/sizeof( PVOID )];
PCHAR buffer = (PCHAR) alignedBuffer;
HRESULT hResult;
PLOG_RECORD pLogRecord;
PRECORD_DATA pRecordData;
COMMAND_MESSAGE commandMessage;
//printf("Log: Starting up\n");
#pragma warning(push)
#pragma warning(disable:4127) // conditional expression is constant
while (TRUE) {
#pragma warning(pop)
//
// Check to see if we should shut down.
//
if (context->CleaningUp) {
break;
}
//
// Request log data from MiniSpy.
//
commandMessage.Command = GetMiniSpyLog;
hResult = FilterSendMessage( context->Port,
&commandMessage,
sizeof( COMMAND_MESSAGE ),
buffer,
sizeof(alignedBuffer),
&bytesReturned );
if (IS_ERROR( hResult )) {
if (HRESULT_FROM_WIN32( ERROR_INVALID_HANDLE ) == hResult) {
printf( "The kernel component of minispy has unloaded. Exiting\n" );
ExitProcess( 0 );
} else {
if (hResult != HRESULT_FROM_WIN32( ERROR_NO_MORE_ITEMS )) {
printf( "UNEXPECTED ERROR received: %x\n", hResult );
}
Sleep( POLL_INTERVAL );
}
continue;
}
//
// Buffer is filled with a series of LOG_RECORD structures, one
// right after another. Each LOG_RECORD says how long it is, so
// we know where the next LOG_RECORD begins.
//
pLogRecord = (PLOG_RECORD) buffer;
used = 0;
//
// Logic to write record to screen and/or file
//
for (;;) {
if (used+FIELD_OFFSET(LOG_RECORD,Name) > bytesReturned) {
break;
}
if (pLogRecord->Length < (sizeof(LOG_RECORD)+sizeof(WCHAR))) {
printf( "UNEXPECTED LOG_RECORD->Length: length=%d expected>=%d\n",
pLogRecord->Length,
(ULONG)(sizeof(LOG_RECORD)+sizeof(WCHAR)));
break;
}
used += pLogRecord->Length;
if (used > bytesReturned) {
printf( "UNEXPECTED LOG_RECORD size: used=%d bytesReturned=%d\n",
used,
bytesReturned);
break;
}
pRecordData = &pLogRecord->Data;
//
// See if a reparse point entry
//
if (FlagOn(pLogRecord->RecordType,RECORD_TYPE_FILETAG)) {
if (!TranslateFileTag( pLogRecord )){
//
// If this is a reparse point that can't be interpreted, move on.
//
pLogRecord = (PLOG_RECORD)Add2Ptr(pLogRecord,pLogRecord->Length);
continue;
}
}
if (context->LogToScreen) {
ScreenDump( pLogRecord->SequenceNumber,
pLogRecord->Name,
pRecordData );
}
if (context->LogToFile) {
FileDump( pLogRecord->SequenceNumber,
pLogRecord->Name,
pRecordData,
context->OutputFile );
}
//
// The RecordType could also designate that we are out of memory
// or hit our program defined memory limit, so check for these
// cases.
//
if (FlagOn(pLogRecord->RecordType,RECORD_TYPE_FLAG_OUT_OF_MEMORY)) {
if (context->LogToScreen) {
printf( "M: %08X System Out of Memory\n",
pLogRecord->SequenceNumber );
}
if (context->LogToFile) {
fprintf( context->OutputFile,
"M:\t0x%08X\tSystem Out of Memory\n",
pLogRecord->SequenceNumber );
}
} else if (FlagOn(pLogRecord->RecordType,RECORD_TYPE_FLAG_EXCEED_MEMORY_ALLOWANCE)) {
if (context->LogToScreen) {
printf( "M: %08X Exceeded Mamimum Allowed Memory Buffers\n",
pLogRecord->SequenceNumber );
}
if (context->LogToFile) {
fprintf( context->OutputFile,
"M:\t0x%08X\tExceeded Mamimum Allowed Memory Buffers\n",
pLogRecord->SequenceNumber );
}
}
//
// Move to next LOG_RECORD
//
pLogRecord = (PLOG_RECORD)Add2Ptr(pLogRecord,pLogRecord->Length);
}
//
// If we didn't get any data, pause for 1/2 second
//
if (bytesReturned == 0) {
Sleep( POLL_INTERVAL );
}
}
printf( "Log: Shutting down\n" );
ReleaseSemaphore( context->ShutDown, 1, NULL );
printf( "Log: All done\n" );
return 0;
}
VOID
PrintIrpCode(
_In_ UCHAR MajorCode,
_In_ UCHAR MinorCode,
_In_opt_ FILE *OutputFile,
_In_ BOOLEAN PrintMajorCode
)
/*++
Routine Description:
Display the operation code
Arguments:
MajorCode - Major function code of operation
MinorCode - Minor function code of operation
OutputFile - If writing to a file (not the screen) the handle for that file
PrintMajorCode - Only used when printing to the display:
TRUE - if we want to display the MAJOR CODE
FALSE - if we want to display the MINOR code
Return Value:
None
--*/
{
CHAR *irpMajorString, *irpMinorString = NULL;
CHAR errorBuf[128];
switch (MajorCode) {
case IRP_MJ_CREATE:
irpMajorString = IRP_MJ_CREATE_STRING;
break;
case IRP_MJ_CREATE_NAMED_PIPE:
irpMajorString = IRP_MJ_CREATE_NAMED_PIPE_STRING;
break;
case IRP_MJ_CLOSE:
irpMajorString = IRP_MJ_CLOSE_STRING;
break;
case IRP_MJ_READ:
irpMajorString = IRP_MJ_READ_STRING;
switch (MinorCode) {
case IRP_MN_NORMAL:
irpMinorString = IRP_MN_NORMAL_STRING;
break;
case IRP_MN_DPC:
irpMinorString = IRP_MN_DPC_STRING;
break;
case IRP_MN_MDL:
irpMinorString = IRP_MN_MDL_STRING;
break;
case IRP_MN_COMPLETE:
irpMinorString = IRP_MN_COMPLETE_STRING;
break;
case IRP_MN_COMPRESSED:
irpMinorString = IRP_MN_COMPRESSED_STRING;
break;
case IRP_MN_MDL_DPC:
irpMinorString = IRP_MN_MDL_DPC_STRING;
break;
case IRP_MN_COMPLETE_MDL:
irpMinorString = IRP_MN_COMPLETE_MDL_STRING;
break;
case IRP_MN_COMPLETE_MDL_DPC:
irpMinorString = IRP_MN_COMPLETE_MDL_DPC_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_WRITE:
irpMajorString = IRP_MJ_WRITE_STRING;
switch (MinorCode) {
case IRP_MN_NORMAL:
irpMinorString = IRP_MN_NORMAL_STRING;
break;
case IRP_MN_DPC:
irpMinorString = IRP_MN_DPC_STRING;
break;
case IRP_MN_MDL:
irpMinorString = IRP_MN_MDL_STRING;
break;
case IRP_MN_COMPLETE:
irpMinorString = IRP_MN_COMPLETE_STRING;
break;
case IRP_MN_COMPRESSED:
irpMinorString = IRP_MN_COMPRESSED_STRING;
break;
case IRP_MN_MDL_DPC:
irpMinorString = IRP_MN_MDL_DPC_STRING;
break;
case IRP_MN_COMPLETE_MDL:
irpMinorString = IRP_MN_COMPLETE_MDL_STRING;
break;
case IRP_MN_COMPLETE_MDL_DPC:
irpMinorString = IRP_MN_COMPLETE_MDL_DPC_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_QUERY_INFORMATION:
irpMajorString = IRP_MJ_QUERY_INFORMATION_STRING;
break;
case IRP_MJ_SET_INFORMATION:
irpMajorString = IRP_MJ_SET_INFORMATION_STRING;
break;
case IRP_MJ_QUERY_EA:
irpMajorString = IRP_MJ_QUERY_EA_STRING;
break;
case IRP_MJ_SET_EA:
irpMajorString = IRP_MJ_SET_EA_STRING;
break;
case IRP_MJ_FLUSH_BUFFERS:
irpMajorString = IRP_MJ_FLUSH_BUFFERS_STRING;
break;
case IRP_MJ_QUERY_VOLUME_INFORMATION:
irpMajorString = IRP_MJ_QUERY_VOLUME_INFORMATION_STRING;
break;
case IRP_MJ_SET_VOLUME_INFORMATION:
irpMajorString = IRP_MJ_SET_VOLUME_INFORMATION_STRING;
break;
case IRP_MJ_DIRECTORY_CONTROL:
irpMajorString = IRP_MJ_DIRECTORY_CONTROL_STRING;
switch (MinorCode) {
case IRP_MN_QUERY_DIRECTORY:
irpMinorString = IRP_MN_QUERY_DIRECTORY_STRING;
break;
case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
irpMinorString = IRP_MN_NOTIFY_CHANGE_DIRECTORY_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_FILE_SYSTEM_CONTROL:
irpMajorString = IRP_MJ_FILE_SYSTEM_CONTROL_STRING;
switch (MinorCode) {
case IRP_MN_USER_FS_REQUEST:
irpMinorString = IRP_MN_USER_FS_REQUEST_STRING;
break;
case IRP_MN_MOUNT_VOLUME:
irpMinorString = IRP_MN_MOUNT_VOLUME_STRING;
break;
case IRP_MN_VERIFY_VOLUME:
irpMinorString = IRP_MN_VERIFY_VOLUME_STRING;
break;
case IRP_MN_LOAD_FILE_SYSTEM:
irpMinorString = IRP_MN_LOAD_FILE_SYSTEM_STRING;
break;
case IRP_MN_TRACK_LINK:
irpMinorString = IRP_MN_TRACK_LINK_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_DEVICE_CONTROL:
irpMajorString = IRP_MJ_DEVICE_CONTROL_STRING;
switch (MinorCode) {
case IRP_MN_SCSI_CLASS:
irpMinorString = IRP_MN_SCSI_CLASS_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_INTERNAL_DEVICE_CONTROL:
irpMajorString = IRP_MJ_INTERNAL_DEVICE_CONTROL_STRING;
break;
case IRP_MJ_SHUTDOWN:
irpMajorString = IRP_MJ_SHUTDOWN_STRING;
break;
case IRP_MJ_LOCK_CONTROL:
irpMajorString = IRP_MJ_LOCK_CONTROL_STRING;
switch (MinorCode) {
case IRP_MN_LOCK:
irpMinorString = IRP_MN_LOCK_STRING;
break;
case IRP_MN_UNLOCK_SINGLE:
irpMinorString = IRP_MN_UNLOCK_SINGLE_STRING;
break;
case IRP_MN_UNLOCK_ALL:
irpMinorString = IRP_MN_UNLOCK_ALL_STRING;
break;
case IRP_MN_UNLOCK_ALL_BY_KEY:
irpMinorString = IRP_MN_UNLOCK_ALL_BY_KEY_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_CLEANUP:
irpMajorString = IRP_MJ_CLEANUP_STRING;
break;
case IRP_MJ_CREATE_MAILSLOT:
irpMajorString = IRP_MJ_CREATE_MAILSLOT_STRING;
break;
case IRP_MJ_QUERY_SECURITY:
irpMajorString = IRP_MJ_QUERY_SECURITY_STRING;
break;
case IRP_MJ_SET_SECURITY:
irpMajorString = IRP_MJ_SET_SECURITY_STRING;
break;
case IRP_MJ_POWER:
irpMajorString = IRP_MJ_POWER_STRING;
switch (MinorCode) {
case IRP_MN_WAIT_WAKE:
irpMinorString = IRP_MN_WAIT_WAKE_STRING;
break;
case IRP_MN_POWER_SEQUENCE:
irpMinorString = IRP_MN_POWER_SEQUENCE_STRING;
break;
case IRP_MN_SET_POWER:
irpMinorString = IRP_MN_SET_POWER_STRING;
break;
case IRP_MN_QUERY_POWER:
irpMinorString = IRP_MN_QUERY_POWER_STRING;
break;
default :
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_SYSTEM_CONTROL:
irpMajorString = IRP_MJ_SYSTEM_CONTROL_STRING;
switch (MinorCode) {
case IRP_MN_QUERY_ALL_DATA:
irpMinorString = IRP_MN_QUERY_ALL_DATA_STRING;
break;
case IRP_MN_QUERY_SINGLE_INSTANCE:
irpMinorString = IRP_MN_QUERY_SINGLE_INSTANCE_STRING;
break;
case IRP_MN_CHANGE_SINGLE_INSTANCE:
irpMinorString = IRP_MN_CHANGE_SINGLE_INSTANCE_STRING;
break;
case IRP_MN_CHANGE_SINGLE_ITEM:
irpMinorString = IRP_MN_CHANGE_SINGLE_ITEM_STRING;
break;
case IRP_MN_ENABLE_EVENTS:
irpMinorString = IRP_MN_ENABLE_EVENTS_STRING;
break;
case IRP_MN_DISABLE_EVENTS:
irpMinorString = IRP_MN_DISABLE_EVENTS_STRING;
break;
case IRP_MN_ENABLE_COLLECTION:
irpMinorString = IRP_MN_ENABLE_COLLECTION_STRING;
break;
case IRP_MN_DISABLE_COLLECTION:
irpMinorString = IRP_MN_DISABLE_COLLECTION_STRING;
break;
case IRP_MN_REGINFO:
irpMinorString = IRP_MN_REGINFO_STRING;
break;
case IRP_MN_EXECUTE_METHOD:
irpMinorString = IRP_MN_EXECUTE_METHOD_STRING;
break;
default :
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_DEVICE_CHANGE:
irpMajorString = IRP_MJ_DEVICE_CHANGE_STRING;
break;
case IRP_MJ_QUERY_QUOTA:
irpMajorString = IRP_MJ_QUERY_QUOTA_STRING;
break;
case IRP_MJ_SET_QUOTA:
irpMajorString = IRP_MJ_SET_QUOTA_STRING;
break;
case IRP_MJ_PNP:
irpMajorString = IRP_MJ_PNP_STRING;
switch (MinorCode) {
case IRP_MN_START_DEVICE:
irpMinorString = IRP_MN_START_DEVICE_STRING;
break;
case IRP_MN_QUERY_REMOVE_DEVICE:
irpMinorString = IRP_MN_QUERY_REMOVE_DEVICE_STRING;
break;
case IRP_MN_REMOVE_DEVICE:
irpMinorString = IRP_MN_REMOVE_DEVICE_STRING;
break;
case IRP_MN_CANCEL_REMOVE_DEVICE:
irpMinorString = IRP_MN_CANCEL_REMOVE_DEVICE_STRING;
break;
case IRP_MN_STOP_DEVICE:
irpMinorString = IRP_MN_STOP_DEVICE_STRING;
break;
case IRP_MN_QUERY_STOP_DEVICE:
irpMinorString = IRP_MN_QUERY_STOP_DEVICE_STRING;
break;
case IRP_MN_CANCEL_STOP_DEVICE:
irpMinorString = IRP_MN_CANCEL_STOP_DEVICE_STRING;
break;
case IRP_MN_QUERY_DEVICE_RELATIONS:
irpMinorString = IRP_MN_QUERY_DEVICE_RELATIONS_STRING;
break;
case IRP_MN_QUERY_INTERFACE:
irpMinorString = IRP_MN_QUERY_INTERFACE_STRING;
break;
case IRP_MN_QUERY_CAPABILITIES:
irpMinorString = IRP_MN_QUERY_CAPABILITIES_STRING;
break;
case IRP_MN_QUERY_RESOURCES:
irpMinorString = IRP_MN_QUERY_RESOURCES_STRING;
break;
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
irpMinorString = IRP_MN_QUERY_RESOURCE_REQUIREMENTS_STRING;
break;
case IRP_MN_QUERY_DEVICE_TEXT:
irpMinorString = IRP_MN_QUERY_DEVICE_TEXT_STRING;
break;
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
irpMinorString = IRP_MN_FILTER_RESOURCE_REQUIREMENTS_STRING;
break;
case IRP_MN_READ_CONFIG:
irpMinorString = IRP_MN_READ_CONFIG_STRING;
break;
case IRP_MN_WRITE_CONFIG:
irpMinorString = IRP_MN_WRITE_CONFIG_STRING;
break;
case IRP_MN_EJECT:
irpMinorString = IRP_MN_EJECT_STRING;
break;
case IRP_MN_SET_LOCK:
irpMinorString = IRP_MN_SET_LOCK_STRING;
break;
case IRP_MN_QUERY_ID:
irpMinorString = IRP_MN_QUERY_ID_STRING;
break;
case IRP_MN_QUERY_PNP_DEVICE_STATE:
irpMinorString = IRP_MN_QUERY_PNP_DEVICE_STATE_STRING;
break;
case IRP_MN_QUERY_BUS_INFORMATION:
irpMinorString = IRP_MN_QUERY_BUS_INFORMATION_STRING;
break;
case IRP_MN_DEVICE_USAGE_NOTIFICATION:
irpMinorString = IRP_MN_DEVICE_USAGE_NOTIFICATION_STRING;
break;
case IRP_MN_SURPRISE_REMOVAL:
irpMinorString = IRP_MN_SURPRISE_REMOVAL_STRING;
break;
case IRP_MN_QUERY_LEGACY_BUS_INFORMATION:
irpMinorString = IRP_MN_QUERY_LEGACY_BUS_INFORMATION_STRING;
break;
default :
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_ACQUIRE_FOR_SECTION_SYNCHRONIZATION:
irpMajorString = IRP_MJ_ACQUIRE_FOR_SECTION_SYNCHRONIZATION_STRING;
break;
case IRP_MJ_RELEASE_FOR_SECTION_SYNCHRONIZATION:
irpMajorString = IRP_MJ_RELEASE_FOR_SECTION_SYNCHRONIZATION_STRING;
break;
case IRP_MJ_ACQUIRE_FOR_MOD_WRITE:
irpMajorString = IRP_MJ_ACQUIRE_FOR_MOD_WRITE_STRING;
break;
case IRP_MJ_RELEASE_FOR_MOD_WRITE:
irpMajorString = IRP_MJ_RELEASE_FOR_MOD_WRITE_STRING;
break;
case IRP_MJ_ACQUIRE_FOR_CC_FLUSH:
irpMajorString = IRP_MJ_ACQUIRE_FOR_CC_FLUSH_STRING;
break;
case IRP_MJ_RELEASE_FOR_CC_FLUSH:
irpMajorString = IRP_MJ_RELEASE_FOR_CC_FLUSH_STRING;
break;
case IRP_MJ_NOTIFY_STREAM_FO_CREATION:
irpMajorString = IRP_MJ_NOTIFY_STREAM_FO_CREATION_STRING;
break;
case IRP_MJ_FAST_IO_CHECK_IF_POSSIBLE:
irpMajorString = IRP_MJ_FAST_IO_CHECK_IF_POSSIBLE_STRING;
break;
case IRP_MJ_NETWORK_QUERY_OPEN:
irpMajorString = IRP_MJ_NETWORK_QUERY_OPEN_STRING;
break;
case IRP_MJ_MDL_READ:
irpMajorString = IRP_MJ_MDL_READ_STRING;
break;
case IRP_MJ_MDL_READ_COMPLETE:
irpMajorString = IRP_MJ_MDL_READ_COMPLETE_STRING;
break;
case IRP_MJ_PREPARE_MDL_WRITE:
irpMajorString = IRP_MJ_PREPARE_MDL_WRITE_STRING;
break;
case IRP_MJ_MDL_WRITE_COMPLETE:
irpMajorString = IRP_MJ_MDL_WRITE_COMPLETE_STRING;
break;
case IRP_MJ_VOLUME_MOUNT:
irpMajorString = IRP_MJ_VOLUME_MOUNT_STRING;
break;
case IRP_MJ_VOLUME_DISMOUNT:
irpMajorString = IRP_MJ_VOLUME_DISMOUNT_STRING;
break;
case IRP_MJ_TRANSACTION_NOTIFY:
irpMajorString = IRP_MJ_TRANSACTION_NOTIFY_STRING;
switch (MinorCode) {
case 0:
irpMinorString = TRANSACTION_BEGIN;
break;
case TRANSACTION_NOTIFY_PREPREPARE_CODE:
irpMinorString = TRANSACTION_NOTIFY_PREPREPARE_STRING;
break;
case TRANSACTION_NOTIFY_PREPARE_CODE:
irpMinorString = TRANSACTION_NOTIFY_PREPARE_STRING;
break;
case TRANSACTION_NOTIFY_COMMIT_CODE:
irpMinorString = TRANSACTION_NOTIFY_COMMIT_STRING;
break;
case TRANSACTION_NOTIFY_COMMIT_FINALIZE_CODE:
irpMinorString = TRANSACTION_NOTIFY_COMMIT_FINALIZE_STRING;
break;
case TRANSACTION_NOTIFY_ROLLBACK_CODE:
irpMinorString = TRANSACTION_NOTIFY_ROLLBACK_STRING;
break;
case TRANSACTION_NOTIFY_PREPREPARE_COMPLETE_CODE:
irpMinorString = TRANSACTION_NOTIFY_PREPREPARE_COMPLETE_STRING;
break;
case TRANSACTION_NOTIFY_PREPARE_COMPLETE_CODE:
irpMinorString = TRANSACTION_NOTIFY_COMMIT_COMPLETE_STRING;
break;
case TRANSACTION_NOTIFY_ROLLBACK_COMPLETE_CODE:
irpMinorString = TRANSACTION_NOTIFY_ROLLBACK_COMPLETE_STRING;
break;
case TRANSACTION_NOTIFY_RECOVER_CODE:
irpMinorString = TRANSACTION_NOTIFY_RECOVER_STRING;
break;
case TRANSACTION_NOTIFY_SINGLE_PHASE_COMMIT_CODE:
irpMinorString = TRANSACTION_NOTIFY_SINGLE_PHASE_COMMIT_STRING;
break;
case TRANSACTION_NOTIFY_DELEGATE_COMMIT_CODE:
irpMinorString = TRANSACTION_NOTIFY_DELEGATE_COMMIT_STRING;
break;
case TRANSACTION_NOTIFY_RECOVER_QUERY_CODE:
irpMinorString = TRANSACTION_NOTIFY_RECOVER_QUERY_STRING;
break;
case TRANSACTION_NOTIFY_ENLIST_PREPREPARE_CODE:
irpMinorString = TRANSACTION_NOTIFY_ENLIST_PREPREPARE_STRING;
break;
case TRANSACTION_NOTIFY_LAST_RECOVER_CODE:
irpMinorString = TRANSACTION_NOTIFY_LAST_RECOVER_STRING;
break;
case TRANSACTION_NOTIFY_INDOUBT_CODE:
irpMinorString = TRANSACTION_NOTIFY_INDOUBT_STRING;
break;
case TRANSACTION_NOTIFY_PROPAGATE_PULL_CODE:
irpMinorString = TRANSACTION_NOTIFY_PROPAGATE_PULL_STRING;
break;
case TRANSACTION_NOTIFY_PROPAGATE_PUSH_CODE:
irpMinorString = TRANSACTION_NOTIFY_PROPAGATE_PUSH_STRING;
break;
case TRANSACTION_NOTIFY_MARSHAL_CODE:
irpMinorString = TRANSACTION_NOTIFY_MARSHAL_STRING;
break;
case TRANSACTION_NOTIFY_ENLIST_MASK_CODE:
irpMinorString = TRANSACTION_NOTIFY_ENLIST_MASK_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Transaction notication code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp major function (%d)",MajorCode);
irpMajorString = errorBuf;
break;
}
if (OutputFile) {
if (irpMinorString) {
fprintf(OutputFile, "\t%-35s\t%-35s", irpMajorString, irpMinorString);
} else {
fprintf(OutputFile, "\t%-35s\t ", irpMajorString);
}
} else {
if (PrintMajorCode) {
printf("%-35s ", irpMajorString);
} else {
if (irpMinorString) {
printf(" %-35s\n",
irpMinorString);
}
}
}
}
ULONG
FormatSystemTime(
_In_ SYSTEMTIME *SystemTime,
_Out_writes_bytes_(BufferLength) CHAR *Buffer,
_In_ ULONG BufferLength
)
/*++
Routine Description:
Formats the values in a SystemTime struct into the buffer
passed in. The resulting string is NULL terminated. The format
for the time is:
hours:minutes:seconds:milliseconds
Arguments:
SystemTime - the struct to format
Buffer - the buffer to place the formatted time in
BufferLength - the size of the buffer
Return Value:
The length of the string returned in Buffer.
--*/
{
ULONG returnLength = 0;
if (BufferLength < TIME_BUFFER_LENGTH) {
//
// Buffer is too short so exit
//
return 0;
}
returnLength = sprintf_s( Buffer,
BufferLength,
"%02d:%02d:%02d:%03d",
SystemTime->wHour,
SystemTime->wMinute,
SystemTime->wSecond,
SystemTime->wMilliseconds );
return returnLength;
}
VOID
FileDump (
_In_ ULONG SequenceNumber,
_In_ WCHAR CONST *Name,
_In_ PRECORD_DATA RecordData,
_In_ FILE *File
)
/*++
Routine Description:
Prints a Data log record to the specified file. The output is in a tab
delimited format with the fields in the following order:
SequenceNumber, OriginatingTime, CompletionTime, CallbackMajorId, CallbackMinorId,
Flags, NoCache, Paging I/O, Synchronous, Synchronous paging, FileName,
ReturnStatus, FileName
Arguments:
SequenceNumber - the sequence number for this log record
Name - the name of the file that this Irp relates to
RecordData - the Data record to print
File - the file to print to
Return Value:
None.
--*/
{
FILETIME localTime;
SYSTEMTIME systemTime;
CHAR time[TIME_BUFFER_LENGTH];
static BOOLEAN didFileHeader = FALSE;
//
// Is this an Irp or a FastIo?
//
if (!didFileHeader) {
#if defined(_WIN64)
fprintf( File, "Opr\t SeqNum \t PreOp Time \tPostOp Time \t Process.Thrd\t Major Operation \t Minor Operation \t IrpFlags \t DevObj \t FileObj \t Transactn \t status:inform \t Arg 1 \t Arg 2 \t Arg 3 \t Arg 4 \t Arg 5 \t Arg 6 \tName\n");
fprintf( File, "---\t----------\t------------\t------------\t-------------\t-----------------------------------\t-----------------------------------\t---------------\t------------------\t------------------\t------------------\t-----------------------------\t------------------\t------------------\t------------------\t------------------\t------------------\t----------\t--------------------------------------------------\n");
#else
fprintf( File, "Opr\t SeqNum \t PreOp Time \tPostOp Time \t Process.Thrd\t Major Operation \t Minor Operation \t IrpFlags \t DevObj \t FileObj \tTransactn \t status:inform \t Arg 1 \t Arg 2 \t Arg 3 \t Arg 4 \t Arg 5 \t Arg 6 \tName\n");
fprintf( File, "---\t----------\t------------\t------------\t-------------\t-----------------------------------\t-----------------------------------\t---------------\t----------\t----------\t----------\t---------------------\t----------\t----------\t----------\t----------\t----------\t----------\t--------------------------------------------------\n");
#endif
didFileHeader = TRUE;
}
//
// Is this an Irp or a FastIo?
//
if (RecordData->Flags & FLT_CALLBACK_DATA_IRP_OPERATION) {
fprintf( File, "IRP");
} else if (RecordData->Flags & FLT_CALLBACK_DATA_FAST_IO_OPERATION) {
fprintf( File, "FIO");
} else if (RecordData->Flags & FLT_CALLBACK_DATA_FS_FILTER_OPERATION) {
fprintf( File, "FSF");
} else {
fprintf( File, "ERR");
}
//
// Print the sequence number
//
fprintf( File, "\t0x%08X", SequenceNumber );
//
// Convert originating time
//
FileTimeToLocalFileTime( (FILETIME *)&(RecordData->OriginatingTime),
&localTime );
FileTimeToSystemTime( &localTime,
&systemTime );
if (FormatSystemTime( &systemTime, time, TIME_BUFFER_LENGTH )) {
fprintf( File, "\t%-12s", time );
} else {
fprintf( File, "\t%-12s", TIME_ERROR );
}
//
// Convert completion time
//
FileTimeToLocalFileTime( (FILETIME *)&(RecordData->CompletionTime),
&localTime );
FileTimeToSystemTime( &localTime,
&systemTime );
if (FormatSystemTime( &systemTime, time, TIME_BUFFER_LENGTH )) {
fprintf( File, "\t%-12s", time );
} else {
fprintf( File, "\t%-12s", TIME_ERROR );
}
fprintf(File, "\t%8Ix.%-4Ix ", RecordData->ProcessId, RecordData->ThreadId);
PrintIrpCode( RecordData->CallbackMajorId,
RecordData->CallbackMinorId,
File,
TRUE );
//
// Interpret set IrpFlags
//
fprintf( File, "\t0x%08lx ", RecordData->IrpFlags );
fprintf( File, "%s", (RecordData->IrpFlags & IRP_NOCACHE) ? "N":"-" );
fprintf( File, "%s", (RecordData->IrpFlags & IRP_PAGING_IO) ? "P":"-" );
fprintf( File, "%s", (RecordData->IrpFlags & IRP_SYNCHRONOUS_API) ? "S":"-" );
fprintf( File, "%s", (RecordData->IrpFlags & IRP_SYNCHRONOUS_PAGING_IO) ? "Y":"-" );
fprintf( File, "\t0x%08p", (PVOID) RecordData->DeviceObject );
fprintf( File, "\t0x%08p", (PVOID) RecordData->FileObject );
fprintf( File, "\t0x%08p", (PVOID) RecordData->Transaction );
fprintf( File, "\t0x%08lx:0x%p", RecordData->Status, (PVOID)RecordData->Information );
fprintf( File, "\t0x%p", RecordData->Arg1 );
fprintf( File, "\t0x%p", RecordData->Arg2 );
fprintf( File, "\t0x%p", RecordData->Arg3 );
fprintf( File, "\t0x%p", RecordData->Arg4 );
fprintf( File, "\t0x%p", RecordData->Arg5 );
fprintf( File, "\t0x%08I64x", RecordData->Arg6.QuadPart );
fprintf( File, "\t%S", Name );
fprintf( File, "\n" );
}
VOID
ScreenDump(
_In_ ULONG SequenceNumber,
_In_ WCHAR CONST *Name,
_In_ PRECORD_DATA RecordData
)
/*++
Routine Description:
Prints a Irp log record to the screen in the following order:
SequenceNumber, OriginatingTime, CompletionTime, IrpMajor, IrpMinor,
Flags, IrpFlags, NoCache, Paging I/O, Synchronous, Synchronous paging,
FileName, ReturnStatus, FileName
Arguments:
SequenceNumber - the sequence number for this log record
Name - the file name to which this Irp relates
RecordData - the Irp record to print
Return Value:
None.
--*/
{
FILETIME localTime;
SYSTEMTIME systemTime;
CHAR time[TIME_BUFFER_LENGTH];
static BOOLEAN didScreenHeader = FALSE;
//
// Is this an Irp or a FastIo?
//
if (!didScreenHeader) {
#if defined(_WIN64)
printf("Opr SeqNum PreOp Time PostOp Time Process.Thrd Major/Minor Operation IrpFlags DevObj FileObj Transact status:inform Arguments Name\n");
printf("--- -------- ------------ ------------ ------------- ----------------------------------- ------------- ---------------- ---------------- ---------------- ------------------------- --------------------------------------------------------------------------------------------------------- -----------------------------------\n");
#else
printf("Opr SeqNum PreOp Time PostOp Time Process.Thrd Major/Minor Operation IrpFlags DevObj FileObj Transact status:inform Arguments Name\n");
printf("--- -------- ------------ ------------ ------------- ----------------------------------- ------------- -------- -------- -------- ----------------- ----------------------------------------------------------------- -----------------------------------\n");
#endif
didScreenHeader = TRUE;
}
//
// Display informatoin
//
if (RecordData->Flags & FLT_CALLBACK_DATA_IRP_OPERATION) {
printf( "IRP ");
} else if (RecordData->Flags & FLT_CALLBACK_DATA_FAST_IO_OPERATION) {
printf( "FIO ");
} else if (RecordData->Flags & FLT_CALLBACK_DATA_FS_FILTER_OPERATION) {
printf( "FSF " );
} else {
printf( "ERR ");
}
printf( "%08X ", SequenceNumber );
//
// Convert originating time
//
FileTimeToLocalFileTime( (FILETIME *)&(RecordData->OriginatingTime),
&localTime );
FileTimeToSystemTime( &localTime,
&systemTime );
if (FormatSystemTime( &systemTime, time, TIME_BUFFER_LENGTH )) {
printf( "%-12s ", time );
} else {
printf( "%-12s ", TIME_ERROR );
}
//
// Convert completion time
//
FileTimeToLocalFileTime( (FILETIME *)&(RecordData->CompletionTime),
&localTime );
FileTimeToSystemTime( &localTime,
&systemTime );
if (FormatSystemTime( &systemTime, time, TIME_BUFFER_LENGTH )) {
printf( "%-12s ", time );
} else {
printf( "%-12s ", TIME_ERROR );
}
printf("%8Ix.%-4Ix ", RecordData->ProcessId, RecordData->ThreadId);
PrintIrpCode( RecordData->CallbackMajorId,
RecordData->CallbackMinorId,
NULL,
TRUE );
//
// Interpret set IrpFlags
//
printf( "%08lx ", RecordData->IrpFlags );
printf( "%s", (RecordData->IrpFlags & IRP_NOCACHE) ? "N":"-" );
printf( "%s", (RecordData->IrpFlags & IRP_PAGING_IO) ? "P":"-" );
printf( "%s", (RecordData->IrpFlags & IRP_SYNCHRONOUS_API) ? "S":"-" );
printf( "%s ", (RecordData->IrpFlags & IRP_SYNCHRONOUS_PAGING_IO) ? "Y":"-" );
printf( "%08p ", (PVOID) RecordData->DeviceObject );
printf( "%08p ", (PVOID) RecordData->FileObject );
printf( "%08p ", (PVOID) RecordData->Transaction );
printf( "%08lx:%p ", RecordData->Status, (PVOID)RecordData->Information );
printf( "1:%p 2:%p 3:%p 4:%p 5:%p 6:%08I64x ",
RecordData->Arg1,
RecordData->Arg2,
RecordData->Arg3,
RecordData->Arg4,
RecordData->Arg5,
RecordData->Arg6.QuadPart );
printf( "%S", Name );
printf( "\n" );
PrintIrpCode( RecordData->CallbackMajorId,
RecordData->CallbackMinorId,
NULL,
FALSE );
}
|