От: | CL0NE | ||
Дата: | 07.09.09 20:32 | ||
Оценка: |
NTSTATUS WINAPI ZwQuerySystemInformation( __in SYSTEM_INFORMATION_CLASS SystemInformationClass, __inout PVOID SystemInformation, __in ULONG SystemInformationLength, __out_opt PULONG ReturnLength );
[DllImport("Ntdll.dll", EntryPoint="ZwQuerySystemInformation")]
static extern Int32 APIQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass,
IntPtr SystemInformation,
int SystemInformationLength,
out long ReturnLength);
SystemInformationClass
The type of system information to be retrieved. This parameter can be one of the following values from the SYSTEM_INFORMATION_CLASS enumeration type.
public enum SYSTEM_INFORMATION_CLASS
{
SystemBasicInformation = 0x02c,
SystemPerformanceInformation = 0x138,
SystemTimeOfDayInformation = 0x020,
SystemProcessInformation = 0x088,
SystemProcessorPerformanceInformation = 0x030,
SystemInterruptInformation = 0x018,
SystemExceptionInformation = 0x010
}
SystemBasicInformation
The number of processors in the system in a SYSTEM_BASIC_INFORMATION structure. Use the GetSystemInfo function instead.
(лень переводить)SystemInformation
A pointer to a buffer that receives the requested information. The size and structure of this information varies depending on the value of the SystemInformationClass parameter, as indicated in the following table.
SYSTEM_BASIC_INFORMATION
When the SystemInformationClass parameter is SystemBasicInformation, the buffer pointed to by the SystemInformation parameter should be large enough to hold a single SYSTEM_BASIC_INFORMATION structure having the following layout:
typedef struct _SYSTEM_BASIC_INFORMATION { BYTE Reserved1[24]; PVOID Reserved2[4]; CCHAR NumberOfProcessors; } SYSTEM_BASIC_INFORMATION;
The NumberOfProcessors member contains the number of processors present in the system. Use GetSystemInfo instead to retrieve this information.
The other members of the structure are reserved for internal use by the operating system.
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_BASIC_INFORMATION {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public byte[] Reserved1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public IntPtr[] Reserved2;
public Char NumberOfProcessors;
}
Первый при удачном вызове, третий — при слишком маленьком буфере.//STATUS_SUCCESS = NTStatus($00000000); //STATUS_ACCESS_DENIED = NTStatus($C0000022); //STATUS_INFO_LENGTH_MISMATCH = NTStatus($C0000004); //SEVERITY_ERROR = NTStatus($C0000000);
long formal;
int size = Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION));
IntPtr ptr = Marshal.AllocHGlobal(size);
Console.WriteLine("NTSTATUS: " + APIQuerySystemInformation(SYSTEM_INFORMATION_CLASS.SystemBasicInformation, ptr, size, out formal).ToString("X"));
SYSTEM_BASIC_INFORMATION INFO = ((SYSTEM_BASIC_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_BASIC_INFORMATION)));
Console.WriteLine(INFO.NumberOfProcessors);
Console.WriteLine(formal);
От: | Аноним | ||
Дата: | 09.09.09 22:16 | ||
Оценка: |
а откуда ты взял значения энума SYSTEM_INFORMATION_CLASS?
везде, где попадались, SystemBasicInformation был равен 0
например, здесь
если взять оттуда и структуру
[StructLayout(LayoutKind.Sequential)]
struct SYSTEM_BASIC_INFORMATION
{
public int Reserved;
public int TimerResolution;
public int PageSize; // 4096 (4kB) on 32-bit systems, 8192 (8kB) on 64-bit systems
public int NumberOfPhysicalPages; // pages of physical memory
public int LowestPhysicalPageNumber;
public int HighestPhysicalPageNumber;
public int AllocationGranularity;
public int MinimumUserModeAddress;
public int MaximumUserModeAddress;
public int ActiveProcessorsAffinityMask;
public byte NumberOfProcessors;
}
то на домашней висте успешно выдалось 2 процессора
а вот на рабочем 2003 сервере не прокатило
тем не менее, и там, и там по коду 0x02c мне выдавался требуемый размер памяти, равный 172, ни из твоего варианта структуры, ни из моего такой размер не получить, у нас 44
так, кстати, я и убедился, что 0 — подходящее значение, при нём и при 62(0x3E) выдавалось 44 требуемых байта (при 62 те же значения полей структуры). ни одно другое число из интервала 0..99999999 44 не дало
Только что, погуглив, нашел где я их взял. http://undocumented.ntinternals.net/[q]
а откуда ты взял значения энума SYSTEM_INFORMATION_CLASS?
значением...Buffer size : 0x02C
От: | CL0NE | ||
Дата: | 22.09.09 12:43 | ||
Оценка: |
public enum SYSTEM_INFORMATION_CLASS : int
{
SystemBasicInformation,
SystemProcessorInformation,
SystemPerformanceInformation,
SystemTimeOfDayInformation,
SystemPathInformation,
SystemProcessInformation,
SystemCallCountInformation,
SystemDeviceInformation,
SystemProcessorPerformanceInformation,
SystemFlagsInformation,
SystemCallTimeInformation,
SystemModuleInformation,
SystemLocksInformation,
SystemStackTraceInformation,
SystemPagedPoolInformation,
SystemNonPagedPoolInformation,
SystemHandleInformation,
SystemObjectInformation,
SystemPageFileInformation,
SystemVdmInstemulInformation,
SystemVdmBopInformation,
SystemFileCacheInformation,
SystemPoolTagInformation,
SystemInterruptInformation,
SystemDpcBehaviorInformation,
SystemFullMemoryInformation,
SystemLoadGdiDriverInformation,
SystemUnloadGdiDriverInformation,
SystemTimeAdjustmentInformation,
SystemSummaryMemoryInformation,
SystemMirrorMemoryInformation,
SystemPerformanceTraceInformation,
SystemCrashDumpInformation,
SystemExceptionInformation,
SystemCrashDumpStateInformation,
SystemKernelDebuggerInformation,
SystemContextSwitchInformation,
SystemRegistryQuotaInformation,
SystemExtendServiceTableInformation, // used to be SystemLoadAndCallImage
SystemPrioritySeparation,
SystemVerifierAddDriverInformation,
SystemVerifierRemoveDriverInformation,
SystemProcessorIdleInformation,
SystemLegacyDriverInformation,
SystemCurrentTimeZoneInformation,
SystemLookasideInformation,
SystemTimeSlipNotification,
SystemSessionCreate,
SystemSessionDetach,
SystemSessionInformation,
SystemRangeStartInformation,
SystemVerifierInformation,
SystemVerifierThunkExtend,
SystemSessionProcessInformation,
SystemLoadGdiDriverInSystemSpace,
SystemNumaProcessorMap,
SystemPrefetcherInformation,
SystemExtendedProcessInformation,
SystemRecommendedSharedDataAlignment,
SystemComPlusPackage,
SystemNumaAvailableMemory, // 60
SystemProcessorPowerInformation,
SystemEmulationBasicInformation,
SystemEmulationProcessorInformation,
SystemExtendedHandleInformation,
SystemLostDelayedWriteInformation,
SystemBigPoolInformation,
SystemSessionPoolTagInformation,
SystemSessionMappedViewInformation,
SystemHotpatchInformation,
SystemObjectSecurityMode, // 70
SystemWatchdogTimerHandler, // doesn't seem to be implemented
SystemWatchdogTimerInformation,
SystemLogicalProcessorInformation,
SystemWow64SharedInformation,
SystemRegisterFirmwareTableInformationHandler,
SystemFirmwareTableInformation,
SystemModuleInformationEx,
SystemVerifierTriageInformation,
SystemSuperfetchInformation,
SystemMemoryListInformation, // 80
SystemFileCacheInformationEx,
SystemNotImplemented19,
SystemProcessorDebugInformation,
SystemVerifierInformation2,
SystemNotImplemented20,
SystemRefTraceInformation,
SystemSpecialPoolTag, // MmSpecialPoolTag, then MmSpecialPoolCatchOverruns != 0
SystemProcessImageName,
SystemNotImplemented21,
SystemBootEnvironmentInformation, // 90
SystemEnlightenmentInformation,
SystemVerifierInformationEx,
SystemNotImplemented22,
SystemNotImplemented23,
SystemCovInformation,
SystemNotImplemented24,
SystemNotImplemented25,
SystemPartitionInformation,
SystemSystemDiskInformation, // this and SystemPartitionInformation both call IoQuerySystemDeviceName
SystemPerformanceDistributionInformation, // 100
SystemNumaProximityNodeInformation,
SystemTimeZoneInformation2,
SystemCodeIntegrityInformation,
SystemNotImplemented26,
SystemUnknownInformation, // No symbols for this case, very strange...
SystemVaInformation // 106, calls MmQuerySystemVaInformation
}