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