Added handle type to object name translation in qsi.
[reactos.git] / rosapps / sysutils / qsi.c
1 /* $Id: qsi.c,v 1.3 2000/05/28 17:44:51 ea Exp $
2 *
3 * PROJECT : ReactOS Operating System (see http://www.reactos.com/)
4 * DESCRIPTION: Tool to query system information
5 * FILE : rosapps/sysutils/qsi.c
6 * AUTHOR : Emanuele Aliberti
7 * LICENSE : GNU GPL (see http://www.gnu.org/)
8 * DATE : 1999-07-28
9 *
10 * BUILD INSTRUCTIONS
11 * If you got this code directly from the CVS repository on
12 * mok.lcvm.com, it should be ok to run "make sqi.exe" from the
13 * current directory. Otherwise, be sure the directories
14 * "rosapps" and "reactos" are siblings (see the FILE file
15 * in the header).
16 *
17 * REVISIONS
18 * 2000-02-12 (ea)
19 * Partially rewritten to run as a tool to query
20 * every system information class data.
21 * 2000-04-23 (ea)
22 * Added almost all structures for getting system
23 * information (from UNDOCNT.H by Dabak et alii).
24 */
25 #include <windows.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <wchar.h>
30
31 #define NTOS_MODE_USER
32 #include <ntos.h>
33
34 typedef
35 struct _FLAGS
36 {
37 DWORD Verbose:1; /* print unknown, unused, service fields */
38 DWORD Dump:1; /* raw dump output buffer */
39 DWORD Batch:1; /* no shell (for future use) */
40 } FLAGS;
41
42 static
43 struct
44 {
45 FLAGS Flag;
46 BOOL Active;
47 HANDLE Heap;
48 INT ExitCode;
49
50 } Application =
51 {
52 {0, 0},
53 FALSE
54 };
55
56 #define ONOFF(b) ((b)?"on":"off")
57
58 #define ARGV_SIZE 64
59
60 #define BUFFER_SIZE_DEFAULT 65536
61
62 #define TF(b) ((b)?"true":"false")
63
64 typedef
65 INT (* COMMAND_CALL) (INT ArgC,LPCSTR ArgV []);
66
67
68
69 VOID STDCALL PrintStatus (NTSTATUS Status);
70
71 #define CMD_REF(n) CMD_##n
72 #define CMD_DEF(n) INT CMD_REF(n) (INT argc, LPCSTR argv [])
73 #define CMD_NOT_IMPLEMENTED {printf("%s not implemented\n", argv[0]);return(0);}
74
75 typedef
76 struct _COMMAND_DESCRIPTOR
77 {
78 LPCSTR Name;
79 COMMAND_CALL EntryPoint;
80 LPCSTR Description;
81
82 } COMMAND_DESCRIPTOR, * PCOMMAND_DESCRIPTOR;
83
84
85 /* Fast BYTE to binary representation */
86
87 #define BIT(n,m) (((n)&(m))?'1':'0')
88 LPSTR
89 STDCALL
90 ByteToBinaryString (
91 BYTE Byte,
92 CHAR Binary [8]
93 )
94 {
95 Binary [7] = BIT(Byte,0x01);
96 Binary [6] = BIT(Byte,0x02);
97 Binary [5] = BIT(Byte,0x04);
98 Binary [4] = BIT(Byte,0x08);
99 Binary [3] = BIT(Byte,0x10);
100 Binary [2] = BIT(Byte,0x20);
101 Binary [1] = BIT(Byte,0x40);
102 Binary [0] = BIT(Byte,0x80);
103 return (LPSTR) Binary;
104 }
105
106 /* --- */
107 VOID
108 STDCALL
109 DumpData (int Size, PVOID pData )
110 {
111 PBYTE Buffer = (PBYTE) pData;
112 PBYTE Base = Buffer;
113 int i;
114 const int Width = 16;
115
116 if (! Application.Flag.Dump)
117 {
118 return;
119 }
120 while (Size > 0)
121 {
122 printf ("%04x: ", (Buffer - Base));
123 for ( i = 0;
124 (i < Width);
125 ++i
126 )
127 {
128 if (Size - i > 0)
129 {
130 printf (
131 "%02x%c",
132 Buffer[i],
133 (i % 4 == 3) ? '|' : ' '
134 );
135 }
136 else
137 {
138 printf (" ");
139 }
140 }
141 printf (" ");
142 for ( i = 0;
143 (i < Width);
144 ++i
145 )
146 {
147 if (Size - i > 0)
148 {
149 printf (
150 "%c",
151 ( (Buffer[i] > ' ')
152 && (Buffer[i] < 127)
153 )
154 ? Buffer[i]
155 : ' '
156 );
157 }
158 }
159 printf ("\n");
160 Buffer += Width;
161 Size -= Width;
162 }
163 printf ("\n");
164 }
165
166 /* --- */
167
168 static
169 LPTSTR
170 KernelObjectName [] =
171 {
172 _T("0"), /* FIXME */
173 _T("1"), /* FIXME */
174 _T("Directory"),
175 _T("SymbolicLink"),
176 _T("Token"),
177 _T("Process"),
178 _T("Thread"),
179 _T("Event"),
180 _T("8"), /* FIXME */
181 _T("Mutant"),
182 _T("Semaphore"),
183 _T("Timer"),
184 _T("12"), /* FIXME */
185 _T("WindowStation"),
186 _T("Desktop"),
187 _T("Section"),
188 _T("Key"),
189 _T("Port"),
190 _T("18"), /* FIXME */
191 _T("19"), /* FIXME */
192 _T("20"), /* FIXME */
193 _T("21"), /* FIXME */
194 _T("IoCompletion"),
195 _T("File"),
196 NULL
197 };
198
199
200 LPTSTR
201 STDCALL
202 HandleTypeToObjectName (
203 DWORD HandleType
204 )
205 {
206 if (HandleType > 23) /* FIXME: use a symbol not a literal */
207 {
208 return _T("Unknown");
209 }
210 return KernelObjectName [HandleType];
211 }
212
213
214 /* --- */
215
216 int
217 STDCALL
218 FindRequiredBufferSize (int i, int step)
219 {
220 NTSTATUS Status = STATUS_INFO_LENGTH_MISMATCH;
221 BYTE Buffer [BUFFER_SIZE_DEFAULT];
222 INT Size;
223 LONG Length = 0;
224
225
226 Size = step = (step > 0 ? step : 1);
227 while ( (Size < sizeof Buffer)
228 && (Status == STATUS_INFO_LENGTH_MISMATCH)
229 )
230 {
231 if (Application.Flag.Verbose)
232 {
233 printf ("\tTry %d", Size);
234 }
235 RtlZeroMemory (Buffer, sizeof Buffer);
236 Length = 0;
237 Status = NtQuerySystemInformation (
238 i,
239 & Buffer,
240 Size,
241 & Length
242 );
243 if (STATUS_SUCCESS == Status)
244 {
245 printf ("Length = %d\n", Size);
246 return Size;
247 }
248 if (Length > 0)
249 {
250 Size = Length;
251 }
252 else
253 {
254 /* FIXME: slow linear search! */
255 Size += step;
256 }
257 }
258 printf ("No valid buffer length found!\n");
259 return -1;
260 }
261
262
263 VOID
264 STDCALL
265 PrintStatus (NTSTATUS Status)
266 {
267 LPCSTR StatusName = NULL;
268
269 switch (Status)
270 {
271 case STATUS_INVALID_INFO_CLASS:
272 StatusName = "STATUS_INVALID_INFO_CLASS";
273 break;
274 case STATUS_INFO_LENGTH_MISMATCH:
275 StatusName = "STATUS_INFO_LENGTH_MISMATCH";
276 break;
277 case STATUS_ACCESS_VIOLATION:
278 StatusName = "STATUS_ACCESS_VIOLATION";
279 break;
280 case STATUS_NOT_IMPLEMENTED:
281 StatusName = "STATUS_NOT_IMPLEMENTED";
282 break;
283 case STATUS_BREAKPOINT:
284 StatusName = "STATUS_BREAKPOINT";
285 break;
286 }
287 if (NULL != StatusName)
288 {
289 printf ("\tStatus = %s\n", StatusName);
290 return;
291 }
292 printf ("\tStatus = 0x%08lX\n", Status );
293 }
294
295 /* Auxiliary functions */
296
297 PCHAR
298 DaysOfWeek [] =
299 {
300 "Sunday",
301 "Monday",
302 "Tuesday",
303 "Wednesday",
304 "Thursday",
305 "Friday",
306 "Saturday",
307 "Sunday"
308 };
309
310 VOID
311 STDCALL
312 PrintUtcDateTime (LPCSTR Template, PTIME UtcTime)
313 {
314 CHAR UtcTimeString [64];
315 TIME_FIELDS UtcTimeFields;
316
317 RtlTimeToTimeFields (
318 (PLARGE_INTEGER) UtcTime,
319 & UtcTimeFields
320 );
321 sprintf (
322 UtcTimeString,
323 "%s %d-%02d-%02d %02d:%02d:%02d.%03d UTC",
324 DaysOfWeek[UtcTimeFields.Weekday],
325 UtcTimeFields.Year,
326 UtcTimeFields.Month,
327 UtcTimeFields.Day,
328 UtcTimeFields.Hour,
329 UtcTimeFields.Minute,
330 UtcTimeFields.Second,
331 UtcTimeFields.Milliseconds
332 );
333 printf (
334 Template,
335 UtcTimeString
336 );
337 }
338
339
340 /**********************************************************************
341 * Dumpers
342 **********************************************************************/
343
344
345 /**********************************************************************
346 *
347 * DESCRIPTION
348 * Dump whatever we get by calling NtQuerySystemInformation with
349 * a user provided system information class id.
350 * NOTE
351 * NtQuerySystemInformation called with user class id.
352 */
353 CMD_DEF(unknown)
354 {
355 int _id = atoi ((char*)(argv[0] + 1)); /* "#24" */
356 /* ^ */
357 int Size = -1;
358 PBYTE Buffer = NULL;
359 NTSTATUS Status;
360
361
362 printf ("SystemInformation %d:\n", _id);
363 /* Find buffer size */
364 Size = FindRequiredBufferSize (_id, 1);
365 if (-1 == Size)
366 {
367 printf("\t(no data)\n");
368 return EXIT_FAILURE;
369 }
370 /* Allocate the buffer */
371 Buffer = GlobalAlloc (GMEM_ZEROINIT, Size);
372 if (NULL == Buffer)
373 {
374 printf ("#%d: could not allocate %d bytes\n", _id, Size);
375 return EXIT_FAILURE;
376 }
377 /* Query the executive */
378 Status = NtQuerySystemInformation (
379 _id,
380 Buffer,
381 Size,
382 NULL
383 );
384 if (!NT_SUCCESS(Status))
385 {
386 PrintStatus (Status);
387 FindRequiredBufferSize (_id, 1);
388 GlobalFree (Buffer);
389 return EXIT_FAILURE;
390 }
391 /* Print the data */
392 DumpData (Size, Buffer);
393 /* --- */
394 GlobalFree (Buffer);
395
396 return EXIT_SUCCESS;
397 }
398
399
400 /**********************************************************************
401 *
402 * DESCRIPTION
403 *
404 * NOTE
405 * Class 0.
406 */
407 CMD_DEF(Basic)
408 {
409 NTSTATUS Status;
410 SYSTEM_BASIC_INFORMATION Info;
411
412 if (Application.Flag.Verbose)
413 {
414 printf ("SystemBasicInformation:\n");
415 }
416 RtlZeroMemory (
417 (PVOID) & Info,
418 sizeof Info
419 );
420 Status = NtQuerySystemInformation (
421 SystemBasicInformation,
422 & Info,
423 sizeof Info,
424 NULL
425 );
426 if (STATUS_SUCCESS != Status)
427 {
428 PrintStatus (Status);
429 return EXIT_FAILURE;
430 }
431 printf ("\tAlwaysZero = 0x%08x\n", Info.AlwaysZero);
432 printf ("\tKeMaximumIncrement = %ld\n", Info.KeMaximumIncrement);
433 printf ("\tMmPageSize = %ld\n", Info.MmPageSize);
434 printf ("\tMmNumberOfPhysicalPages = %ld\n", Info.MmNumberOfPhysicalPages);
435 printf ("\tMmLowestPhysicalPage = %ld\n", Info.MmLowestPhysicalPage);
436 printf ("\tMmHighestPhysicalPage = %ld\n", Info.MmHighestPhysicalPage);
437 printf ("\tMmLowestUserAddress = 0x%08x\n", Info.MmLowestUserAddress);
438 printf ("\tMmLowestUserAddress1 = 0x%08x\n", Info.MmLowestUserAddress1);
439 printf ("\tMmHighestUserAddress = 0x%08x\n", Info.MmHighestUserAddress);
440 printf ("\tKeActiveProcessors = 0x%08x\n", Info.KeActiveProcessors);
441 printf ("\tKeNumberProcessors = %ld\n", Info.KeNumberProcessors);
442
443 return EXIT_SUCCESS;
444 }
445
446
447 /**********************************************************************
448 *
449 * DESCRIPTION
450 *
451 * NOTE
452 * Class 1.
453 */
454 CMD_DEF(Processor)
455 {
456 NTSTATUS Status;
457 SYSTEM_PROCESSOR_INFORMATION Info;
458
459 if (Application.Flag.Verbose)
460 {
461 printf ("SystemProcessorInformation:\n");
462 }
463 RtlZeroMemory (
464 (PVOID) & Info,
465 sizeof Info
466 );
467 Status = NtQuerySystemInformation (
468 SystemProcessorInformation,
469 & Info,
470 sizeof Info,
471 NULL
472 );
473 if (STATUS_SUCCESS != Status)
474 {
475 PrintStatus (Status);
476 return EXIT_FAILURE;
477 }
478 printf ("\tKeProcessorArchitecture = %ld\n", Info.KeProcessorArchitecture);
479 printf ("\tKeProcessorLevel = %ld\n", Info.KeProcessorLevel);
480 printf ("\tKeProcessorRevision = %ld\n", Info.KeProcessorRevision);
481 if (Application.Flag.Verbose)
482 {
483 printf ("\tAlwaysZero = 0x%08x\n", Info.AlwaysZero);
484 }
485 printf ("\tKeFeatureBits = %08x\n", Info.KeFeatureBits);
486
487 return EXIT_SUCCESS;
488 }
489
490
491 /**********************************************************************
492 *
493 * DESCRIPTION
494 * System performance information.
495 *
496 * NOTE
497 * Class 2.
498 */
499 CMD_DEF(Performance)
500 {
501 NTSTATUS Status = STATUS_SUCCESS;
502 PSYSTEM_PERFORMANCE_INFO Info;
503 LONG Length = 0;
504
505
506 if (Application.Flag.Verbose)
507 {
508 printf ("SystemPerformanceInformation:\n");
509 }
510 Status = NtQuerySystemInformation (
511 SystemPerformanceInformation,
512 & Info,
513 sizeof Info,
514 & Length
515 );
516 if (STATUS_SUCCESS != Status)
517 {
518 PrintStatus (Status);
519 return EXIT_FAILURE;
520 }
521 printf ("Not implemented.\n");
522 #if 0
523 LARGE_INTEGER TotalProcessorTime;
524 LARGE_INTEGER IoReadTransferCount;
525 LARGE_INTEGER IoWriteTransferCount;
526 LARGE_INTEGER IoOtherTransferCount;
527 ULONG IoReadOperationCount;
528 ULONG IoWriteOperationCount;
529 ULONG IoOtherOperationCount;
530 ULONG MmAvailablePages;
531 ULONG MmTotalCommitedPages;
532 ULONG MmTotalCommitLimit;
533 ULONG MmPeakLimit;
534 ULONG PageFaults;
535 ULONG WriteCopies;
536 ULONG TransitionFaults;
537 ULONG Unknown1;
538 ULONG DemandZeroFaults;
539 ULONG PagesInput;
540 ULONG PagesRead;
541 ULONG Unknown2;
542 ULONG Unknown3;
543 ULONG PagesOutput;
544 ULONG PageWrites;
545 ULONG Unknown4;
546 ULONG Unknown5;
547 ULONG PoolPagedBytes;
548 ULONG PoolNonPagedBytes;
549 ULONG Unknown6;
550 ULONG Unknown7;
551 ULONG Unknown8;
552 ULONG Unknown9;
553 ULONG MmTotalSystemFreePtes;
554 ULONG MmSystemCodepage;
555 ULONG MmTotalSystemDriverPages;
556 ULONG MmTotalSystemCodePages;
557 ULONG Unknown10;
558 ULONG Unknown11;
559 ULONG Unknown12;
560 ULONG MmSystemCachePage;
561 ULONG MmPagedPoolPage;
562 ULONG MmSystemDriverPage;
563 ULONG CcFastReadNoWait;
564 ULONG CcFastReadWait;
565 ULONG CcFastReadResourceMiss;
566 ULONG CcFastReadNotPossible;
567 ULONG CcFastMdlReadNoWait;
568 ULONG CcFastMdlReadWait;
569 ULONG CcFastMdlReadResourceMiss;
570 ULONG CcFastMdlReadNotPossible;
571 ULONG CcMapDataNoWait;
572 ULONG CcMapDataWait;
573 ULONG CcMapDataNoWaitMiss;
574 ULONG CcMapDataWaitMiss;
575 ULONG CcPinMappedDataCount;
576 ULONG CcPinReadNoWait;
577 ULONG CcPinReadWait;
578 ULONG CcPinReadNoWaitMiss;
579 ULONG CcPinReadWaitMiss;
580 ULONG CcCopyReadNoWait;
581 ULONG CcCopyReadWait;
582 ULONG CcCopyReadNoWaitMiss;
583 ULONG CcCopyReadWaitMiss;
584 ULONG CcMdlReadNoWait;
585 ULONG CcMdlReadWait;
586 ULONG CcMdlReadNoWaitMiss;
587 ULONG CcMdlReadWaitMiss;
588 ULONG CcReadaheadIos;
589 ULONG CcLazyWriteIos;
590 ULONG CcLazyWritePages;
591 ULONG CcDataFlushes;
592 ULONG CcDataPages;
593 ULONG ContextSwitches;
594 ULONG Unknown13;
595 ULONG Unknown14;
596 ULONG SystemCalls;
597 #endif
598 return EXIT_SUCCESS;
599 }
600
601
602 /**********************************************************************
603 *
604 * DESCRIPTION
605 *
606 * NOTE
607 * Class 3.
608 */
609 CMD_DEF(Time)
610 {
611 NTSTATUS Status;
612 SYSTEM_TIME_INFORMATION Info;
613
614 if (Application.Flag.Verbose)
615 {
616 printf ("SystemTimeInformation:\n");
617 }
618 Status = NtQuerySystemInformation (
619 SystemTimeInformation,
620 & Info,
621 sizeof Info,
622 NULL
623 );
624 if (STATUS_SUCCESS != Status)
625 {
626 PrintStatus (Status);
627 return EXIT_FAILURE;
628 }
629 PrintUtcDateTime ("\tKeBootTime : %s\n", & Info.KeBootTime);
630 PrintUtcDateTime ("\tKeSystemTime : %s\n", & Info.KeSystemTime);
631 PrintUtcDateTime ("\tExpTimeZoneBias: %s\n", & Info.ExpTimeZoneBias); /* FIXME */
632 printf ("\tExpTimeZoneId : %ld\n", Info.ExpTimeZoneId);
633 if (Application.Flag.Verbose)
634 {
635 printf ("\tUnused : %08x (?)\n", Info.Unused);
636 }
637
638 return EXIT_SUCCESS;
639 }
640
641
642 /**********************************************************************
643 *
644 * DESCRIPTION
645 *
646 * NOTE
647 * Class 4.
648 */
649 CMD_DEF(Path)
650 {
651 NTSTATUS Status;
652 SYSTEM_PATH_INFORMATION Info;
653 CHAR _Info [_MAX_PATH];
654 ULONG Length = 0;
655
656 RtlZeroMemory (& Info, _MAX_PATH);
657 Status = NtQuerySystemInformation (
658 SystemPathInformation,
659 & _Info,
660 _MAX_PATH,
661 & Length
662 );
663 if (STATUS_SUCCESS != Status)
664 {
665 PrintStatus (Status);
666 DumpData (_MAX_PATH, & _Info);
667 return EXIT_FAILURE;
668 }
669 DumpData (_MAX_PATH, & _Info);
670 return EXIT_SUCCESS;
671 }
672
673
674 /**********************************************************************
675 *
676 * DESCRIPTION
677 * A snapshot of the process+thread tables.
678 *
679 * NOTE
680 * Class 5.
681 */
682 CMD_DEF(Process)
683 {
684 NTSTATUS Status = STATUS_SUCCESS;
685 PSYSTEM_PROCESS_INFORMATION pInfo = NULL;
686 LONG Length = 0;
687 ULONG ThreadIndex;
688
689 pInfo = GlobalAlloc (GMEM_ZEROINIT, BUFFER_SIZE_DEFAULT);
690 /* FIXME: check NULL==pInfo */
691
692 if (Application.Flag.Verbose)
693 {
694 printf ("SystemProcessInformation:\n");
695 }
696 /*
697 * Obtain required buffer size
698 */
699 Status = NtQuerySystemInformation (
700 SystemProcessInformation,
701 pInfo,
702 BUFFER_SIZE_DEFAULT,
703 & Length
704 );
705 if (STATUS_SUCCESS != Status)
706 {
707 if (STATUS_INFO_LENGTH_MISMATCH == Status)
708 {
709 /*
710 * Allocate buffer
711 */
712 pInfo = GlobalReAlloc (pInfo, Length, GMEM_ZEROINIT);
713 if (NULL == pInfo)
714 {
715 printf ("\tCould not allocate memory.\n");
716 return EXIT_FAILURE;
717 }
718 }
719 else
720 {
721 PrintStatus (Status);
722 GlobalFree (pInfo);
723 return EXIT_FAILURE;
724 }
725 }
726 /*
727 * Get process+thread list from ntoskrnl.exe
728 */
729 Status = NtQuerySystemInformation (
730 SystemProcessInformation,
731 pInfo,
732 Length,
733 & Length
734 );
735 if (!NT_SUCCESS(Status))
736 {
737 PrintStatus (Status);
738 GlobalFree (pInfo);
739 return EXIT_FAILURE;
740 }
741
742 while (1)
743 {
744 wprintf (L"%s:\n", (pInfo->Name.Length ? pInfo->Name.Buffer : L"*idle*") );
745 if (Application.Flag.Verbose)
746 {
747 wprintf (L"\tRelativeOffset = 0x%08x\n", pInfo->RelativeOffset);
748 }
749 wprintf (L"\tThreads = %ld\n", pInfo->ThreadCount);
750 wprintf (L"\tHandles = %ld\n", pInfo->HandleCount);
751 wprintf (L"\tBasePriority = %ld\n", pInfo->BasePriority);
752 wprintf (L"\tPID = %ld\n", pInfo->ProcessId);
753 wprintf (L"\tPPID = %ld\n", pInfo->ParentProcessId);
754 wprintf (L"\tVirtualSize:\t\tWorkingSetSize:\n");
755 wprintf (L"\t\tPeak : %ld\t\t\tPeak : %ld\n",
756 pInfo->PeakVirtualSizeBytes,
757 pInfo->PeakWorkingSetSizeBytes
758 );
759 wprintf (L"\t\tTotal: %ld\t\t\tTotal: %ld\n",
760 pInfo->TotalVirtualSizeBytes,
761 pInfo->TotalWorkingSetSizeBytes
762 );
763 wprintf (L"\tPagedPoolUsage:\t\tNonPagedPoolUsage:\n");
764 wprintf (L"\t\tPeak : %ld\t\t\tPeak : %ld\n",
765 pInfo->PeakPagedPoolUsagePages,
766 pInfo->TotalPagedPoolUsagePages
767 );
768 wprintf (L"\t\tTotal: %ld\t\t\tTotal: %ld\n",
769 pInfo->PeakNonPagedPoolUsagePages,
770 pInfo->TotalNonPagedPoolUsagePages
771 );
772 wprintf (L"\tPageFileUsage:\n");
773 wprintf (L"\t\tPeak : %ld\n", pInfo->PeakPageFileUsageBytes);
774 wprintf (L"\t\tTotal: %ld\n", pInfo->TotalPageFileUsageBytes);
775
776 wprintf (L"\tPageFaultCount = %ld\n", pInfo->PageFaultCount);
777 wprintf (L"\tTotalPrivateBytes = %ld\n", pInfo->TotalPrivateBytes);
778 /* Threads */
779 for ( ThreadIndex = 0;
780 (ThreadIndex < pInfo->ThreadCount);
781 ThreadIndex ++
782 )
783 {
784 wprintf (L"\t%x in %x:\n",
785 pInfo->ThreadSysInfo[ThreadIndex].ClientId.UniqueThread,
786 pInfo->ThreadSysInfo[ThreadIndex].ClientId.UniqueProcess
787 );
788 PrintUtcDateTime (
789 "\t\tKernelTime = %s\n",
790 & (pInfo->ThreadSysInfo[ThreadIndex].KernelTime)
791 );
792 PrintUtcDateTime (
793 "\t\tUserTime = %s\n",
794 & (pInfo->ThreadSysInfo[ThreadIndex].UserTime)
795 );
796 PrintUtcDateTime (
797 "\t\tCreateTime = %s\n",
798 & (pInfo->ThreadSysInfo[ThreadIndex].CreateTime)
799 );
800 wprintf (L"\t\tTickCount = %ld\n",
801 pInfo->ThreadSysInfo[ThreadIndex].TickCount
802 );
803 wprintf (L"\t\tStartEIP = 0x%08x\n",
804 pInfo->ThreadSysInfo[ThreadIndex].StartEIP
805 );
806 /* CLIENT_ID ClientId; */
807 wprintf (L"\t\tDynamicPriority = %d\n",
808 pInfo->ThreadSysInfo[ThreadIndex].DynamicPriority
809 );
810 wprintf (L"\t\tBasePriority = %d\n",
811 pInfo->ThreadSysInfo[ThreadIndex].BasePriority
812 );
813 wprintf (L"\t\tnSwitches = %ld\n",
814 pInfo->ThreadSysInfo[ThreadIndex].nSwitches
815 );
816 wprintf (L"\t\tState = 0x%08x\n",
817 pInfo->ThreadSysInfo[ThreadIndex].State
818 );
819 wprintf (L"\t\tWaitReason = %ld\n",
820 pInfo->ThreadSysInfo[ThreadIndex].WaitReason
821 );
822 }
823 /* Next */
824 if (0 == pInfo->RelativeOffset)
825 {
826 break;
827 }
828 (ULONG) pInfo += pInfo->RelativeOffset;
829 }
830
831 DumpData (Length, pInfo);
832
833 GlobalFree (pInfo);
834
835 return EXIT_SUCCESS;
836 }
837
838
839 /**********************************************************************
840 *
841 * DESCRIPTION
842 *
843 * NOTE
844 * Class 6.
845 */
846 CMD_DEF(ServiceDescriptorTable)
847 {
848 NTSTATUS Status;
849 SYSTEM_SDT_INFORMATION Info;
850 ULONG Length = 0;
851
852 /* FIXME */
853 if (Application.Flag.Verbose)
854 {
855 printf ("SystemServiceDescriptorTableInfo:\n");
856 }
857 RtlZeroMemory (& Info, sizeof Info);
858 Status = NtQuerySystemInformation (
859 SystemServiceDescriptorTableInfo,
860 & Info,
861 sizeof Info,
862 & Length
863 );
864 if (STATUS_SUCCESS != Status)
865 {
866 PrintStatus (Status);
867 DumpData (Length, & Info);
868 return EXIT_FAILURE;
869 }
870 printf ("\tBufferLength = %ld\n", Info.BufferLength);
871 printf ("\tNumberOfSystemServiceTables = %ld\n", Info.NumberOfSystemServiceTables);
872 printf ("\tNumberOfServices = %ld\n", Info.NumberOfServices [0]);
873 printf ("\tServiceCounters = %ld\n", Info.ServiceCounters [0]);
874
875 DumpData (Length, & Info);
876
877 return EXIT_SUCCESS;
878 }
879
880
881 /**********************************************************************
882 *
883 * DESCRIPTION
884 *
885 * NOTE
886 * Class 7.
887 */
888 CMD_DEF(IoConfig)
889 {
890 NTSTATUS Status = STATUS_SUCCESS;
891 SYSTEM_IOCONFIG_INFORMATION Info;
892 ULONG Length = 0;
893
894 if (Application.Flag.Verbose)
895 {
896 printf ("SystemIoConfigInformation:\n");
897 }
898 Status = NtQuerySystemInformation (
899 SystemIoConfigInformation,
900 & Info,
901 sizeof Info,
902 & Length
903 );
904 if (STATUS_SUCCESS != Status)
905 {
906 PrintStatus (Status);
907 return EXIT_FAILURE;
908 }
909 printf ("\tDiskCount : %ld\n", Info.DiskCount);
910 printf ("\tFloppyCount : %ld\n", Info.FloppyCount);
911 printf ("\tCdRomCount : %ld\n", Info.CdRomCount);
912 printf ("\tTapeCount : %ld\n", Info.TapeCount);
913 printf ("\tSerialCount : %ld\n", Info.SerialCount);
914 printf ("\tParallelCount: %ld\n", Info.ParallelCount);
915
916 DumpData (Length, & Info);
917
918 return EXIT_SUCCESS;
919 }
920
921
922 /**********************************************************************
923 *
924 * DESCRIPTION
925 *
926 * NOTE
927 * Class 8.
928 */
929 CMD_DEF(ProcessorTime)
930 {
931 NTSTATUS Status;
932 SYSTEM_PROCESSORTIME_INFO Info;
933 ULONG Length = 0;
934
935 if (Application.Flag.Verbose)
936 {
937 printf ("SystemProcessorTimeInformation:\n");
938 }
939 Status = NtQuerySystemInformation (
940 SystemProcessorTimeInformation,
941 & Info,
942 sizeof Info,
943 & Length
944 );
945 if (STATUS_SUCCESS != Status)
946 {
947 PrintStatus (Status);
948 return EXIT_FAILURE;
949 }
950 PrintUtcDateTime ("\tTotalProcessorRunTime : %s\n", & Info.TotalProcessorRunTime);
951 PrintUtcDateTime ("\tTotalProcessorTime : %s\n", & Info.TotalProcessorTime);
952 PrintUtcDateTime ("\tTotalProcessorUserTime: %s\n", & Info.TotalProcessorUserTime);
953 PrintUtcDateTime ("\tTotalDPCTime : %s\n", & Info.TotalDPCTime);
954 PrintUtcDateTime ("\tTotalInterruptTime : %s\n", & Info.TotalInterruptTime);
955 printf ("\tTotalInterrupts : %ld\n", Info.TotalInterrupts);
956 if (Application.Flag.Verbose)
957 {
958 printf ("\tUnused : %08x\n", Info.Unused);
959 }
960
961 return EXIT_SUCCESS;
962 }
963
964
965 /**********************************************************************
966 *
967 * DESCRIPTION
968 *
969 * NOTE
970 * Class 9.
971 */
972 CMD_DEF(NtGlobalFlag)
973 {
974 NTSTATUS Status;
975 SYSTEM_GLOBAL_FLAG_INFO Info;
976 ULONG Length = 0;
977
978 if (Application.Flag.Verbose)
979 {
980 printf ("SystemNtGlobalFlagInformation:\n");
981 }
982 Status = NtQuerySystemInformation (
983 SystemNtGlobalFlagInformation,
984 & Info,
985 sizeof Info,
986 & Length
987 );
988 if (STATUS_SUCCESS != Status)
989 {
990 PrintStatus (Status);
991 return EXIT_FAILURE;
992 }
993 printf ("\tNtGlobalFlag: %08x\n", Info.NtGlobalFlag);
994 /* FIXME: decode each flag */
995
996 return EXIT_SUCCESS;
997 }
998
999
1000 /**********************************************************************
1001 *
1002 * DESCRIPTION
1003 *
1004 * NOTE
1005 * Class 10.
1006 */
1007 CMD_DEF(10)
1008 CMD_NOT_IMPLEMENTED
1009
1010
1011 /**********************************************************************
1012 *
1013 * DESCRIPTION
1014 *
1015 * NOTE
1016 * Class 11.
1017 *
1018 * NOTE
1019 * Code originally in Yariv Kaplan's NtDriverList,
1020 * at http://www.internals.com/, adapted to ReactOS
1021 * structures layout.
1022 */
1023 CMD_DEF(Module)
1024 {
1025 NTSTATUS Status = STATUS_SUCCESS;
1026 PSYSTEM_MODULE_INFORMATION pInfo = NULL;
1027 LONG Length = 0;
1028 INT Index;
1029 const PCHAR hr =
1030 "-------- -------- -------- ---------------------------------------\n";
1031
1032
1033 if (Application.Flag.Verbose)
1034 {
1035 printf ("SystemModuleInformation:\n");
1036 }
1037 /*
1038 * Obtain required buffer size
1039 */
1040 Status = NtQuerySystemInformation (
1041 SystemModuleInformation,
1042 & pInfo,
1043 0, /* query size */
1044 & Length
1045 );
1046 if (STATUS_INFO_LENGTH_MISMATCH == Status)
1047 {
1048 /*
1049 * Allocate buffer
1050 */
1051 pInfo = GlobalAlloc (GMEM_ZEROINIT, Length);
1052 if (NULL == pInfo)
1053 {
1054 printf ("Could not allocate memory.\n");
1055 return EXIT_FAILURE;
1056 }
1057 }
1058 else
1059 {
1060 PrintStatus (Status);
1061 return EXIT_FAILURE;
1062 }
1063 /*
1064 * Get module list from ntoskrnl.exe
1065 */
1066 Status = NtQuerySystemInformation (
1067 SystemModuleInformation,
1068 pInfo,
1069 Length,
1070 & Length
1071 );
1072 if (!NT_SUCCESS(Status))
1073 {
1074 PrintStatus (Status);
1075 return EXIT_FAILURE;
1076 }
1077 printf ("Index Address Size Name\n");
1078 printf (hr);
1079
1080 for ( Index = 0;
1081 (Index < (int) pInfo->Count);
1082 Index ++
1083 )
1084 {
1085 printf (
1086 "%8x %08x %8x %s\n",
1087 pInfo->Module[Index].ModuleEntryIndex,
1088 pInfo->Module[Index].ModuleBaseAddress,
1089 pInfo->Module[Index].ModuleSize,
1090 pInfo->Module[Index].ModuleName
1091 );
1092 }
1093 printf (hr);
1094
1095 GlobalFree (pInfo);
1096
1097 return EXIT_SUCCESS;
1098 }
1099
1100
1101 /**********************************************************************
1102 *
1103 * DESCRIPTION
1104 *
1105 * NOTE
1106 * Class 12.
1107 */
1108 CMD_DEF(ResourceLock)
1109 {
1110 NTSTATUS Status = STATUS_SUCCESS;
1111 PSYSTEM_RESOURCE_LOCK_INFO pInfo = NULL;
1112 LONG Length = 0;
1113 INT Index;
1114 const PCHAR hr =
1115 "-------- -------- -------- -------- -------- -------- ------------\n";
1116
1117 pInfo = GlobalAlloc (GMEM_ZEROINIT, BUFFER_SIZE_DEFAULT);
1118 /* FIXME: check NULL==pInfo */
1119
1120 if (Application.Flag.Verbose)
1121 {
1122 printf ("SystemResourceLockInformation:\n");
1123 }
1124 /*
1125 * Obtain required buffer size
1126 */
1127 Status = NtQuerySystemInformation (
1128 SystemResourceLockInformation,
1129 pInfo,
1130 BUFFER_SIZE_DEFAULT, /* query size */
1131 & Length
1132 );
1133 if (STATUS_SUCCESS != Status)
1134 {
1135 if (STATUS_INFO_LENGTH_MISMATCH == Status)
1136 {
1137 /*
1138 * Allocate buffer
1139 */
1140 pInfo = GlobalReAlloc (pInfo, Length, GMEM_ZEROINIT);
1141 if (NULL == pInfo)
1142 {
1143 printf ("Could not allocate memory.\n");
1144 return EXIT_FAILURE;
1145 }
1146 }
1147 else
1148 {
1149 PrintStatus (Status);
1150 GlobalFree (pInfo);
1151 return EXIT_FAILURE;
1152 }
1153 }
1154 /*
1155 * Get locked resource list from ntoskrnl.exe
1156 */
1157 Status = NtQuerySystemInformation (
1158 SystemResourceLockInformation,
1159 pInfo,
1160 Length,
1161 & Length
1162 );
1163 if (!NT_SUCCESS(Status))
1164 {
1165 PrintStatus (Status);
1166 GlobalFree (pInfo);
1167 return EXIT_FAILURE;
1168 }
1169 printf ("Address Active # Content# Sh/Wait Exc/Wait\n");
1170 printf (hr);
1171
1172 for ( Index = 0;
1173 (Index < (int) pInfo->Count);
1174 Index ++
1175 )
1176 {
1177 printf (
1178 "%08x %8ld %8ld %8ld %8ld %08x\n",
1179 pInfo->Lock[Index].ResourceAddress,
1180 pInfo->Lock[Index].ActiveCount,
1181 pInfo->Lock[Index].ContentionCount,
1182 pInfo->Lock[Index].NumberOfSharedWaiters,
1183 pInfo->Lock[Index].NumberOfExclusiveWaiters,
1184 pInfo->Lock[Index].Unknown
1185 );
1186 }
1187 printf (hr);
1188
1189 GlobalFree (pInfo);
1190
1191 return EXIT_SUCCESS;
1192 }
1193
1194
1195 /**********************************************************************
1196 *
1197 * DESCRIPTION
1198 *
1199 * NOTE
1200 * Class 13.
1201 */
1202 CMD_DEF(13)
1203 CMD_NOT_IMPLEMENTED
1204
1205
1206 /**********************************************************************
1207 *
1208 * DESCRIPTION
1209 *
1210 * NOTE
1211 * Class 14.
1212 */
1213 CMD_DEF(14)
1214 CMD_NOT_IMPLEMENTED
1215
1216
1217 /**********************************************************************
1218 *
1219 * DESCRIPTION
1220 *
1221 * NOTE
1222 * Class 15.
1223 */
1224 CMD_DEF(15)
1225 CMD_NOT_IMPLEMENTED
1226
1227
1228 /**********************************************************************
1229 *
1230 * DESCRIPTION
1231 *
1232 * NOTE
1233 * Class 16. You can not pass 0 as the initial output buffer's
1234 * size to get back the needed buffer size.
1235 */
1236 CMD_DEF(Handle)
1237 {
1238 NTSTATUS Status = STATUS_SUCCESS;
1239 PSYSTEM_HANDLE_INFORMATION pInfo = NULL;
1240 LONG Length = 0;
1241 INT Index;
1242 const PCHAR hr =
1243 "-------- -------- -------- -------- -------- ----------\n";
1244 CHAR FlagsString [9] = {0};
1245
1246 pInfo = GlobalAlloc (GMEM_ZEROINIT, BUFFER_SIZE_DEFAULT);
1247
1248 if (Application.Flag.Verbose)
1249 {
1250 printf ("SystemHandleInformation:\n");
1251 }
1252 /*
1253 * Obtain required buffer size
1254 */
1255 Status = NtQuerySystemInformation (
1256 SystemHandleInformation,
1257 pInfo,
1258 BUFFER_SIZE_DEFAULT,
1259 & Length
1260 );
1261 if (STATUS_SUCCESS != Status)
1262 {
1263 if (STATUS_INFO_LENGTH_MISMATCH == Status)
1264 {
1265 /*
1266 * Allocate buffer
1267 */
1268 pInfo = GlobalReAlloc (pInfo, Length, GMEM_ZEROINIT);
1269 if (NULL == pInfo)
1270 {
1271 printf ("\tCould not allocate memory.\n");
1272 return EXIT_FAILURE;
1273 }
1274 }
1275 else
1276 {
1277 PrintStatus (Status);
1278 GlobalFree (pInfo);
1279 return EXIT_FAILURE;
1280 }
1281 }
1282 /*
1283 * Get handle table from ntoskrnl.exe
1284 */
1285 Status = NtQuerySystemInformation (
1286 SystemHandleInformation,
1287 pInfo,
1288 Length,
1289 & Length
1290 );
1291 if (!NT_SUCCESS(Status))
1292 {
1293 PrintStatus (Status);
1294 GlobalFree (pInfo);
1295 return EXIT_FAILURE;
1296 }
1297 printf ("Handle OwnerPID ObjPtr Access Flags Type\n");
1298 printf (hr);
1299
1300 for ( Index = 0;
1301 (Index < (int) pInfo->Count);
1302 Index ++
1303 )
1304 {
1305 printf (
1306 "%8x %8x %8x %8x %s %s\n",
1307 pInfo->Handle[Index].HandleValue,
1308 pInfo->Handle[Index].OwnerPid,
1309 pInfo->Handle[Index].ObjectPointer,
1310 pInfo->Handle[Index].AccessMask,
1311 ByteToBinaryString (
1312 pInfo->Handle[Index].HandleFlags,
1313 FlagsString
1314 ),
1315 HandleTypeToObjectName (pInfo->Handle[Index].ObjectType)
1316 );
1317 }
1318 printf (hr);
1319
1320 DumpData (Length, pInfo);
1321
1322 GlobalFree (pInfo);
1323
1324 return EXIT_SUCCESS;
1325 }
1326
1327
1328 /**********************************************************************
1329 *
1330 * DESCRIPTION
1331 *
1332 * NOTE
1333 * Class 17.
1334 */
1335 CMD_DEF(Object)
1336 CMD_NOT_IMPLEMENTED
1337
1338
1339 /**********************************************************************
1340 *
1341 * DESCRIPTION
1342 *
1343 * NOTE
1344 * Class 18.
1345 */
1346 CMD_DEF(PageFile)
1347 {
1348 NTSTATUS Status;
1349 PSYSTEM_PAGEFILE_INFORMATION pInfo = NULL;
1350 LONG Length = 0;
1351
1352 pInfo = GlobalAlloc (GMEM_ZEROINIT, BUFFER_SIZE_DEFAULT);
1353 /* FIXME: check pInfo */
1354
1355 if (Application.Flag.Verbose)
1356 {
1357 printf ("SystemPageFileInformation:\n");
1358 }
1359 Status = NtQuerySystemInformation(
1360 SystemPageFileInformation,
1361 pInfo,
1362 BUFFER_SIZE_DEFAULT,
1363 & Length
1364 );
1365 if (STATUS_SUCCESS != Status)
1366 {
1367 if (STATUS_INFO_LENGTH_MISMATCH == Status)
1368 {
1369 /*
1370 * Allocate buffer
1371 */
1372 pInfo = GlobalReAlloc (pInfo, Length, GMEM_ZEROINIT);
1373 if (NULL == pInfo)
1374 {
1375 printf ("Could not allocate memory.\n");
1376 return EXIT_FAILURE;
1377 }
1378 }
1379 else
1380 {
1381 PrintStatus (Status);
1382 GlobalFree (pInfo);
1383 return EXIT_FAILURE;
1384 }
1385 }
1386 Status = NtQuerySystemInformation (
1387 SystemPageFileInformation,
1388 pInfo,
1389 Length,
1390 & Length
1391 );
1392 if (!NT_SUCCESS(Status))
1393 {
1394 PrintStatus (Status);
1395 GlobalFree (pInfo);
1396 return EXIT_FAILURE;
1397 }
1398
1399 while (1)
1400 {
1401 wprintf (L"\t\"%s\":\n", pInfo->PagefileFileName.Buffer);
1402 if (Application.Flag.Verbose)
1403 {
1404 wprintf (L"\t\tRelativeOffset = %08x\n", pInfo->RelativeOffset);
1405 }
1406 wprintf (L"\t\tCurrentSizePages = %ld\n", pInfo->CurrentSizePages);
1407 wprintf (L"\t\tTotalUsedPages = %ld\n", pInfo->TotalUsedPages);
1408 wprintf (L"\t\tPeakUsedPages = %ld\n", pInfo->PeakUsedPages);
1409
1410 if (0 == pInfo->RelativeOffset)
1411 {
1412 break;
1413 }
1414 printf ("\n");
1415 (ULONG) pInfo += pInfo->RelativeOffset;
1416 }
1417
1418 DumpData (Length, pInfo);
1419
1420 GlobalFree (pInfo);
1421
1422 return EXIT_SUCCESS;
1423 }
1424
1425
1426 /**********************************************************************
1427 *
1428 * DESCRIPTION
1429 *
1430 * NOTE
1431 * Class 19.
1432 */
1433 CMD_DEF(InstructionEmulation)
1434 {
1435 NTSTATUS Status;
1436 SYSTEM_VDM_INFORMATION Info;
1437
1438 if (Application.Flag.Verbose)
1439 {
1440 printf ("SystemInstructionEmulationInfo:\n");
1441 }
1442 RtlZeroMemory (& Info, sizeof Info);
1443 Status = NtQuerySystemInformation (
1444 SystemInstructionEmulationInfo,
1445 & Info,
1446 sizeof Info,
1447 NULL
1448 );
1449 if (!NT_SUCCESS(Status))
1450 {
1451 PrintStatus (Status);
1452 return EXIT_FAILURE;
1453 }
1454 printf ("\tVdmSegmentNotPresentCount = %ld\n", Info.VdmSegmentNotPresentCount);
1455 printf ("\tVdmINSWCount = %ld\n", Info.VdmINSWCount);
1456 printf ("\tVdmESPREFIXCount = %ld\n", Info.VdmESPREFIXCount);
1457 printf ("\tVdmCSPREFIXCount = %ld\n", Info.VdmCSPREFIXCount);
1458 printf ("\tVdmSSPREFIXCount = %ld\n", Info.VdmSSPREFIXCount);
1459 printf ("\tVdmDSPREFIXCount = %ld\n", Info.VdmDSPREFIXCount);
1460 printf ("\tVdmFSPREFIXCount = %ld\n", Info.VdmFSPREFIXCount);
1461 printf ("\tVdmGSPREFIXCount = %ld\n", Info.VdmGSPREFIXCount);
1462 printf ("\tVdmOPER32PREFIXCount = %ld\n", Info.VdmOPER32PREFIXCount);
1463 printf ("\tVdmADDR32PREFIXCount = %ld\n", Info.VdmADDR32PREFIXCount);
1464 printf ("\tVdmINSBCount = %ld\n", Info.VdmINSBCount);
1465 printf ("\tVdmINSWV86Count = %ld\n", Info.VdmINSWV86Count);
1466 printf ("\tVdmOUTSBCount = %ld\n", Info.VdmOUTSBCount);
1467 printf ("\tVdmOUTSWCount = %ld\n", Info.VdmOUTSWCount);
1468 printf ("\tVdmPUSHFCount = %ld\n", Info.VdmPUSHFCount);
1469 printf ("\tVdmPOPFCount = %ld\n", Info.VdmPOPFCount);
1470 printf ("\tVdmINTNNCount = %ld\n", Info.VdmINTNNCount);
1471 printf ("\tVdmINTOCount = %ld\n", Info.VdmINTOCount);
1472 printf ("\tVdmIRETCount = %ld\n", Info.VdmIRETCount);
1473 printf ("\tVdmINBIMMCount = %ld\n", Info.VdmINBIMMCount);
1474 printf ("\tVdmINWIMMCount = %ld\n", Info.VdmINWIMMCount);
1475 printf ("\tVdmOUTBIMMCount = %ld\n", Info.VdmOUTBIMMCount);
1476 printf ("\tVdmOUTWIMMCount = %ld\n", Info.VdmOUTWIMMCount);
1477 printf ("\tVdmINBCount = %ld\n", Info.VdmINBCount);
1478 printf ("\tVdmINWCount = %ld\n", Info.VdmINWCount);
1479 printf ("\tVdmOUTBCount = %ld\n", Info.VdmOUTBCount);
1480 printf ("\tVdmOUTWCount = %ld\n", Info.VdmOUTWCount);
1481 printf ("\tVdmLOCKPREFIXCount = %ld\n", Info.VdmLOCKPREFIXCount);
1482 printf ("\tVdmREPNEPREFIXCount = %ld\n", Info.VdmREPNEPREFIXCount);
1483 printf ("\tVdmREPPREFIXCount = %ld\n", Info.VdmREPPREFIXCount);
1484 printf ("\tVdmHLTCount = %ld\n", Info.VdmHLTCount);
1485 printf ("\tVdmCLICount = %ld\n", Info.VdmCLICount);
1486 printf ("\tVdmSTICount = %ld\n", Info.VdmSTICount);
1487 printf ("\tVdmBopCount = %ld\n", Info.VdmBopCount);
1488
1489 return EXIT_SUCCESS;
1490 }
1491
1492
1493 /**********************************************************************
1494 *
1495 * DESCRIPTION
1496 *
1497 * NOTE
1498 * Class 20.
1499 */
1500 CMD_DEF(20)
1501 CMD_NOT_IMPLEMENTED
1502
1503
1504 /**********************************************************************
1505 *
1506 * DESCRIPTION
1507 *
1508 * NOTE
1509 * Class 21.
1510 */
1511 CMD_DEF(Cache)
1512 {
1513 NTSTATUS Status;
1514 SYSTEM_CACHE_INFORMATION Si;
1515
1516 if (Application.Flag.Verbose)
1517 {
1518 printf ("SystemCacheInformation:\n");
1519 }
1520 RtlZeroMemory (
1521 (PVOID) & Si,
1522 sizeof Si
1523 );
1524 Status = NtQuerySystemInformation (
1525 SystemCacheInformation,
1526 & Si,
1527 sizeof Si,
1528 0
1529 );
1530 if (!NT_SUCCESS(Status))
1531 {
1532 PrintStatus (Status);
1533 return EXIT_FAILURE;
1534 }
1535 printf ("\tSize:\n");
1536 printf ("\t\tCurrent = %ld\n", Si.CurrentSize);
1537 printf ("\t\tPeak = %ld\n\n", Si.PeakSize);
1538 printf ("\tPageFaults:\n\t\tCount = %ld\n\n", Si.PageFaultCount);
1539 printf ("\tWorking Set:\n");
1540 printf ("\t\tMinimum = %ld\n", Si.MinimumWorkingSet );
1541 printf ("\t\tMaximum = %ld\n", Si.MaximumWorkingSet );
1542
1543 return EXIT_SUCCESS;
1544 }
1545
1546
1547 /**********************************************************************
1548 *
1549 * DESCRIPTION
1550 * Get statistic data about tagged pools. Not implemented in the
1551 * free build.
1552 *
1553 * NOTE
1554 * Class 22.
1555 */
1556 CMD_DEF(PoolTag)
1557 {
1558 NTSTATUS Status;
1559 PSYSTEM_POOL_TAG_INFO pInfo = NULL;
1560 ULONG Length;
1561 ULONG PoolIndex;
1562
1563 pInfo = GlobalAlloc (GMEM_ZEROINIT, BUFFER_SIZE_DEFAULT);
1564 /* FIXME: check pInfo */
1565
1566 if (Application.Flag.Verbose)
1567 {
1568 printf ("SystemPoolTagInformation:\n");
1569 }
1570 Status = NtQuerySystemInformation(
1571 SystemPoolTagInformation,
1572 pInfo,
1573 BUFFER_SIZE_DEFAULT,
1574 & Length
1575 );
1576 if (STATUS_SUCCESS != Status)
1577 {
1578 if (STATUS_INFO_LENGTH_MISMATCH == Status)
1579 {
1580 /*
1581 * Allocate buffer
1582 */
1583 pInfo = GlobalReAlloc (pInfo, Length, GMEM_ZEROINIT);
1584 if (NULL == pInfo)
1585 {
1586 printf ("Could not allocate memory.\n");
1587 return EXIT_FAILURE;
1588 }
1589 }
1590 else
1591 {
1592 PrintStatus (Status);
1593 GlobalFree (pInfo);
1594 return EXIT_FAILURE;
1595 }
1596 }
1597 Status = NtQuerySystemInformation (
1598 SystemPoolTagInformation,
1599 pInfo,
1600 Length,
1601 & Length
1602 );
1603 if (!NT_SUCCESS(Status))
1604 {
1605 PrintStatus (Status);
1606 GlobalFree (pInfo);
1607 return EXIT_FAILURE;
1608 }
1609
1610 for ( PoolIndex = 0;
1611 (PoolIndex < pInfo->Count);
1612 PoolIndex ++
1613 )
1614 {
1615 wprintf (L"\t%08x:\n", pInfo->PoolEntry[PoolIndex].Tag);
1616 wprintf (L"\t\tPaged:\t\tNon Paged:\n");
1617 wprintf (
1618 L"\t\tAllocationCount = %ld\tAllocationCount = %ld\n",
1619 pInfo->PoolEntry[PoolIndex].Paged.AllocationCount,
1620 pInfo->PoolEntry[PoolIndex].NonPaged.AllocationCount
1621 );
1622 wprintf (
1623 L"\t\tFreeCount = %ld\tFreeCount = %ld\n",
1624 pInfo->PoolEntry[PoolIndex].Paged.FreeCount,
1625 pInfo->PoolEntry[PoolIndex].NonPaged.FreeCount
1626 );
1627 wprintf (
1628 L"\t\tSizeBytes = %ld\tSizeBytes = %ld\n",
1629 pInfo->PoolEntry[PoolIndex].Paged.SizeBytes,
1630 pInfo->PoolEntry[PoolIndex].NonPaged.SizeBytes
1631 );
1632 }
1633
1634 DumpData (Length, pInfo);
1635
1636 GlobalFree (pInfo);
1637
1638 return EXIT_SUCCESS;
1639 }
1640
1641
1642 /**********************************************************************
1643 *
1644 * DESCRIPTION
1645 *
1646 * NOTE
1647 * Class 23.
1648 */
1649 CMD_DEF(ProcessorSchedule)
1650 {
1651 NTSTATUS Status;
1652 SYSTEM_PROCESSOR_SCHEDULE_INFO Info;
1653
1654 if (Application.Flag.Verbose)
1655 {
1656 printf ("SystemProcessorScheduleInfo:\n");
1657 }
1658 RtlZeroMemory (
1659 & Info,
1660 sizeof Info
1661 );
1662 Status = NtQuerySystemInformation (
1663 SystemProcessorScheduleInfo,
1664 & Info,
1665 sizeof Info,
1666 NULL
1667 );
1668 if (STATUS_SUCCESS != Status)
1669 {
1670 PrintStatus (Status);
1671 return EXIT_FAILURE;
1672 }
1673
1674 printf ("\tnContextSwitches = %ld\n", Info.nContextSwitches);
1675 printf ("\tnDPCQueued = %ld\n", Info.nDPCQueued);
1676 printf ("\tnDPCRate = %ld\n", Info.nDPCRate);
1677 printf ("\tTimerResolution = %ld\n", Info.TimerResolution);
1678 printf ("\tnDPCBypasses = %ld\n", Info.nDPCBypasses);
1679 printf ("\tnAPCBypasses = %ld\n", Info.nAPCBypasses);
1680
1681 DumpData (sizeof Info, & Info);
1682
1683 return EXIT_SUCCESS;
1684
1685 }
1686
1687
1688 /**********************************************************************
1689 *
1690 * DESCRIPTION
1691 *
1692 * NOTE
1693 * Class 24.
1694 */
1695 CMD_DEF(Dpc)
1696 {
1697 NTSTATUS Status;
1698 SYSTEM_DPC_INFORMATION Info;
1699
1700 if (Application.Flag.Verbose)
1701 {
1702 printf ("SystemDpcInformation:\n");
1703 }
1704 RtlZeroMemory (
1705 & Info,
1706 sizeof Info
1707 );
1708 Status = NtQuerySystemInformation (
1709 SystemDpcInformation,
1710 & Info,
1711 sizeof Info,
1712 NULL
1713 );
1714 if (STATUS_SUCCESS != Status)
1715 {
1716 PrintStatus (Status);
1717 return EXIT_FAILURE;
1718 }
1719
1720 if (Application.Flag.Verbose)
1721 {
1722 printf ("\tUnused = %ld\n", Info.Unused);
1723 }
1724 printf ("\tKiMaximumDpcQueueDepth = %ld\n", Info.KiMaximumDpcQueueDepth);
1725 printf ("\tKiMinimumDpcRate = %ld\n", Info.KiMinimumDpcRate);
1726 printf ("\tKiAdjustDpcThreshold = %ld\n", Info.KiAdjustDpcThreshold);
1727 printf ("\tKiIdealDpcRate = %ld\n", Info.KiIdealDpcRate);
1728
1729 DumpData (sizeof Info, & Info);
1730
1731 return EXIT_SUCCESS;
1732 }
1733
1734
1735 /**********************************************************************
1736 *
1737 * DESCRIPTION
1738 *
1739 * NOTE
1740 * Class 25.
1741 */
1742 CMD_DEF(25)
1743 CMD_NOT_IMPLEMENTED
1744
1745
1746 /**********************************************************************
1747 *
1748 * DESCRIPTION
1749 *
1750 * NOTE
1751 * Class 26.
1752 */
1753 INT CMD_LoadImage (INT argc, LPCSTR argv [])
1754 CMD_NOT_IMPLEMENTED
1755
1756 /**********************************************************************
1757 *
1758 * DESCRIPTION
1759 *
1760 * NOTE
1761 * Class 27.
1762 */
1763 CMD_DEF(UnloadImage)
1764 CMD_NOT_IMPLEMENTED
1765
1766
1767 /**********************************************************************
1768 *
1769 * DESCRIPTION
1770 *
1771 * NOTE
1772 * Class 28.
1773 */
1774 CMD_DEF(TimeAdjustment)
1775 {
1776 NTSTATUS Status = STATUS_SUCCESS;
1777 SYSTEM_TIME_ADJUSTMENT_INFO Info;
1778
1779 if (Application.Flag.Verbose)
1780 {
1781 printf ("SystemTimeAdjustmentInformation:\n");
1782 }
1783 RtlZeroMemory (& Info, sizeof Info);
1784 Status = NtQuerySystemInformation (
1785 SystemTimeAdjustmentInformation,
1786 & Info,
1787 sizeof Info,
1788 0
1789 );
1790 if (!NT_SUCCESS(Status))
1791 {
1792 PrintStatus (Status);
1793 return EXIT_FAILURE;
1794 }
1795 printf ("\tKeTimeAdjustment = %ld\n", Info.KeTimeAdjustment);
1796 printf ("\tKeMaximumIncrement = %ld\n", Info.KeMaximumIncrement);
1797 printf ("\tKeTimeSynchronization = %s\n", TF(Info.KeTimeSynchronization));
1798
1799 return EXIT_SUCCESS;
1800 }
1801
1802
1803 /**********************************************************************
1804 *
1805 * DESCRIPTION
1806 *
1807 * NOTE
1808 * Class 29.
1809 */
1810 CMD_DEF(29)
1811 CMD_NOT_IMPLEMENTED
1812
1813
1814 /**********************************************************************
1815 *
1816 * DESCRIPTION
1817 *
1818 * NOTE
1819 * Class 30.
1820 */
1821 CMD_DEF(30)
1822 CMD_NOT_IMPLEMENTED
1823
1824
1825 /**********************************************************************
1826 *
1827 * DESCRIPTION
1828 *
1829 * NOTE
1830 * Class 31.
1831 */
1832 CMD_DEF(31)
1833 CMD_NOT_IMPLEMENTED
1834
1835
1836 /**********************************************************************
1837 *
1838 * DESCRIPTION
1839 *
1840 * NOTE
1841 * Class 32.
1842 */
1843 CMD_DEF(CrashDumpSection)
1844 CMD_NOT_IMPLEMENTED
1845
1846
1847 /**********************************************************************
1848 *
1849 * DESCRIPTION
1850 *
1851 * NOTE
1852 * Class 33.
1853 */
1854 CMD_DEF(ProcessorFaultCount)
1855 CMD_NOT_IMPLEMENTED
1856
1857
1858 /**********************************************************************
1859 *
1860 * DESCRIPTION
1861 *
1862 * NOTE
1863 * Class 34.
1864 */
1865 CMD_DEF(CrashDumpState)
1866 CMD_NOT_IMPLEMENTED
1867
1868
1869 /**********************************************************************
1870 *
1871 * DESCRIPTION
1872 *
1873 * NOTE
1874 * Class 35.
1875 */
1876 CMD_DEF(Debugger)
1877 {
1878 NTSTATUS Status;
1879 SYSTEM_DEBUGGER_INFO Info;
1880
1881 RtlZeroMemory (& Info, sizeof Info);
1882 Status = NtQuerySystemInformation (
1883 SystemDebuggerInformation,
1884 & Info,
1885 sizeof Info,
1886 NULL
1887 );
1888 if (STATUS_SUCCESS != Status)
1889 {
1890 PrintStatus (Status);
1891 return EXIT_FAILURE;
1892 }
1893 printf ("\tKdDebuggerEnabled = %s\n", TF(Info.KdDebuggerEnabled));
1894 printf ("\tKdDebuggerPresent = %s\n", TF(Info.KdDebuggerPresent));
1895
1896 DumpData (sizeof Info, & Info);
1897
1898 return EXIT_SUCCESS;
1899 }
1900
1901
1902 /**********************************************************************
1903 *
1904 * DESCRIPTION
1905 *
1906 * NOTE
1907 * Class 36.
1908 */
1909 CMD_DEF(ThreadSwitchCounters)
1910 CMD_NOT_IMPLEMENTED
1911
1912
1913 /**********************************************************************
1914 *
1915 * DESCRIPTION
1916 *
1917 * NOTE
1918 * Class 37.
1919 */
1920 CMD_DEF(Quota)
1921 {
1922 NTSTATUS Status = STATUS_SUCCESS;
1923 SYSTEM_QUOTA_INFORMATION Info;
1924
1925 if (Application.Flag.Verbose)
1926 {
1927 printf ("SystemQuotaInformation:\n");
1928 }
1929 RtlZeroMemory (& Info, sizeof Info);
1930 Status = NtQuerySystemInformation (
1931 SystemQuotaInformation,
1932 & Info,
1933 sizeof Info,
1934 0
1935 );
1936 if (!NT_SUCCESS(Status))
1937 {
1938 PrintStatus (Status);
1939 return EXIT_FAILURE;
1940 }
1941 printf ("\tCmpGlobalQuota = %ld\n", Info.CmpGlobalQuota);
1942 printf ("\tCmpGlobalQuotaUsed = %ld\n", Info.CmpGlobalQuotaUsed);
1943 printf ("\tMmSizeofPagedPoolInBytes = %ld\n", Info.MmSizeofPagedPoolInBytes);
1944
1945 return EXIT_SUCCESS;
1946 }
1947
1948
1949 /**********************************************************************
1950 *
1951 * DESCRIPTION
1952 *
1953 * NOTE
1954 * Class 38.
1955 */
1956 CMD_DEF(LoadDriver)
1957 CMD_NOT_IMPLEMENTED
1958
1959
1960 /**********************************************************************
1961 *
1962 * DESCRIPTION
1963 *
1964 * NOTE
1965 * Class 39.
1966 */
1967 CMD_DEF(PrioritySeparation)
1968 CMD_NOT_IMPLEMENTED
1969
1970
1971 /**********************************************************************
1972 *
1973 * DESCRIPTION
1974 *
1975 * NOTE
1976 * Class 40.
1977 */
1978 CMD_DEF(40)
1979 CMD_NOT_IMPLEMENTED
1980
1981
1982 /**********************************************************************
1983 *
1984 * DESCRIPTION
1985 *
1986 * NOTE
1987 * Class 41.
1988 */
1989 CMD_DEF(41)
1990 CMD_NOT_IMPLEMENTED
1991
1992
1993 /**********************************************************************
1994 *
1995 * DESCRIPTION
1996 *
1997 * NOTE
1998 * Class 42.
1999 */
2000 CMD_DEF(42)
2001 CMD_NOT_IMPLEMENTED
2002
2003
2004 /**********************************************************************
2005 *
2006 * DESCRIPTION
2007 *
2008 * NOTE
2009 * Class 43.
2010 */
2011 CMD_DEF(43)
2012 CMD_NOT_IMPLEMENTED
2013
2014
2015 /**********************************************************************
2016 *
2017 * DESCRIPTION
2018 * Dump the system TIME_ZONE_INFORMATION object.
2019 *
2020 * NOTE
2021 * Class 44.
2022 */
2023 CMD_DEF(TimeZone)
2024 {
2025 #if 0
2026 NTSTATUS Status;
2027 TIME_ZONE_INFORMATION Tzi;
2028 WCHAR Name [33];
2029
2030 if (Application.Flag.Verbose)
2031 {
2032 printf ("SystemTimeZoneInformation:\n");
2033 }
2034 RtlZeroMemory (& Tzi, sizeof Tzi);
2035 Status = NtQuerySystemInformation(
2036 SystemTimeZoneInformation,
2037 & Tzi,
2038 sizeof Tzi,
2039 0
2040 );
2041 if (!NT_SUCCESS(Status))
2042 {
2043 PrintStatus (Status);
2044 return EXIT_FAILURE;
2045 }
2046 printf (
2047 "12h/24h.....: %dh\n",
2048 0 /* FIXME: */
2049 );
2050 printf (
2051 "Bias........: %d'\n",
2052 Tzi.Bias /* LONG */
2053 );
2054
2055 printf ("Standard\n");
2056 RtlZeroMemory (
2057 (PVOID) Name,
2058 sizeof Name
2059 );
2060 lstrcpynW (
2061 Name,
2062 Tzi.StandardName, /* WCHAR [32] */
2063 32
2064 );
2065 wprintf (
2066 L"\tName: \"%s\"\n",
2067 Name
2068 );
2069
2070 PrintUtcDateTime (
2071 "\tDate: %s\n",
2072 & Tzi.StandardDate /* SYSTEMTIME */
2073 );
2074
2075 printf ("\tBias: %d'\n",
2076 Tzi.StandardBias /* LONG */
2077 );
2078
2079 printf ("Daylight\n");
2080 RtlZeroMemory (
2081 (PVOID) Name,
2082 sizeof Name
2083 );
2084 lstrcpynW (
2085 Name,
2086 Tzi.DaylightName, /* WCHAR [32] */
2087 32
2088 );
2089 wprintf (
2090 L"\tName: \"%s\"\n",
2091 Name
2092 );
2093
2094 PrintUtcDateTime (
2095 "\tDate: %s\n",
2096 & Tzi.DaylightDate /* SYSTEMTIME */
2097 );
2098
2099 printf (
2100 "\tBias: %d'\n",
2101 Tzi.DaylightBias /* LONG */
2102 );
2103
2104 #endif
2105 return EXIT_SUCCESS;
2106 }
2107
2108
2109 /**********************************************************************
2110 *
2111 * DESCRIPTION
2112 *
2113 * NOTE
2114 * Class 45.
2115 */
2116 CMD_DEF(Lookaside)
2117 CMD_NOT_IMPLEMENTED
2118
2119
2120 /**********************************************************************
2121 * Miscellanea Commands
2122 **********************************************************************/
2123
2124 CMD_DEF(ver)
2125 {
2126 INT Total = 0;
2127
2128 Total =
2129 printf (
2130 "ReactOS Operating System - http://www.reactos.com/\n"
2131 "QSI - Query System Information (compiled on %s, %s)\n"
2132 "Copyright (c) 1999, 2000 Emanuele Aliberti et alii\n\n",
2133 __DATE__, __TIME__
2134 );
2135
2136 if (Application.Flag.Verbose)
2137 {
2138 Total +=
2139 printf (
2140 "This program is free software; you can redistribute it and/or modify\n"
2141 "it under the terms of the GNU General Public License as published by\n"
2142 "the Free Software Foundation; either version 2 of the License, or\n"
2143 "(at your option) any later version.\n\n"
2144
2145 "This program is distributed in the hope that it will be useful,\n"
2146 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
2147 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
2148 "GNU General Public License for more details.\n\n"
2149
2150 "You should have received a copy of the GNU General Public License\n"
2151 "along with this program; if not, write to the Free Software\n"
2152 "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
2153 "(See also http://www.fsf.org/).\n"
2154 );
2155 }
2156 return (Total);
2157 }
2158
2159
2160 CMD_DEF(exit)
2161 {
2162 Application.Active = FALSE;
2163 return EXIT_SUCCESS;
2164 }
2165
2166
2167 extern COMMAND_DESCRIPTOR Commands [];
2168
2169 CMD_DEF(help)
2170 {
2171 int i;
2172
2173 if (Application.Flag.Verbose)
2174 {
2175 printf ("Commands:\n");
2176 }
2177 for ( i = 0;
2178 (NULL != Commands[i].Name);
2179 i ++
2180 )
2181 {
2182 printf (
2183 (strlen (Commands[i].Name) > 7)
2184 ? "%s\t: %s\n"
2185 : "%s\t\t: %s\n",
2186 Commands[i].Name,
2187 Commands[i].Description
2188 );
2189 }
2190 return EXIT_SUCCESS;
2191 }
2192
2193
2194 CMD_DEF(credits)
2195 {
2196 return
2197 printf (
2198 "\nReactOS (http://www.reactos.com/):\n"
2199 "\tEmanuele Aliberti\n"
2200 "\tEric Kohl\n\n"
2201
2202 "HandleEx:\n"
2203 "\tMark Russinovich (http://www.sysinternals.com/)\n\n"
2204
2205 "NtDriverList:\n"
2206 "\tYariv Kaplan (http://www.internals.com/)\n\n"
2207
2208 "Undocumented SYSTEM_POOL_INFORMATION:\n"
2209 "\tKlaus P. Gerlicher\n\n"
2210
2211 "Undocumented Windows NT:\n"
2212 "\tPrasad Dabak, Sandeep Phadke, and Milind Borate\n\n"
2213
2214 "Windows NT/2000 Native API Reference:\n"
2215 "\tGary Nebbett\n\n"
2216
2217 "comp.os.ms-windows.programmer.nt.kernel-mode\n"
2218 "\t(many postings with sample code)\n"
2219 );
2220 }
2221
2222
2223 CMD_DEF(verbose)
2224 {
2225 Application.Flag.Verbose = ~Application.Flag.Verbose;
2226 return printf (
2227 "Verbose mode is %s.\n",
2228 ONOFF(Application.Flag.Verbose)
2229 );
2230 }
2231
2232
2233 CMD_DEF(dump)
2234 {
2235 Application.Flag.Dump = ~Application.Flag.Dump;
2236 return printf (
2237 "Dump mode is %s.\n",
2238 ONOFF(Application.Flag.Dump)
2239 );
2240 }
2241
2242
2243 /**********************************************************************
2244 * Commands table
2245 **********************************************************************/
2246
2247 COMMAND_DESCRIPTOR
2248 Commands [] =
2249 {
2250 /* System information classes */
2251
2252 { /* 0 Q */
2253 "basic",
2254 CMD_REF(Basic),
2255 "Basic system information"
2256 },
2257 { /* 1 Q */
2258 "processor",
2259 CMD_REF(Processor),
2260 "Processor characteristics"
2261 },
2262 { /* 2 Q */
2263 "perf",
2264 CMD_REF(Performance),
2265 "System performance data"
2266 },
2267 { /* 3 Q */
2268 "time",
2269 CMD_REF(Time),
2270 "System times"
2271 },
2272 { /* 4 Q */
2273 "path",
2274 CMD_REF(Path),
2275 "unknown"
2276 },
2277 { /* 5 Q */
2278 "process",
2279 CMD_REF(Process),
2280 "Process & thread tables"
2281 },
2282 { /* 6 Q */
2283 "sdt",
2284 CMD_REF(ServiceDescriptorTable),
2285 "Service descriptor table (SDT)"
2286 },
2287 { /* 7 Q */
2288 "ioconfig",
2289 CMD_REF(IoConfig),
2290 "I/O devices in the system, by class"
2291 },
2292 { /* 8 Q */
2293 "proctime",
2294 CMD_REF(ProcessorTime),
2295 "Print processor times"
2296 },
2297 { /* 9 QS */
2298 "flag",
2299 CMD_REF(NtGlobalFlag),
2300 "Print the system wide flags"
2301 },
2302 { /* 10 */
2303 "#10",
2304 CMD_REF(10),
2305 "UNKNOWN"
2306 },
2307 { /* 11 Q */
2308 "module",
2309 CMD_REF(Module),
2310 "Table of kernel modules"
2311 },
2312 { /* 12 Q */
2313 "reslock",
2314 CMD_REF(ResourceLock),
2315 "Table of locks on resources"
2316 },
2317 { /* 13 */
2318 "#13",
2319 CMD_REF(13),
2320 "UNKNOWN"
2321 },
2322 { /* 14 */
2323 "#14",
2324 CMD_REF(14),
2325 "UNKNOWN"
2326 },
2327 { /* 15 */
2328 "#15",
2329 CMD_REF(15),
2330 "UNKNOWN"
2331 },
2332 { /* 16 Q */
2333 "handle",
2334 CMD_REF(Handle),
2335 "Table of handles (Ps Manager)"
2336 },
2337 { /* 17 Q */
2338 "object",
2339 CMD_REF(Object),
2340 "Table of objects (Ob Manager)"
2341 },
2342 { /* 18 Q */
2343 "pagefile",
2344 CMD_REF(PageFile),
2345 "Virtual memory paging files (Cc Subsystem)"
2346 },
2347 { /* 19 Q */
2348 "emulation",
2349 CMD_REF(InstructionEmulation),
2350 "Virtual DOS Machine instruction emulation (VDM)"
2351 },
2352 { /* 20 */
2353 "#20",
2354 CMD_REF(20),
2355 "UNKNOWN"
2356 },
2357 { /* 21 QS */
2358 "cache",
2359 CMD_REF(Cache),
2360 "Cache Manager Status"
2361 },
2362 { /* 22 Q */
2363 "pooltag",
2364 CMD_REF(PoolTag),
2365 "Tagged pools statistics (checked build only)"
2366 },
2367 { /* 23 Q */
2368 "procsched",
2369 CMD_REF(ProcessorSchedule),
2370 "Processor schedule information"
2371 },
2372 { /* 24 QS */
2373 "dpc",
2374 CMD_REF(Dpc),
2375 "Deferred procedure call (DPC)"
2376 },
2377 { /* 25 */
2378 "#25",
2379 CMD_REF(25),
2380 "UNKNOWN"
2381 },
2382 { /* 26 S (callable) */
2383 "loadpe",
2384 CMD_REF(LoadImage),
2385 "Load a kernel mode DLL (in PE format)"
2386 },
2387 { /* 27 S (callable) */
2388 "unloadpe",
2389 CMD_REF(UnloadImage),
2390 "Unload a kernel mode DLL (module)"
2391 },
2392 { /* 28 QS */
2393 "timeadj",
2394 CMD_REF(TimeAdjustment),
2395 "Time adjustment"
2396 },
2397 { /* 29 */
2398 "#29",
2399 CMD_REF(29),
2400 "UNKNOWN"
2401 },
2402 { /* 30 */
2403 "#30",
2404 CMD_REF(30),
2405 "UNKNOWN"
2406 },
2407 { /* 31 */
2408 "#31",
2409 CMD_REF(31),
2410 "UNKNOWN"
2411 },
2412 { /* 32 Q */
2413 "crashsect",
2414 CMD_REF(CrashDumpSection),
2415 "Crash Dump Section"
2416 },
2417 { /* 33 Q */
2418 "procfault",
2419 CMD_REF(ProcessorFaultCount),
2420 "Processor fault count"
2421 },
2422 { /* 34 Q */
2423 "crashstate",
2424 CMD_REF(CrashDumpState),
2425 "Crash Dump State"
2426 },
2427 { /* 35 Q */
2428 "debugger",
2429 CMD_REF(Debugger),
2430 "System debugger"
2431 },
2432 { /* 36 Q */
2433 "threadsw",
2434 CMD_REF(ThreadSwitchCounters),
2435 "Thread switch counters"
2436 },
2437 { /* 37 QS */
2438 "quota",
2439 CMD_REF(Quota),
2440 "System quota values"
2441 },
2442 { /* 38 S */
2443 "loaddrv",
2444 CMD_REF(LoadDriver),
2445 "Load kernel driver (SYS)"
2446 },
2447 { /* 39 S */
2448 "prisep",
2449 CMD_REF(PrioritySeparation),
2450 "Priority Separation"
2451 },
2452 { /* 40 */
2453 "#40",
2454 CMD_REF(40),
2455 "UNKNOWN"
2456 },
2457 { /* 41 */
2458 "#41",
2459 CMD_REF(41),
2460 "UNKNOWN"
2461 },
2462 { /* 42 */
2463 "#42",
2464 CMD_REF(42),
2465 "UNKNOWN"
2466 },
2467 { /* 43 */
2468 "#43",
2469 CMD_REF(43),
2470 "UNKNOWN"
2471 },
2472 { /* 44 QS */
2473 "tz",
2474 CMD_REF(TimeZone),
2475 "Time zone (TZ) information"
2476 },
2477 { /* 45 Q */
2478 "lookaside",
2479 CMD_REF(Lookaside),
2480 "Lookaside"
2481 },
2482 /* User commands */
2483 {
2484 "?",
2485 CMD_REF(help),
2486 "Same as 'help'"
2487 },
2488 {
2489 "help",
2490 CMD_REF(help),
2491 "Print this command directory"
2492 },
2493 {
2494 "credits",
2495 CMD_REF(credits),
2496 "Print the list of people and sources that made QSI possible"
2497 },
2498 {
2499 "ver",
2500 CMD_REF(ver),
2501 "Print version number and license information"
2502 },
2503 {
2504 "exit",
2505 CMD_REF(exit),
2506 "Exit to operating system"
2507 },
2508 {
2509 "dump",
2510 CMD_REF(dump),
2511 "Enable/disable dumping raw data returned by system"
2512 },
2513 {
2514 "verbose",
2515 CMD_REF(verbose),
2516 "Enable/disable printing unused, unknown, and service fields"
2517 },
2518
2519 { NULL, NULL }
2520 };
2521
2522
2523
2524 /* user input --> command decoder */
2525
2526
2527 COMMAND_CALL
2528 DecodeCommand (LPCSTR Command)
2529 {
2530 int i;
2531
2532 for ( i = 0;
2533 ( Commands[i].Name
2534 && stricmp (Commands[i].Name,Command)
2535 );
2536 ++i
2537 );
2538 return Commands[i].EntryPoint;
2539 }
2540
2541 INT
2542 ParseCommandLine (
2543 LPCSTR CommandLine,
2544 LPCSTR CommandArgv []
2545 )
2546 {
2547 INT ArgC = 0;
2548 LPCSTR Separators = " \t";
2549
2550 for ( CommandArgv [ArgC] = strtok ((char*)CommandLine, (char*)Separators);
2551 (ArgC < ARGV_SIZE);
2552 CommandArgv [ArgC] = (LPCSTR) strtok (NULL, (char*)Separators)
2553 )
2554 {
2555 if (NULL == CommandArgv [ArgC++])
2556 {
2557 break;
2558 }
2559 }
2560 return (ArgC);
2561 }
2562
2563
2564 int
2565 main (int argc, char * argv [])
2566 {
2567 CHAR CommandLine [_MAX_PATH];
2568
2569 INT CommandArgc;
2570 LPCSTR CommandArgv [ARGV_SIZE];
2571
2572 /*
2573 * Initialize rt data.
2574 */
2575 Application.Heap = GetProcessHeap ();
2576 Application.Active = TRUE;
2577 /*
2578 * r-e-p loop.
2579 */
2580 while (Application.Active)
2581 {
2582 /* Print the prompt string. */
2583 if (! Application.Flag.Batch)
2584 {
2585 printf ("\r\nsystem> ");
2586 }
2587 /* Read user command. */
2588 gets (CommandLine);
2589 /* Parse the user command */
2590 CommandArgc = ParseCommandLine (
2591 CommandLine,
2592 CommandArgv
2593 );
2594 if (0 != CommandArgc)
2595 {
2596 COMMAND_CALL CommandCall = NULL;
2597
2598 /* decode */
2599 if ((CommandCall = DecodeCommand (CommandArgv[0])))
2600 {
2601 /* execute */
2602 Application.ExitCode =
2603 CommandCall (
2604 CommandArgc,
2605 CommandArgv
2606 );
2607 }
2608 else
2609 {
2610 printf ("Unknown command (type help for a list of valid commands).\n");
2611 }
2612 }
2613
2614 }
2615 if (! Application.Flag.Batch)
2616 {
2617 printf ("Bye\n");
2618 }
2619 return (EXIT_SUCCESS);
2620 }
2621
2622 /* EOF */