1 /* $Id: qsi.c,v 1.4 2001/01/13 18:17:17 ea Exp $
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/)
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
19 * Partially rewritten to run as a tool to query
20 * every system information class data.
22 * Added almost all structures for getting system
23 * information (from UNDOCNT.H by Dabak et alii).
25 * New QSI classe names used by E.Kohl.
33 #define NTOS_MODE_USER
39 DWORD Verbose
:1; /* print unknown, unused, service fields */
40 DWORD Dump
:1; /* raw dump output buffer */
41 DWORD Batch
:1; /* no shell (for future use) */
58 #define ONOFF(b) ((b)?"on":"off")
62 #define BUFFER_SIZE_DEFAULT 65536
64 #define TF(b) ((b)?"true":"false")
67 INT (* COMMAND_CALL
) (INT ArgC
,LPCSTR ArgV
[]);
71 VOID STDCALL
PrintStatus (NTSTATUS Status
);
73 #define CMD_REF(n) CMD_##n
74 #define CMD_DEF(n) INT CMD_REF(n) (INT argc, LPCSTR argv [])
75 #define CMD_NOT_IMPLEMENTED {printf("%s not implemented\n", argv[0]);return(0);}
78 struct _COMMAND_DESCRIPTOR
81 COMMAND_CALL EntryPoint
;
84 } COMMAND_DESCRIPTOR
, * PCOMMAND_DESCRIPTOR
;
87 /* Fast BYTE to binary representation */
89 #define BIT(n,m) (((n)&(m))?'1':'0')
97 Binary
[7] = BIT(Byte
,0x01);
98 Binary
[6] = BIT(Byte
,0x02);
99 Binary
[5] = BIT(Byte
,0x04);
100 Binary
[4] = BIT(Byte
,0x08);
101 Binary
[3] = BIT(Byte
,0x10);
102 Binary
[2] = BIT(Byte
,0x20);
103 Binary
[1] = BIT(Byte
,0x40);
104 Binary
[0] = BIT(Byte
,0x80);
105 return (LPSTR
) Binary
;
111 DumpData (int Size
, PVOID pData
)
113 PBYTE Buffer
= (PBYTE
) pData
;
116 const int Width
= 16;
118 if (! Application
.Flag
.Dump
)
124 printf ("%04x: ", (Buffer
- Base
));
135 (i
% 4 == 3) ? '|' : ' '
172 KernelObjectName
[] =
186 _T("12"), /* FIXME */
192 _T("18"), /* FIXME */
193 _T("19"), /* FIXME */
194 _T("20"), /* FIXME */
195 _T("21"), /* FIXME */
204 HandleTypeToObjectName (
208 if (HandleType
> 23) /* FIXME: use a symbol not a literal */
210 return _T("Unknown");
212 return KernelObjectName
[HandleType
];
220 FindRequiredBufferSize (int i
, int step
)
222 NTSTATUS Status
= STATUS_INFO_LENGTH_MISMATCH
;
223 BYTE Buffer
[BUFFER_SIZE_DEFAULT
];
228 Size
= step
= (step
> 0 ? step
: 1);
229 while ( (Size
< sizeof Buffer
)
230 && (Status
== STATUS_INFO_LENGTH_MISMATCH
)
233 if (Application
.Flag
.Verbose
)
235 printf ("\tTry %d", Size
);
237 RtlZeroMemory (Buffer
, sizeof Buffer
);
239 Status
= NtQuerySystemInformation (
245 if (STATUS_SUCCESS
== Status
)
247 printf ("Length = %d\n", Size
);
256 /* FIXME: slow linear search! */
260 printf ("No valid buffer length found!\n");
267 PrintStatus (NTSTATUS Status
)
269 LPCSTR StatusName
= NULL
;
273 case STATUS_INVALID_INFO_CLASS
:
274 StatusName
= "STATUS_INVALID_INFO_CLASS";
276 case STATUS_INFO_LENGTH_MISMATCH
:
277 StatusName
= "STATUS_INFO_LENGTH_MISMATCH";
279 case STATUS_ACCESS_VIOLATION
:
280 StatusName
= "STATUS_ACCESS_VIOLATION";
282 case STATUS_NOT_IMPLEMENTED
:
283 StatusName
= "STATUS_NOT_IMPLEMENTED";
285 case STATUS_BREAKPOINT
:
286 StatusName
= "STATUS_BREAKPOINT";
289 if (NULL
!= StatusName
)
291 printf ("\tStatus = %s\n", StatusName
);
294 printf ("\tStatus = 0x%08lX\n", Status
);
297 /* Auxiliary functions */
314 PrintUtcDateTime (LPCSTR Template
, PTIME UtcTime
)
316 CHAR UtcTimeString
[64];
317 TIME_FIELDS UtcTimeFields
;
319 RtlTimeToTimeFields (
320 (PLARGE_INTEGER
) UtcTime
,
325 "%s %d-%02d-%02d %02d:%02d:%02d.%03d UTC",
326 DaysOfWeek
[UtcTimeFields
.Weekday
],
331 UtcTimeFields
.Minute
,
332 UtcTimeFields
.Second
,
333 UtcTimeFields
.Milliseconds
342 /**********************************************************************
344 **********************************************************************/
347 /**********************************************************************
350 * Dump whatever we get by calling NtQuerySystemInformation with
351 * a user provided system information class id.
353 * NtQuerySystemInformation called with user class id.
357 int _id
= atoi ((char*)(argv
[0] + 1)); /* "#24" */
364 printf ("SystemInformation %d:\n", _id
);
365 /* Find buffer size */
366 Size
= FindRequiredBufferSize (_id
, 1);
369 printf("\t(no data)\n");
372 /* Allocate the buffer */
373 Buffer
= GlobalAlloc (GMEM_ZEROINIT
, Size
);
376 printf ("#%d: could not allocate %d bytes\n", _id
, Size
);
379 /* Query the executive */
380 Status
= NtQuerySystemInformation (
386 if (!NT_SUCCESS(Status
))
388 PrintStatus (Status
);
389 FindRequiredBufferSize (_id
, 1);
394 DumpData (Size
, Buffer
);
402 /**********************************************************************
412 SYSTEM_BASIC_INFORMATION Info
;
418 Status
= NtQuerySystemInformation (
424 if (STATUS_SUCCESS
!= Status
)
426 PrintStatus (Status
);
429 printf (" Reserved 0x%08x\n", Info
.Reserved
);
430 printf (" TimerResolution %d\n", Info
.TimerResolution
);
431 printf (" PageSize %d\n", Info
.PageSize
);
432 printf (" NumberOfPhysicalPages %d\n", Info
.NumberOfPhysicalPages
);
433 printf (" LowestPhysicalPageNumber %d\n", Info
.LowestPhysicalPageNumber
);
434 printf (" HighestPhysicalPageNumber %d\n", Info
.HighestPhysicalPageNumber
);
435 printf (" AllocationGranularity %d\n", Info
.AllocationGranularity
);
436 printf (" MinimumUserModeAddress 0x%08x (%d)\n", Info
.MinimumUserModeAddress
, Info
.MinimumUserModeAddress
);
437 printf (" MaximumUserModeAddress 0x%08x (%d)\n", Info
.MaximumUserModeAddress
, Info
.MaximumUserModeAddress
);
438 printf (" ActiveProcessorsAffinityMask 0x%08x\n", Info
.ActiveProcessorsAffinityMask
);
439 printf (" NumberOfProcessors %d\n", (int) Info
.NumberOfProcessors
);
445 /**********************************************************************
455 SYSTEM_PROCESSOR_INFORMATION Info
;
461 Status
= NtQuerySystemInformation (
467 if (STATUS_SUCCESS
!= Status
)
469 PrintStatus (Status
);
472 printf (" ProcessorArchitecture %d\n", Info
.ProcessorArchitecture
);
473 printf (" ProcessorLevel %d\n", Info
.ProcessorLevel
);
474 printf (" ProcessorRevision %d\n", Info
.ProcessorRevision
);
475 printf (" Reserved 0x%08x\n", Info
.Reserved
);
476 printf (" FeatureBits %08x\n", Info
.ProcessorFeatureBits
);
477 /* FIXME: decode feature bits */
483 /**********************************************************************
486 * System performance information.
493 NTSTATUS Status
= STATUS_SUCCESS
;
494 PSYSTEM_PERFORMANCE_INFO Info
;
498 Status
= NtQuerySystemInformation (
504 if (STATUS_SUCCESS
!= Status
)
506 PrintStatus (Status
);
509 printf ("Not implemented.\n");
511 LARGE_INTEGER TotalProcessorTime
;
512 LARGE_INTEGER IoReadTransferCount
;
513 LARGE_INTEGER IoWriteTransferCount
;
514 LARGE_INTEGER IoOtherTransferCount
;
515 ULONG IoReadOperationCount
;
516 ULONG IoWriteOperationCount
;
517 ULONG IoOtherOperationCount
;
518 ULONG MmAvailablePages
;
519 ULONG MmTotalCommitedPages
;
520 ULONG MmTotalCommitLimit
;
524 ULONG TransitionFaults
;
526 ULONG DemandZeroFaults
;
535 ULONG PoolPagedBytes
;
536 ULONG PoolNonPagedBytes
;
541 ULONG MmTotalSystemFreePtes
;
542 ULONG MmSystemCodepage
;
543 ULONG MmTotalSystemDriverPages
;
544 ULONG MmTotalSystemCodePages
;
548 ULONG MmSystemCachePage
;
549 ULONG MmPagedPoolPage
;
550 ULONG MmSystemDriverPage
;
551 ULONG CcFastReadNoWait
;
552 ULONG CcFastReadWait
;
553 ULONG CcFastReadResourceMiss
;
554 ULONG CcFastReadNotPossible
;
555 ULONG CcFastMdlReadNoWait
;
556 ULONG CcFastMdlReadWait
;
557 ULONG CcFastMdlReadResourceMiss
;
558 ULONG CcFastMdlReadNotPossible
;
559 ULONG CcMapDataNoWait
;
561 ULONG CcMapDataNoWaitMiss
;
562 ULONG CcMapDataWaitMiss
;
563 ULONG CcPinMappedDataCount
;
564 ULONG CcPinReadNoWait
;
566 ULONG CcPinReadNoWaitMiss
;
567 ULONG CcPinReadWaitMiss
;
568 ULONG CcCopyReadNoWait
;
569 ULONG CcCopyReadWait
;
570 ULONG CcCopyReadNoWaitMiss
;
571 ULONG CcCopyReadWaitMiss
;
572 ULONG CcMdlReadNoWait
;
574 ULONG CcMdlReadNoWaitMiss
;
575 ULONG CcMdlReadWaitMiss
;
576 ULONG CcReadaheadIos
;
577 ULONG CcLazyWriteIos
;
578 ULONG CcLazyWritePages
;
581 ULONG ContextSwitches
;
590 /**********************************************************************
600 SYSTEM_TIMEOFDAY_INFORMATION Info
;
602 Status
= NtQuerySystemInformation (
608 if (STATUS_SUCCESS
!= Status
)
610 PrintStatus (Status
);
613 PrintUtcDateTime (" BootTime %s\n", (PTIME
) & Info
.BootTime
);
614 PrintUtcDateTime (" CurrentTime %s\n", (PTIME
) & Info
.CurrentTime
);
615 PrintUtcDateTime (" TimeZoneBias %s\n", (PTIME
) & Info
.TimeZoneBias
); /* FIXME */
616 printf (" TimeZoneId %ld\n", Info
.TimeZoneId
);
617 printf (" Reserved %08x\n", Info
.Reserved
);
623 /**********************************************************************
633 SYSTEM_PATH_INFORMATION Info
;
634 CHAR _Info
[_MAX_PATH
];
637 RtlZeroMemory (& Info
, _MAX_PATH
);
638 Status
= NtQuerySystemInformation (
644 if (STATUS_SUCCESS
!= Status
)
646 PrintStatus (Status
);
647 DumpData (_MAX_PATH
, & _Info
);
650 DumpData (_MAX_PATH
, & _Info
);
655 /**********************************************************************
658 * A snapshot of the process+thread tables.
665 NTSTATUS Status
= STATUS_SUCCESS
;
666 PSYSTEM_PROCESS_INFORMATION pInfo
= NULL
;
670 pInfo
= GlobalAlloc (GMEM_ZEROINIT
, BUFFER_SIZE_DEFAULT
);
671 /* FIXME: check NULL==pInfo */
674 * Obtain required buffer size
676 Status
= NtQuerySystemInformation (
682 if (STATUS_SUCCESS
!= Status
)
684 if (STATUS_INFO_LENGTH_MISMATCH
== Status
)
689 pInfo
= GlobalReAlloc (pInfo
, Length
, GMEM_ZEROINIT
);
692 printf ("\tCould not allocate memory.\n");
698 PrintStatus (Status
);
704 * Get process+thread list from ntoskrnl.exe
706 Status
= NtQuerySystemInformation (
707 SystemProcessInformation
,
712 if (!NT_SUCCESS(Status
))
714 PrintStatus (Status
);
721 wprintf (L
"%s:\n", (pInfo
->Name
.Length
? pInfo
->Name
.Buffer
: L
"*idle*") );
722 if (Application
.Flag
.Verbose
)
724 wprintf (L
"\tRelativeOffset = 0x%08x\n", pInfo
->RelativeOffset
);
726 wprintf (L
"\tThreads = %ld\n", pInfo
->ThreadCount
);
727 wprintf (L
"\tHandles = %ld\n", pInfo
->HandleCount
);
728 wprintf (L
"\tBasePriority = %ld\n", pInfo
->BasePriority
);
729 wprintf (L
"\tPID = %ld\n", pInfo
->ProcessId
);
730 wprintf (L
"\tPPID = %ld\n", pInfo
->ParentProcessId
);
731 wprintf (L
"\tVirtualSize:\t\tWorkingSetSize:\n");
732 wprintf (L
"\t\tPeak : %ld\t\t\tPeak : %ld\n",
733 pInfo
->PeakVirtualSizeBytes
,
734 pInfo
->PeakWorkingSetSizeBytes
736 wprintf (L
"\t\tTotal: %ld\t\t\tTotal: %ld\n",
737 pInfo
->TotalVirtualSizeBytes
,
738 pInfo
->TotalWorkingSetSizeBytes
740 wprintf (L
"\tPagedPoolUsage:\t\tNonPagedPoolUsage:\n");
741 wprintf (L
"\t\tPeak : %ld\t\t\tPeak : %ld\n",
742 pInfo
->PeakPagedPoolUsagePages
,
743 pInfo
->TotalPagedPoolUsagePages
745 wprintf (L
"\t\tTotal: %ld\t\t\tTotal: %ld\n",
746 pInfo
->PeakNonPagedPoolUsagePages
,
747 pInfo
->TotalNonPagedPoolUsagePages
749 wprintf (L
"\tPageFileUsage:\n");
750 wprintf (L
"\t\tPeak : %ld\n", pInfo
->PeakPageFileUsageBytes
);
751 wprintf (L
"\t\tTotal: %ld\n", pInfo
->TotalPageFileUsageBytes
);
753 wprintf (L
"\tPageFaultCount = %ld\n", pInfo
->PageFaultCount
);
754 wprintf (L
"\tTotalPrivateBytes = %ld\n", pInfo
->TotalPrivateBytes
);
756 for ( ThreadIndex
= 0;
757 (ThreadIndex
< pInfo
->ThreadCount
);
761 wprintf (L
"\t%x in %x:\n",
762 pInfo
->ThreadSysInfo
[ThreadIndex
].ClientId
.UniqueThread
,
763 pInfo
->ThreadSysInfo
[ThreadIndex
].ClientId
.UniqueProcess
766 "\t\tKernelTime = %s\n",
767 & (pInfo
->ThreadSysInfo
[ThreadIndex
].KernelTime
)
770 "\t\tUserTime = %s\n",
771 & (pInfo
->ThreadSysInfo
[ThreadIndex
].UserTime
)
774 "\t\tCreateTime = %s\n",
775 & (pInfo
->ThreadSysInfo
[ThreadIndex
].CreateTime
)
777 wprintf (L
"\t\tTickCount = %ld\n",
778 pInfo
->ThreadSysInfo
[ThreadIndex
].TickCount
780 wprintf (L
"\t\tStartEIP = 0x%08x\n",
781 pInfo
->ThreadSysInfo
[ThreadIndex
].StartEIP
783 /* CLIENT_ID ClientId; */
784 wprintf (L
"\t\tDynamicPriority = %d\n",
785 pInfo
->ThreadSysInfo
[ThreadIndex
].DynamicPriority
787 wprintf (L
"\t\tBasePriority = %d\n",
788 pInfo
->ThreadSysInfo
[ThreadIndex
].BasePriority
790 wprintf (L
"\t\tnSwitches = %ld\n",
791 pInfo
->ThreadSysInfo
[ThreadIndex
].nSwitches
793 wprintf (L
"\t\tState = 0x%08x\n",
794 pInfo
->ThreadSysInfo
[ThreadIndex
].State
796 wprintf (L
"\t\tWaitReason = %ld\n",
797 pInfo
->ThreadSysInfo
[ThreadIndex
].WaitReason
801 if (0 == pInfo
->RelativeOffset
)
805 (ULONG
) pInfo
+= pInfo
->RelativeOffset
;
808 DumpData (Length
, pInfo
);
816 /**********************************************************************
826 SYSTEM_SDT_INFORMATION Info
;
830 RtlZeroMemory (& Info
, sizeof Info
);
831 Status
= NtQuerySystemInformation (
837 if (STATUS_SUCCESS
!= Status
)
839 PrintStatus (Status
);
840 DumpData (Length
, & Info
);
843 printf (" BufferLength = %ld\n", Info
.BufferLength
);
844 printf (" NumberOfSystemServiceTables = %ld\n", Info
.NumberOfSystemServiceTables
);
845 printf (" NumberOfServices = %ld\n", Info
.NumberOfServices
[0]);
846 printf (" ServiceCounters = %ld\n", Info
.ServiceCounters
[0]);
848 DumpData (Length
, & Info
);
854 /**********************************************************************
863 NTSTATUS Status
= STATUS_SUCCESS
;
864 SYSTEM_DEVICE_INFORMATION Info
;
867 Status
= NtQuerySystemInformation (
873 if (STATUS_SUCCESS
!= Status
)
875 PrintStatus (Status
);
878 printf (" Number Of Disks %ld\n", Info
.NumberOfDisks
);
879 printf (" Number Of Floppies %ld\n", Info
.NumberOfFloppies
);
880 printf (" Number Of CD-ROMs %ld\n", Info
.NumberOfCdRoms
);
881 printf (" Number Of Tapes %ld\n", Info
.NumberOfTapes
);
882 printf (" Number Of Serial Ports %ld\n", Info
.NumberOfSerialPorts
);
883 printf (" Number Of Parallel Ports %ld\n", Info
.NumberOfParallelPorts
);
885 DumpData (Length
, & Info
);
891 /**********************************************************************
901 SYSTEM_PROCESSORTIME_INFO Info
;
904 Status
= NtQuerySystemInformation (
910 if (STATUS_SUCCESS
!= Status
)
912 PrintStatus (Status
);
915 PrintUtcDateTime (" TotalProcessorRunTime : %s\n", & Info
.TotalProcessorRunTime
);
916 PrintUtcDateTime (" TotalProcessorTime : %s\n", & Info
.TotalProcessorTime
);
917 PrintUtcDateTime (" TotalProcessorUserTime: %s\n", & Info
.TotalProcessorUserTime
);
918 PrintUtcDateTime (" TotalDPCTime : %s\n", & Info
.TotalDPCTime
);
919 PrintUtcDateTime (" TotalInterruptTime : %s\n", & Info
.TotalInterruptTime
);
920 printf (" TotalInterrupts : %ld\n", Info
.TotalInterrupts
);
921 printf (" Unused : %08x\n", Info
.Unused
);
927 /**********************************************************************
937 SYSTEM_FLAGS_INFORMATION Info
;
940 Status
= NtQuerySystemInformation (
946 if (STATUS_SUCCESS
!= Status
)
948 PrintStatus (Status
);
951 printf (" NtGlobalFlag: %08x\n", Info
.Flags
);
952 /* FIXME: decode each flag */
958 /**********************************************************************
969 /**********************************************************************
977 * Code originally in Yariv Kaplan's NtDriverList,
978 * at http://www.internals.com/, adapted to ReactOS
983 NTSTATUS Status
= STATUS_SUCCESS
;
984 PSYSTEM_MODULE_INFORMATION pInfo
= NULL
;
988 "-------- -------- -------- ---------------------------------------\n";
992 * Obtain required buffer size
994 Status
= NtQuerySystemInformation (
1000 if (STATUS_INFO_LENGTH_MISMATCH
== Status
)
1005 pInfo
= GlobalAlloc (GMEM_ZEROINIT
, Length
);
1008 printf ("Could not allocate memory.\n");
1009 return EXIT_FAILURE
;
1014 PrintStatus (Status
);
1015 return EXIT_FAILURE
;
1018 * Get module list from ntoskrnl.exe
1020 Status
= NtQuerySystemInformation (
1026 if (!NT_SUCCESS(Status
))
1028 PrintStatus (Status
);
1029 return EXIT_FAILURE
;
1031 printf ("Index Address Size Name\n");
1035 (Index
< (int) pInfo
->Count
);
1040 "%8x %08x %8x %s\n",
1041 pInfo
->Module
[Index
].ModuleEntryIndex
,
1042 pInfo
->Module
[Index
].ModuleBaseAddress
,
1043 pInfo
->Module
[Index
].ModuleSize
,
1044 pInfo
->Module
[Index
].ModuleName
1051 return EXIT_SUCCESS
;
1055 /**********************************************************************
1064 NTSTATUS Status
= STATUS_SUCCESS
;
1065 PSYSTEM_RESOURCE_LOCK_INFO pInfo
= NULL
;
1069 "-------- -------- -------- -------- -------- -------- ------------\n";
1071 pInfo
= GlobalAlloc (GMEM_ZEROINIT
, BUFFER_SIZE_DEFAULT
);
1072 /* FIXME: check NULL==pInfo */
1075 * Obtain required buffer size
1077 Status
= NtQuerySystemInformation (
1080 BUFFER_SIZE_DEFAULT
, /* query size */
1083 if (STATUS_SUCCESS
!= Status
)
1085 if (STATUS_INFO_LENGTH_MISMATCH
== Status
)
1090 pInfo
= GlobalReAlloc (pInfo
, Length
, GMEM_ZEROINIT
);
1093 printf ("Could not allocate memory.\n");
1094 return EXIT_FAILURE
;
1099 PrintStatus (Status
);
1101 return EXIT_FAILURE
;
1105 * Get locked resource list from ntoskrnl.exe
1107 Status
= NtQuerySystemInformation (
1113 if (!NT_SUCCESS(Status
))
1115 PrintStatus (Status
);
1117 return EXIT_FAILURE
;
1119 printf ("Address Active # Content# Sh/Wait Exc/Wait\n");
1123 (Index
< (int) pInfo
->Count
);
1128 "%08x %8ld %8ld %8ld %8ld %08x\n",
1129 pInfo
->Lock
[Index
].ResourceAddress
,
1130 pInfo
->Lock
[Index
].ActiveCount
,
1131 pInfo
->Lock
[Index
].ContentionCount
,
1132 pInfo
->Lock
[Index
].NumberOfSharedWaiters
,
1133 pInfo
->Lock
[Index
].NumberOfExclusiveWaiters
,
1134 pInfo
->Lock
[Index
].Unknown
1141 return EXIT_SUCCESS
;
1145 /**********************************************************************
1156 /**********************************************************************
1167 /**********************************************************************
1178 /**********************************************************************
1183 * Class 16. You can not pass 0 as the initial output buffer's
1184 * size to get back the needed buffer size.
1188 NTSTATUS Status
= STATUS_SUCCESS
;
1189 PSYSTEM_HANDLE_INFORMATION pInfo
= NULL
;
1193 "-------- -------- -------- -------- -------- ----------\n";
1194 CHAR FlagsString
[9] = {0};
1196 pInfo
= GlobalAlloc (GMEM_ZEROINIT
, BUFFER_SIZE_DEFAULT
);
1199 * Obtain required buffer size
1201 Status
= NtQuerySystemInformation (
1204 BUFFER_SIZE_DEFAULT
,
1207 if (STATUS_SUCCESS
!= Status
)
1209 if (STATUS_INFO_LENGTH_MISMATCH
== Status
)
1214 pInfo
= GlobalReAlloc (pInfo
, Length
, GMEM_ZEROINIT
);
1217 printf ("\tCould not allocate memory.\n");
1218 return EXIT_FAILURE
;
1223 PrintStatus (Status
);
1225 return EXIT_FAILURE
;
1229 * Get handle table from ntoskrnl.exe
1231 Status
= NtQuerySystemInformation (
1237 if (!NT_SUCCESS(Status
))
1239 PrintStatus (Status
);
1241 return EXIT_FAILURE
;
1243 printf ("Handle OwnerPID ObjPtr Access Flags Type\n");
1247 (Index
< (int) pInfo
->Count
);
1252 "%8x %8x %8x %8x %s %s\n",
1253 pInfo
->Handle
[Index
].HandleValue
,
1254 pInfo
->Handle
[Index
].OwnerPid
,
1255 pInfo
->Handle
[Index
].ObjectPointer
,
1256 pInfo
->Handle
[Index
].AccessMask
,
1257 ByteToBinaryString (
1258 pInfo
->Handle
[Index
].HandleFlags
,
1261 HandleTypeToObjectName (pInfo
->Handle
[Index
].ObjectType
)
1266 DumpData (Length
, pInfo
);
1270 return EXIT_SUCCESS
;
1274 /**********************************************************************
1285 /**********************************************************************
1295 PSYSTEM_PAGEFILE_INFORMATION pInfo
= NULL
;
1298 pInfo
= GlobalAlloc (GMEM_ZEROINIT
, BUFFER_SIZE_DEFAULT
);
1299 /* FIXME: check pInfo */
1301 Status
= NtQuerySystemInformation(
1304 BUFFER_SIZE_DEFAULT
,
1307 if (STATUS_SUCCESS
!= Status
)
1309 if (STATUS_INFO_LENGTH_MISMATCH
== Status
)
1314 pInfo
= GlobalReAlloc (pInfo
, Length
, GMEM_ZEROINIT
);
1317 printf ("Could not allocate memory.\n");
1318 return EXIT_FAILURE
;
1323 PrintStatus (Status
);
1325 return EXIT_FAILURE
;
1328 Status
= NtQuerySystemInformation (
1334 if (!NT_SUCCESS(Status
))
1336 PrintStatus (Status
);
1338 return EXIT_FAILURE
;
1343 wprintf (L
" \"%s\":\n", pInfo
->PagefileFileName
.Buffer
);
1344 wprintf (L
"\tRelativeOffset %08x\n", pInfo
->RelativeOffset
);
1345 wprintf (L
"\tCurrentSizePages %ld\n", pInfo
->CurrentSizePages
);
1346 wprintf (L
"\tTotalUsedPages %ld\n", pInfo
->TotalUsedPages
);
1347 wprintf (L
"\tPeakUsedPages %ld\n", pInfo
->PeakUsedPages
);
1349 if (0 == pInfo
->RelativeOffset
)
1354 (ULONG
) pInfo
+= pInfo
->RelativeOffset
;
1357 DumpData (Length
, pInfo
);
1361 return EXIT_SUCCESS
;
1365 /**********************************************************************
1375 SYSTEM_VDM_INFORMATION Info
;
1377 RtlZeroMemory (& Info
, sizeof Info
);
1378 Status
= NtQuerySystemInformation (
1384 if (!NT_SUCCESS(Status
))
1386 PrintStatus (Status
);
1387 return EXIT_FAILURE
;
1389 printf (" VdmSegmentNotPresentCount = %ld\n", Info
.VdmSegmentNotPresentCount
);
1390 printf (" VdmINSWCount = %ld\n", Info
.VdmINSWCount
);
1391 printf (" VdmESPREFIXCount = %ld\n", Info
.VdmESPREFIXCount
);
1392 printf (" VdmCSPREFIXCount = %ld\n", Info
.VdmCSPREFIXCount
);
1393 printf (" VdmSSPREFIXCount = %ld\n", Info
.VdmSSPREFIXCount
);
1394 printf (" VdmDSPREFIXCount = %ld\n", Info
.VdmDSPREFIXCount
);
1395 printf (" VdmFSPREFIXCount = %ld\n", Info
.VdmFSPREFIXCount
);
1396 printf (" VdmGSPREFIXCount = %ld\n", Info
.VdmGSPREFIXCount
);
1397 printf (" VdmOPER32PREFIXCount = %ld\n", Info
.VdmOPER32PREFIXCount
);
1398 printf (" VdmADDR32PREFIXCount = %ld\n", Info
.VdmADDR32PREFIXCount
);
1399 printf (" VdmINSBCount = %ld\n", Info
.VdmINSBCount
);
1400 printf (" VdmINSWV86Count = %ld\n", Info
.VdmINSWV86Count
);
1401 printf (" VdmOUTSBCount = %ld\n", Info
.VdmOUTSBCount
);
1402 printf (" VdmOUTSWCount = %ld\n", Info
.VdmOUTSWCount
);
1403 printf (" VdmPUSHFCount = %ld\n", Info
.VdmPUSHFCount
);
1404 printf (" VdmPOPFCount = %ld\n", Info
.VdmPOPFCount
);
1405 printf (" VdmINTNNCount = %ld\n", Info
.VdmINTNNCount
);
1406 printf (" VdmINTOCount = %ld\n", Info
.VdmINTOCount
);
1407 printf (" VdmIRETCount = %ld\n", Info
.VdmIRETCount
);
1408 printf (" VdmINBIMMCount = %ld\n", Info
.VdmINBIMMCount
);
1409 printf (" VdmINWIMMCount = %ld\n", Info
.VdmINWIMMCount
);
1410 printf (" VdmOUTBIMMCount = %ld\n", Info
.VdmOUTBIMMCount
);
1411 printf (" VdmOUTWIMMCount = %ld\n", Info
.VdmOUTWIMMCount
);
1412 printf (" VdmINBCount = %ld\n", Info
.VdmINBCount
);
1413 printf (" VdmINWCount = %ld\n", Info
.VdmINWCount
);
1414 printf (" VdmOUTBCount = %ld\n", Info
.VdmOUTBCount
);
1415 printf (" VdmOUTWCount = %ld\n", Info
.VdmOUTWCount
);
1416 printf (" VdmLOCKPREFIXCount = %ld\n", Info
.VdmLOCKPREFIXCount
);
1417 printf (" VdmREPNEPREFIXCount = %ld\n", Info
.VdmREPNEPREFIXCount
);
1418 printf (" VdmREPPREFIXCount = %ld\n", Info
.VdmREPPREFIXCount
);
1419 printf (" VdmHLTCount = %ld\n", Info
.VdmHLTCount
);
1420 printf (" VdmCLICount = %ld\n", Info
.VdmCLICount
);
1421 printf (" VdmSTICount = %ld\n", Info
.VdmSTICount
);
1422 printf (" VdmBopCount = %ld\n", Info
.VdmBopCount
);
1424 return EXIT_SUCCESS
;
1428 /**********************************************************************
1439 /**********************************************************************
1449 SYSTEM_CACHE_INFORMATION Si
;
1455 Status
= NtQuerySystemInformation (
1461 if (!NT_SUCCESS(Status
))
1463 PrintStatus (Status
);
1464 return EXIT_FAILURE
;
1466 printf ("\tSize:\n");
1467 printf ("\t\tCurrent = %ld\n", Si
.CurrentSize
);
1468 printf ("\t\tPeak = %ld\n\n", Si
.PeakSize
);
1469 printf ("\tPageFaults:\n\t\tCount = %ld\n\n", Si
.PageFaultCount
);
1470 printf ("\tWorking Set:\n");
1471 printf ("\t\tMinimum = %ld\n", Si
.MinimumWorkingSet
);
1472 printf ("\t\tMaximum = %ld\n", Si
.MaximumWorkingSet
);
1474 return EXIT_SUCCESS
;
1478 /**********************************************************************
1481 * Get statistic data about tagged pools. Not implemented in the
1490 PSYSTEM_POOL_TAG_INFO pInfo
= NULL
;
1494 pInfo
= GlobalAlloc (GMEM_ZEROINIT
, BUFFER_SIZE_DEFAULT
);
1495 /* FIXME: check pInfo */
1497 Status
= NtQuerySystemInformation(
1500 BUFFER_SIZE_DEFAULT
,
1503 if (STATUS_SUCCESS
!= Status
)
1505 if (STATUS_INFO_LENGTH_MISMATCH
== Status
)
1510 pInfo
= GlobalReAlloc (pInfo
, Length
, GMEM_ZEROINIT
);
1513 printf ("Could not allocate memory.\n");
1514 return EXIT_FAILURE
;
1519 PrintStatus (Status
);
1521 return EXIT_FAILURE
;
1524 Status
= NtQuerySystemInformation (
1530 if (!NT_SUCCESS(Status
))
1532 PrintStatus (Status
);
1534 return EXIT_FAILURE
;
1537 for ( PoolIndex
= 0;
1538 (PoolIndex
< pInfo
->Count
);
1542 wprintf (L
"\t%08x:\n", pInfo
->PoolEntry
[PoolIndex
].Tag
);
1543 wprintf (L
"\t\tPaged:\t\tNon Paged:\n");
1545 L
"\t\tAllocationCount = %ld\tAllocationCount = %ld\n",
1546 pInfo
->PoolEntry
[PoolIndex
].Paged
.AllocationCount
,
1547 pInfo
->PoolEntry
[PoolIndex
].NonPaged
.AllocationCount
1550 L
"\t\tFreeCount = %ld\tFreeCount = %ld\n",
1551 pInfo
->PoolEntry
[PoolIndex
].Paged
.FreeCount
,
1552 pInfo
->PoolEntry
[PoolIndex
].NonPaged
.FreeCount
1555 L
"\t\tSizeBytes = %ld\tSizeBytes = %ld\n",
1556 pInfo
->PoolEntry
[PoolIndex
].Paged
.SizeBytes
,
1557 pInfo
->PoolEntry
[PoolIndex
].NonPaged
.SizeBytes
1561 DumpData (Length
, pInfo
);
1565 return EXIT_SUCCESS
;
1569 /**********************************************************************
1579 SYSTEM_PROCESSOR_SCHEDULE_INFO Info
;
1585 Status
= NtQuerySystemInformation (
1591 if (STATUS_SUCCESS
!= Status
)
1593 PrintStatus (Status
);
1594 return EXIT_FAILURE
;
1597 printf ("\tnContextSwitches = %ld\n", Info
.nContextSwitches
);
1598 printf ("\tnDPCQueued = %ld\n", Info
.nDPCQueued
);
1599 printf ("\tnDPCRate = %ld\n", Info
.nDPCRate
);
1600 printf ("\tTimerResolution = %ld\n", Info
.TimerResolution
);
1601 printf ("\tnDPCBypasses = %ld\n", Info
.nDPCBypasses
);
1602 printf ("\tnAPCBypasses = %ld\n", Info
.nAPCBypasses
);
1604 DumpData (sizeof Info
, & Info
);
1606 return EXIT_SUCCESS
;
1611 /**********************************************************************
1621 SYSTEM_DPC_INFORMATION Info
;
1627 Status
= NtQuerySystemInformation (
1633 if (STATUS_SUCCESS
!= Status
)
1635 PrintStatus (Status
);
1636 return EXIT_FAILURE
;
1639 if (Application
.Flag
.Verbose
)
1641 printf ("\tUnused = %ld\n", Info
.Unused
);
1643 printf ("\tKiMaximumDpcQueueDepth = %ld\n", Info
.KiMaximumDpcQueueDepth
);
1644 printf ("\tKiMinimumDpcRate = %ld\n", Info
.KiMinimumDpcRate
);
1645 printf ("\tKiAdjustDpcThreshold = %ld\n", Info
.KiAdjustDpcThreshold
);
1646 printf ("\tKiIdealDpcRate = %ld\n", Info
.KiIdealDpcRate
);
1648 DumpData (sizeof Info
, & Info
);
1650 return EXIT_SUCCESS
;
1654 /**********************************************************************
1665 /**********************************************************************
1675 /**********************************************************************
1686 /**********************************************************************
1695 NTSTATUS Status
= STATUS_SUCCESS
;
1696 SYSTEM_TIME_ADJUSTMENT_INFO Info
;
1698 RtlZeroMemory (& Info
, sizeof Info
);
1699 Status
= NtQuerySystemInformation (
1705 if (!NT_SUCCESS(Status
))
1707 PrintStatus (Status
);
1708 return EXIT_FAILURE
;
1710 printf ("\tKeTimeAdjustment = %ld\n", Info
.KeTimeAdjustment
);
1711 printf ("\tKeMaximumIncrement = %ld\n", Info
.KeMaximumIncrement
);
1712 printf ("\tKeTimeSynchronization = %s\n", TF(Info
.KeTimeSynchronization
));
1714 return EXIT_SUCCESS
;
1718 /**********************************************************************
1729 /**********************************************************************
1740 /**********************************************************************
1751 /**********************************************************************
1762 /**********************************************************************
1773 /**********************************************************************
1784 /**********************************************************************
1794 SYSTEM_DEBUGGER_INFO Info
;
1796 RtlZeroMemory (& Info
, sizeof Info
);
1797 Status
= NtQuerySystemInformation (
1803 if (STATUS_SUCCESS
!= Status
)
1805 PrintStatus (Status
);
1806 return EXIT_FAILURE
;
1808 printf ("\tKdDebuggerEnabled = %s\n", TF(Info
.KdDebuggerEnabled
));
1809 printf ("\tKdDebuggerPresent = %s\n", TF(Info
.KdDebuggerPresent
));
1811 DumpData (sizeof Info
, & Info
);
1813 return EXIT_SUCCESS
;
1817 /**********************************************************************
1828 /**********************************************************************
1837 NTSTATUS Status
= STATUS_SUCCESS
;
1838 SYSTEM_QUOTA_INFORMATION Info
;
1840 RtlZeroMemory (& Info
, sizeof Info
);
1841 Status
= NtQuerySystemInformation (
1847 if (!NT_SUCCESS(Status
))
1849 PrintStatus (Status
);
1850 return EXIT_FAILURE
;
1852 printf ("\tCmpGlobalQuota = %ld\n", Info
.CmpGlobalQuota
);
1853 printf ("\tCmpGlobalQuotaUsed = %ld\n", Info
.CmpGlobalQuotaUsed
);
1854 printf ("\tMmSizeofPagedPoolInBytes = %ld\n", Info
.MmSizeofPagedPoolInBytes
);
1856 return EXIT_SUCCESS
;
1860 /**********************************************************************
1871 /**********************************************************************
1882 /**********************************************************************
1893 /**********************************************************************
1904 /**********************************************************************
1915 /**********************************************************************
1926 /**********************************************************************
1929 * Dump the system TIME_ZONE_INFORMATION object.
1938 TIME_ZONE_INFORMATION Tzi
;
1941 RtlZeroMemory (& Tzi
, sizeof Tzi
);
1942 Status
= NtQuerySystemInformation(
1943 SystemTimeZoneInformation
,
1948 if (!NT_SUCCESS(Status
))
1950 PrintStatus (Status
);
1951 return EXIT_FAILURE
;
1954 "12h/24h.....: %dh\n",
1958 "Bias........: %d'\n",
1962 printf ("Standard\n");
1969 Tzi
.StandardName
, /* WCHAR [32] */
1973 L
"\tName: \"%s\"\n",
1979 & Tzi
.StandardDate
/* SYSTEMTIME */
1982 printf ("\tBias: %d'\n",
1983 Tzi
.StandardBias
/* LONG */
1986 printf ("Daylight\n");
1993 Tzi
.DaylightName
, /* WCHAR [32] */
1997 L
"\tName: \"%s\"\n",
2003 & Tzi
.DaylightDate
/* SYSTEMTIME */
2008 Tzi
.DaylightBias
/* LONG */
2011 return EXIT_SUCCESS
;
2015 /**********************************************************************
2026 /**********************************************************************
2037 /**********************************************************************
2048 /**********************************************************************
2059 /**********************************************************************
2070 /**********************************************************************
2081 /**********************************************************************
2092 /**********************************************************************
2103 /**********************************************************************
2114 /**********************************************************************
2115 * Miscellanea Commands
2116 **********************************************************************/
2124 "ReactOS Operating System - http://www.reactos.com/\n"
2125 "QSI - Query System Information (compiled on %s, %s)\n"
2126 "Copyright (c) 1999-2001 Emanuele Aliberti et alii\n\n"
2127 "Run the command in verbose mode, for full license information.\n\n",
2131 if (Application
.Flag
.Verbose
)
2135 "This program is free software; you can redistribute it and/or modify\n"
2136 "it under the terms of the GNU General Public License as published by\n"
2137 "the Free Software Foundation; either version 2 of the License, or\n"
2138 "(at your option) any later version.\n\n"
2140 "This program is distributed in the hope that it will be useful,\n"
2141 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
2142 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
2143 "GNU General Public License for more details.\n\n"
2145 "You should have received a copy of the GNU General Public License\n"
2146 "along with this program; if not, write to the Free Software\n"
2147 "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
2148 "(See also http://www.fsf.org/).\n"
2157 Application
.Active
= FALSE
;
2158 return EXIT_SUCCESS
;
2162 extern COMMAND_DESCRIPTOR Commands
[];
2168 if (Application
.Flag
.Verbose
)
2170 printf ("Commands:\n");
2173 (NULL
!= Commands
[i
].Name
);
2178 (strlen (Commands
[i
].Name
) > 7)
2182 Commands
[i
].Description
2185 return EXIT_SUCCESS
;
2193 "\nReactOS (http://www.reactos.com/):\n"
2194 "\tEmanuele Aliberti\n"
2198 "\tMark Russinovich (http://www.sysinternals.com/)\n\n"
2201 "\tYariv Kaplan (http://www.internals.com/)\n\n"
2203 "Undocumented SYSTEM_POOL_INFORMATION:\n"
2204 "\tKlaus P. Gerlicher\n\n"
2206 "Undocumented Windows NT:\n"
2207 "\tPrasad Dabak, Sandeep Phadke, and Milind Borate\n\n"
2209 "Windows NT/2000 Native API Reference:\n"
2210 "\tGary Nebbett\n\n"
2212 "comp.os.ms-windows.programmer.nt.kernel-mode\n"
2213 "\t(many postings with sample code)\n"
2220 Application
.Flag
.Verbose
= ~Application
.Flag
.Verbose
;
2222 "Verbose mode is %s.\n",
2223 ONOFF(Application
.Flag
.Verbose
)
2230 Application
.Flag
.Dump
= ~Application
.Flag
.Dump
;
2232 "Dump mode is %s.\n",
2233 ONOFF(Application
.Flag
.Dump
)
2238 /**********************************************************************
2240 **********************************************************************/
2245 /* System information classes */
2250 "Basic system information"
2255 "Processor characteristics"
2260 "System performance data"
2267 { /* 4 Q (checked build only) */
2270 "Path (checked build only)"
2275 "Process & thread tables"
2280 "Call count information"
2285 "I/O devices in the system, by class"
2290 "Processor performance"
2305 "Table of kernel modules"
2310 "Table of locks on resources"
2335 "Table of executive objects"
2340 "Virtual memory paging files"
2345 "Virtual DOS Machine instruction emulation (VDM)"
2360 "Tagged pools statistics (checked build only)"
2365 "Processor schedule information (interrupt)"
2370 "Deferred procedure call behaviour (DPC)"
2377 { /* 26 S (callable) */
2380 "Load a kernel mode DLL (module in PE format)"
2382 { /* 27 S (callable) */
2385 "Unload a kernel mode DLL (module in Pe format)"
2410 "Crash Dump Section"
2430 "Thread context switch counters"
2435 "Registry quota values"
2440 "Extended service table"
2445 "Priority Separation"
2470 "Current time zone (TZ)"
2481 "Set time slip (5.0)"
2486 "Create session (5.0)"
2491 "Delete session (5.0)"
2511 "Add verifier (5.0)"
2516 "Session processes (5.0)"
2527 "Print this command directory"
2532 "Print the list of people and sources that made QSI possible"
2537 "Print version number and license information"
2542 "Exit to operating system"
2547 "Enable/disable dumping raw data returned by system"
2552 "Enable/disable printing unused, unknown, and service fields"
2560 /* user input --> command decoder */
2564 DecodeCommand (LPCSTR Command
)
2570 && stricmp (Commands
[i
].Name
,Command
)
2574 return Commands
[i
].EntryPoint
;
2580 LPCSTR CommandArgv
[]
2584 LPCSTR Separators
= " \t";
2586 for ( CommandArgv
[ArgC
] = strtok ((char*)CommandLine
, (char*)Separators
);
2588 CommandArgv
[ArgC
] = (LPCSTR
) strtok (NULL
, (char*)Separators
)
2591 if (NULL
== CommandArgv
[ArgC
++])
2601 main (int argc
, char * argv
[])
2603 CHAR CommandLine
[_MAX_PATH
];
2606 LPCSTR CommandArgv
[ARGV_SIZE
];
2609 * Initialize rt data.
2611 Application
.Heap
= GetProcessHeap ();
2612 Application
.Active
= TRUE
;
2616 while (Application
.Active
)
2618 /* Print the prompt string. */
2619 if (! Application
.Flag
.Batch
)
2621 printf ("\r\nsystem> ");
2623 /* Read user command. */
2625 /* Parse the user command */
2626 CommandArgc
= ParseCommandLine (
2630 if (0 != CommandArgc
)
2632 COMMAND_CALL CommandCall
= NULL
;
2635 if ((CommandCall
= DecodeCommand (CommandArgv
[0])))
2638 Application
.ExitCode
=
2646 printf ("Unknown command (type help for a list of valid commands).\n");
2651 if (! Application
.Flag
.Batch
)
2655 return (EXIT_SUCCESS
);