// ntdll!NtQuerySystemInformation (NT specific!)
//
// The function copies the system information of the
// specified type into a buffer
//
// NTSYSAPI
// NTSTATUS
// NTAPI
// NtQuerySystemInformation(
// IN UINT SystemInformationClass, // information type
// OUT PVOID SystemInformation, // pointer to buffer
// IN ULONG SystemInformationLength, // buffer size in bytes
// OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit
// // variable that receives
// // the number of bytes
// // written to the buffer
// );
typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
// get number of processors in the system
status = NtQuerySystemInformation(SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL);
if (status != NO_ERROR)
return;
printf("\nCPU Usage (press any key to exit): ");
while(!_kbhit())
{
// get new system time
status = NtQuerySystemInformation(SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0);
if (status!=NO_ERROR)
return;
// get new CPU's idle time
status = NtQuerySystemInformation(SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL);
if (status != NO_ERROR)
return;
// if it's a first call - skip it
if (liOldIdleTime.QuadPart != 0)
{
// CurrentValue = NewValue - OldValue
dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
push OFFSET $SG-5
xor edi, edi
xor ebx, ebx
push OFFSET $SG-6
xor esi, esi
mov DWORD PTR _liOldIdleTime$[esp+452], ebx
mov DWORD PTR _liOldSystemTime$[esp+452], edi
call DWORD PTR __imp__GetModuleHandleA@4
push eax
call DWORD PTR __imp__GetProcAddress@8
; 87 :
; 88 : if (!NtQuerySystemInformation)
cmp eax, edi
mov DWORD PTR ?NtQuerySystemInformation@@3P6GJIPAXKPAK@ZA, eax ; NtQuerySystemInformation
je $LN17@main
; 89 : return;
; 90 :
; 91 : // get number of processors in the system
; 92 : status = NtQuerySystemInformation(SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL);
push edi
push 44 ; 0000002cH
lea ecx, DWORD PTR _SysBaseInfo$[esp+448]
push ecx
push edi
call eax
; 93 : if (status != NO_ERROR)
test eax, eax
jne $LN17@main
; 94 : return;
; 95 :
; 96 : printf("\nCPU Usage (press any key to exit): ");