📄 qssi.c
字号:
/* $Id: qssi.c 16861 2005-07-29 13:46:03Z ea $
*
* PROJECT : ReactOS Operating System (see http://www.reactos.com/)
* DESCRIPTION: Tool to query system information
* FILE : rosapps/sysutils/qsi.c
* AUTHOR : Emanuele Aliberti
* LICENSE : GNU GPL (see http://www.gnu.org/)
* DATE : 1999-07-28
*
* BUILD INSTRUCTIONS
* If you got this code directly from the CVS repository on
* mok.lcvm.com, it should be ok to run "make sqi.exe" from the
* current directory. Otherwise, be sure the directories
* "rosapps" and "reactos" are siblings (see the FILE file
* in the header).
*
* REVISIONS
* 2000-02-12 (ea)
* Partially rewritten to run as a tool to query
* every system information class data.
* 2000-04-23 (ea)
* Added almost all structures for getting system
* information (from UNDOCNT.H by Dabak et alii).
* 2001-01-13 (ea)
* New QSI class names used by E.Kohl.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#define NTOS_MODE_USER
#include <ntos.h>
typedef
struct _FLAGS
{
DWORD Verbose:1; /* print unknown, unused, service fields */
DWORD Dump:1; /* raw dump output buffer */
DWORD Batch:1; /* no shell (for future use) */
} FLAGS;
static
struct
{
FLAGS Flag;
BOOL Active;
HANDLE Heap;
INT ExitCode;
} Application =
{
{0, 0},
FALSE
};
#define ONOFF(b) ((b)?"on":"off")
#define ARGV_SIZE 64
#define BUFFER_SIZE_DEFAULT 65536
#define TF(b) ((b)?"true":"false")
typedef
INT (* COMMAND_CALL) (INT ArgC,LPCSTR ArgV []);
VOID STDCALL PrintStatus (NTSTATUS Status);
#define CMD_REF(n) CMD_##n
#define CMD_DEF(n) INT CMD_REF(n) (INT argc, LPCSTR argv [])
#define CMD_NOT_IMPLEMENTED {printf("%s not implemented\n", argv[0]);return(0);}
typedef
struct _COMMAND_DESCRIPTOR
{
LPCSTR Name;
COMMAND_CALL EntryPoint;
LPCSTR Description;
} COMMAND_DESCRIPTOR, * PCOMMAND_DESCRIPTOR;
/* Fast BYTE to binary representation */
#define BIT(n,m) (((n)&(m))?'1':'0')
LPSTR
STDCALL
ByteToBinaryString (
BYTE Byte,
CHAR Binary [8]
)
{
Binary [7] = BIT(Byte,0x01);
Binary [6] = BIT(Byte,0x02);
Binary [5] = BIT(Byte,0x04);
Binary [4] = BIT(Byte,0x08);
Binary [3] = BIT(Byte,0x10);
Binary [2] = BIT(Byte,0x20);
Binary [1] = BIT(Byte,0x40);
Binary [0] = BIT(Byte,0x80);
return (LPSTR) Binary;
}
/* --- */
VOID
STDCALL
DumpData (int Size, PVOID pData )
{
PBYTE Buffer = (PBYTE) pData;
PBYTE Base = Buffer;
int i;
const int Width = 16;
if (! Application.Flag.Dump)
{
return;
}
while (Size > 0)
{
printf ("%04x: ", (Buffer - Base));
for ( i = 0;
(i < Width);
++i
)
{
if (Size - i > 0)
{
printf (
"%02x%c",
Buffer[i],
(i % 4 == 3) ? '|' : ' '
);
}
else
{
printf (" ");
}
}
printf (" ");
for ( i = 0;
(i < Width);
++i
)
{
if (Size - i > 0)
{
printf (
"%c",
( (Buffer[i] > ' ')
&& (Buffer[i] < 127)
)
? Buffer[i]
: ' '
);
}
}
printf ("\n");
Buffer += Width;
Size -= Width;
}
printf ("\n");
}
/* --- */
static
LPTSTR
KernelObjectName [] =
{
_T("0"), /* FIXME */
_T("1"), /* FIXME */
_T("Directory"),
_T("SymbolicLink"),
_T("Token"),
_T("Process"),
_T("Thread"),
_T("Event"),
_T("8"), /* FIXME */
_T("Mutant"),
_T("Semaphore"),
_T("Timer"),
_T("12"), /* FIXME */
_T("WindowStation"),
_T("Desktop"),
_T("Section"),
_T("Key"),
_T("Port"),
_T("18"), /* FIXME */
_T("19"), /* FIXME */
_T("20"), /* FIXME */
_T("21"), /* FIXME */
_T("IoCompletion"),
_T("File"),
NULL
};
LPTSTR
STDCALL
HandleTypeToObjectName (
DWORD HandleType
)
{
if (HandleType > 23) /* FIXME: use a symbol not a literal */
{
return _T("Unknown");
}
return KernelObjectName [HandleType];
}
/* --- */
int
STDCALL
FindRequiredBufferSize (int i, int step)
{
NTSTATUS Status = STATUS_INFO_LENGTH_MISMATCH;
BYTE Buffer [BUFFER_SIZE_DEFAULT];
INT Size;
LONG Length = 0;
Size = step = (step > 0 ? step : 1);
while ( (Size < sizeof Buffer)
&& (Status == STATUS_INFO_LENGTH_MISMATCH)
)
{
if (Application.Flag.Verbose)
{
printf ("\tTry %d", Size);
}
RtlZeroMemory (Buffer, sizeof Buffer);
Length = 0;
Status = NtQuerySystemInformation (
i,
& Buffer,
Size,
& Length
);
if (STATUS_SUCCESS == Status)
{
printf ("Length = %d\n", Size);
return Size;
}
if (Length > 0)
{
Size = Length;
}
else
{
/* FIXME: slow linear search! */
Size += step;
}
}
printf ("No valid buffer length found!\n");
return -1;
}
VOID
STDCALL
PrintStatus (NTSTATUS Status)
{
LPCSTR StatusName = NULL;
switch (Status)
{
case STATUS_INVALID_INFO_CLASS:
StatusName = "STATUS_INVALID_INFO_CLASS";
break;
case STATUS_INFO_LENGTH_MISMATCH:
StatusName = "STATUS_INFO_LENGTH_MISMATCH";
break;
case STATUS_ACCESS_VIOLATION:
StatusName = "STATUS_ACCESS_VIOLATION";
break;
case STATUS_NOT_IMPLEMENTED:
StatusName = "STATUS_NOT_IMPLEMENTED";
break;
case STATUS_BREAKPOINT:
StatusName = "STATUS_BREAKPOINT";
break;
}
if (NULL != StatusName)
{
printf ("\tStatus = %s\n", StatusName);
return;
}
printf ("\tStatus = 0x%08lX\n", Status );
}
/* Auxiliary functions */
PCHAR
DaysOfWeek [] =
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};
VOID
STDCALL
PrintUtcDateTime (LPCSTR Template, PTIME UtcTime)
{
CHAR UtcTimeString [64];
TIME_FIELDS UtcTimeFields;
RtlTimeToTimeFields (
(PLARGE_INTEGER) UtcTime,
& UtcTimeFields
);
sprintf (
UtcTimeString,
"%s %d-%02d-%02d %02d:%02d:%02d.%03d UTC",
DaysOfWeek[UtcTimeFields.Weekday],
UtcTimeFields.Year,
UtcTimeFields.Month,
UtcTimeFields.Day,
UtcTimeFields.Hour,
UtcTimeFields.Minute,
UtcTimeFields.Second,
UtcTimeFields.Milliseconds
);
printf (
Template,
UtcTimeString
);
}
/**********************************************************************
* Dumpers
**********************************************************************/
/**********************************************************************
*
* DESCRIPTION
* Dump whatever we get by calling NtQuerySystemInformation with
* a user provided system information class id.
* NOTE
* NtQuerySystemInformation called with user class id.
*/
CMD_DEF(unknown)
{
int _id = atoi ((char*)(argv[0] + 1)); /* "#24" */
/* ^ */
int Size = -1;
PBYTE Buffer = NULL;
NTSTATUS Status;
printf ("SystemInformation %d:\n", _id);
/* Find buffer size */
Size = FindRequiredBufferSize (_id, 1);
if (-1 == Size)
{
printf("\t(no data)\n");
return EXIT_FAILURE;
}
/* Allocate the buffer */
Buffer = GlobalAlloc (GMEM_ZEROINIT, Size);
if (NULL == Buffer)
{
printf ("#%d: could not allocate %d bytes\n", _id, Size);
return EXIT_FAILURE;
}
/* Query the executive */
Status = NtQuerySystemInformation (
_id,
Buffer,
Size,
NULL
);
if (!NT_SUCCESS(Status))
{
PrintStatus (Status);
FindRequiredBufferSize (_id, 1);
GlobalFree (Buffer);
return EXIT_FAILURE;
}
/* Print the data */
DumpData (Size, Buffer);
/* --- */
GlobalFree (Buffer);
return EXIT_SUCCESS;
}
/**********************************************************************
*
* DESCRIPTION
*
* NOTE
* Class 0.
*/
CMD_DEF(0)
{
NTSTATUS Status;
SYSTEM_BASIC_INFORMATION Info;
RtlZeroMemory (
(PVOID) & Info,
sizeof Info
);
Status = NtQuerySystemInformation (
0,
& Info,
sizeof Info,
NULL
);
if (STATUS_SUCCESS != Status)
{
PrintStatus (Status);
return EXIT_FAILURE;
}
printf (" Reserved 0x%08lx\n", Info.Reserved);
printf (" TimerResolution %ld\n", Info.TimerResolution);
printf (" PageSize %ld\n", Info.PageSize);
printf (" NumberOfPhysicalPages %ld\n", Info.NumberOfPhysicalPages);
printf (" LowestPhysicalPageNumber %ld\n", Info.LowestPhysicalPageNumber);
printf (" HighestPhysicalPageNumber %ld\n", Info.HighestPhysicalPageNumber);
printf (" AllocationGranularity %ld\n", Info.AllocationGranularity);
printf (" MinimumUserModeAddress 0x%08lx (%ld)\n", Info.MinimumUserModeAddress, Info.MinimumUserModeAddress);
printf (" MaximumUserModeAddress 0x%08lx (%ld)\n", Info.MaximumUserModeAddress, Info.MaximumUserModeAddress);
printf (" ActiveProcessorsAffinityMask 0x%08lx\n", Info.ActiveProcessorsAffinityMask);
printf (" NumberOfProcessors %d\n", (int) Info.NumberOfProcessors);
return EXIT_SUCCESS;
}
/**********************************************************************
*
* DESCRIPTION
*
* NOTE
* Class 1.
*/
CMD_DEF(1)
{
NTSTATUS Status;
SYSTEM_PROCESSOR_INFORMATION Info;
RtlZeroMemory (
(PVOID) & Info,
sizeof Info
);
Status = NtQuerySystemInformation (
1,
& Info,
sizeof Info,
NULL
);
if (STATUS_SUCCESS != Status)
{
PrintStatus (Status);
return EXIT_FAILURE;
}
printf (" ProcessorArchitecture %d\n", Info.ProcessorArchitecture);
printf (" ProcessorLevel %d\n", Info.ProcessorLevel);
printf (" ProcessorRevision %d\n", Info.ProcessorRevision);
printf (" Reserved 0x%08x\n", Info.Reserved);
printf (" FeatureBits %08lx\n", Info.ProcessorFeatureBits);
/* FIXME: decode feature bits */
return EXIT_SUCCESS;
}
/**********************************************************************
*
* DESCRIPTION
* System performance information.
*
* NOTE
* Class 2.
*/
CMD_DEF(2)
{
NTSTATUS Status = STATUS_SUCCESS;
PSYSTEM_PERFORMANCE_INFO Info;
LONG Length = 0;
Status = NtQuerySystemInformation (
2,
& Info,
sizeof Info,
& Length
);
if (STATUS_SUCCESS != Status)
{
PrintStatus (Status);
return EXIT_FAILURE;
}
printf ("Not implemented.\n");
#if 0
LARGE_INTEGER TotalProcessorTime;
LARGE_INTEGER IoReadTransferCount;
LARGE_INTEGER IoWriteTransferCount;
LARGE_INTEGER IoOtherTransferCount;
ULONG IoReadOperationCount;
ULONG IoWriteOperationCount;
ULONG IoOtherOperationCount;
ULONG MmAvailablePages;
ULONG MmTotalCommitedPages;
ULONG MmTotalCommitLimit;
ULONG MmPeakLimit;
ULONG PageFaults;
ULONG WriteCopies;
ULONG TransitionFaults;
ULONG Unknown1;
ULONG DemandZeroFaults;
ULONG PagesInput;
ULONG PagesRead;
ULONG Unknown2;
ULONG Unknown3;
ULONG PagesOutput;
ULONG PageWrites;
ULONG Unknown4;
ULONG Unknown5;
ULONG PoolPagedBytes;
ULONG PoolNonPagedBytes;
ULONG Unknown6;
ULONG Unknown7;
ULONG Unknown8;
ULONG Unknown9;
ULONG MmTotalSystemFreePtes;
ULONG MmSystemCodepage;
ULONG MmTotalSystemDriverPages;
ULONG MmTotalSystemCodePages;
ULONG Unknown10;
ULONG Unknown11;
ULONG Unknown12;
ULONG MmSystemCachePage;
ULONG MmPagedPoolPage;
ULONG MmSystemDriverPage;
ULONG CcFastReadNoWait;
ULONG CcFastReadWait;
ULONG CcFastReadResourceMiss;
ULONG CcFastReadNotPossible;
ULONG CcFastMdlReadNoWait;
ULONG CcFastMdlReadWait;
ULONG CcFastMdlReadResourceMiss;
ULONG CcFastMdlReadNotPossible;
ULONG CcMapDataNoWait;
ULONG CcMapDataWait;
ULONG CcMapDataNoWaitMiss;
ULONG CcMapDataWaitMiss;
ULONG CcPinMappedDataCount;
ULONG CcPinReadNoWait;
ULONG CcPinReadWait;
ULONG CcPinReadNoWaitMiss;
ULONG CcPinReadWaitMiss;
ULONG CcCopyReadNoWait;
ULONG CcCopyReadWait;
ULONG CcCopyReadNoWaitMiss;
ULONG CcCopyReadWaitMiss;
ULONG CcMdlReadNoWait;
ULONG CcMdlReadWait;
ULONG CcMdlReadNoWaitMiss;
ULONG CcMdlReadWaitMiss;
ULONG CcReadaheadIos;
ULONG CcLazyWriteIos;
ULONG CcLazyWritePages;
ULONG CcDataFlushes;
ULONG CcDataPages;
ULONG ContextSwitches;
ULONG Unknown13;
ULONG Unknown14;
ULONG SystemCalls;
#endif
return EXIT_SUCCESS;
}
/**********************************************************************
*
* DESCRIPTION
*
* NOTE
* Class 3.
*/
CMD_DEF(3)
{
NTSTATUS Status;
SYSTEM_TIMEOFDAY_INFORMATION Info;
Status = NtQuerySystemInformation (
3,
& Info,
sizeof Info,
NULL
);
if (STATUS_SUCCESS != Status)
{
PrintStatus (Status);
return EXIT_FAILURE;
}
PrintUtcDateTime (" BootTime %s\n", (PTIME) & Info.BootTime);
PrintUtcDateTime (" CurrentTime %s\n", (PTIME) & Info.CurrentTime);
PrintUtcDateTime (" TimeZoneBias %s\n", (PTIME) & Info.TimeZoneBias); /* FIXME */
printf (" TimeZoneId %ld\n", Info.TimeZoneId);
printf (" Reserved %08lx\n", Info.Reserved);
return EXIT_SUCCESS;
}
/**********************************************************************
*
* DESCRIPTION
*
* NOTE
* Class 4.
*/
CMD_DEF(4)
{
NTSTATUS Status;
SYSTEM_PATH_INFORMATION Info;
CHAR _Info [_MAX_PATH];
ULONG Length = 0;
RtlZeroMemory (& Info, _MAX_PATH);
Status = NtQuerySystemInformation (
4,
& _Info,
_MAX_PATH,
& Length
);
if (STATUS_SUCCESS != Status)
{
PrintStatus (Status);
DumpData (_MAX_PATH, & _Info);
return EXIT_FAILURE;
}
DumpData (_MAX_PATH, & _Info);
return EXIT_SUCCESS;
}
/**********************************************************************
*
* DESCRIPTION
* A snapshot of the process+thread tables.
*
* NOTE
* Class 5.
*/
CMD_DEF(5)
{
NTSTATUS Status = STATUS_SUCCESS;
PSYSTEM_PROCESS_INFORMATION pInfo = NULL;
LONG Length = 0;
ULONG ThreadIndex;
pInfo = GlobalAlloc (GMEM_ZEROINIT, BUFFER_SIZE_DEFAULT);
/* FIXME: check NULL==pInfo */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -