home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 February / Chip_2004-02_cd1.bin / zkuste / konfig / download / msic / Help / Int / MiTeC_Native.int < prev    next >
Text File  |  2003-08-26  |  9KB  |  259 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {         MiTeC System Information Components           }
  4. {               WinNT Native API                        }
  5. {           version 1.0 for Delphi 5,6                  }
  6. {                                                       }
  7. {           Copyright ⌐ 2002 Michal Mutl                }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. {$INCLUDE MITEC_DEF.INC}
  12.  
  13. unit MiTeC_Native;
  14.  
  15. interface
  16.  
  17. uses Windows, SysUtils;
  18.  
  19. type
  20.   TUnicodeString =  packed record
  21.     Length,
  22.     MaximumLength: WORD;
  23.     Buffer: PWideChar;
  24.   end;
  25.   PUnicodeString = ^TUnicodeString;
  26.  
  27.   TSystemInformationClass = (
  28.           SystemBasicInformation,
  29.           SystemProcessorInformation,
  30.           SystemPerformanceInformation,
  31.           SystemTimeOfDayInformation,
  32.           SystemNotImplemented1,
  33.           SystemProcessesAndThreadsInformation,
  34.           SystemCallCounts,
  35.           SystemConfigurationInformation,
  36.           SystemProcessorTimes,
  37.           SystemGlobalFlag,
  38.           SystemNotImplemented2,
  39.           SystemModuleInformation,
  40.           SystemLockInformation,
  41.           SystemNotImplemented3,
  42.           SystemNotImplemented4,
  43.           SystemNotImplemented5,
  44.           SystemHandleInformation,
  45.           SystemObjectInformation,
  46.           SystemPagefileInformation,
  47.           SystemInstructionEmulationCounts,
  48.           SystemInvalidInfoClass1,
  49.           SystemCacheInformation,
  50.           SystemPoolTagInformation,
  51.           SystemProcessorStatistics,
  52.           SystemDpcInformation,
  53.           SystemNotImplemented6,
  54.           SystemLoadImage,
  55.           SystemUnloadImage,
  56.           SystemTimeAdjustment,
  57.           SystemNotImplemented7,
  58.           SystemNotImplemented8,
  59.           SystemNotImplemented9,
  60.           SystemCrashDumpInformation,
  61.           SystemExceptionInformation,
  62.           SystemCrashDumpStateInformation,
  63.           SystemKernelDebuggerInformation,
  64.           SystemContextSwitchInformation,
  65.           SystemRegistryQuotaInformation,
  66.           SystemLoadAndCallImage,
  67.           SystemPrioritySeparation,
  68.           SystemNotImplemented10,
  69.           SystemNotImplemented11,
  70.           SystemInvalidInfoClass2,
  71.           SystemInvalidInfoClass3,
  72.           SystemTimeZoneInformation,
  73.           SystemLookasideInformation,
  74.           SystemSetTimeSlipEvent,
  75.           SystemCreateSession,
  76.           SystemDeleteSession,
  77.           SystemInvalidInfoClass4,
  78.           SystemRangeStartInformation,
  79.           SystemVerifierInformation,
  80.           SystemAddVerifier,
  81.           SystemSessionProcessesInformation);
  82.  
  83.   TSystemProcessorTimes = packed record
  84.      IdleTime,
  85.      KernelTime,
  86.      UserTime,
  87.      DpcTime,
  88.      InterruptTime: int64;
  89.      InterruptCount: DWORD;
  90.   end;
  91.   PSystemProcessorTimes = ^TSystemProcessorTimes;
  92.  
  93.   _CLIENT_ID = record
  94.     UniqueProcess: DWORD;
  95.     UniqueThread: DWORD;
  96.   end;
  97.   TClientID = _CLIENT_ID;
  98.   PClientID = ^TClientID;
  99.  
  100.   _SYSTEM_THREAD_INFORMATION = record
  101.     KernelTime: LARGE_INTEGER;             // time spent in kernel mode
  102.     UserTime: LARGE_INTEGER;               // time spent in user mode
  103.     CreateTime: LARGE_INTEGER;             // thread creation time
  104.     WaitTime: DWORD;               // wait time
  105.     StartAddress: Pointer;           // start address
  106.     ClientId: TClientID;               // thread and process IDs
  107.     Priority: integer;               // dynamic priority
  108.     BasePriority: DWORD;           // base priority
  109.     ContextSwitchCount: DWORD;     // number of context switches
  110.     State: Integer;                  // current state
  111.     WaitReason: integer;             // wait reason
  112.   end;
  113.   TSystemThreadInformation = _SYSTEM_THREAD_INFORMATION;
  114.   PSystemThreadInformation = ^TSystemThreadInformation;
  115.  
  116.   _VM_COUNTERS = record
  117.     PeakVirtualSize: DWORD;
  118.     VirtualSize: DWORD;
  119.     PageFaultCount: DWORD;
  120.     PeakWorkingSetSize: DWORD;
  121.     WorkingSetSize: DWORD;
  122.     QuotaPeakPagedPoolUsage: DWORD;
  123.     QuotaPagedPoolUsage: DWORD;
  124.     QuotaPeakNonPagedPoolUsage: DWORD;
  125.     QuotaNonPagedPoolUsage: DWORD;
  126.     PagefileUsage: DWORD;
  127.     PeakPagefileUsage: DWORD;
  128.   end;
  129.   TVMCounters = _VM_COUNTERS;
  130.   PVMCounters = ^TVMCounters;
  131.  
  132.   _IO_COUNTERS  = record
  133.     ReadOperationCount: LARGE_INTEGER;
  134.     WriteOperationCount: LARGE_INTEGER;
  135.     OtherOperationCount: LARGE_INTEGER;
  136.     ReadTransferCount: LARGE_INTEGER;
  137.     WriteTransferCount: LARGE_INTEGER;
  138.     OtherTransferCount: LARGE_INTEGER;
  139.   end;
  140.   TIOCounters = _IO_COUNTERS;
  141.   PIoCounters = ^TIoCounters;
  142.  
  143.   _SYSTEM_PROCESS_INFORMATION = record
  144.     NextEntryDelta: DWORD;         // offset to the next entry
  145.     ThreadCount: DWORD;            // number of threads
  146.     Reserved1: array[0..5] of DWORD;           // reserved
  147.     CreateTime: LARGE_INTEGER;             // process creation time
  148.     UserTime: LARGE_INTEGER;               // time spent in user mode
  149.     KernelTime: LARGE_INTEGER;             // time spent in kernel mode
  150.     ProcessName: TUnicodeString;            // process name
  151.     BasePriority: Integer;           // base process priority
  152.     ProcessId: DWORD;              // process identifier
  153.     InheritedFromProcessId: DWORD; // parent process identifier
  154.     HandleCount: DWORD;            // number of handles
  155.     Reserved2: array[0..1] of DWORD;           // reserved
  156.     VmCounters: TVmCounters;             // virtual memory counters
  157.     IoCounters: TIoCounters;             // i/o counters
  158.     Threads: array[0..0] of TSystemThreadInformation;   // threads
  159.   end;
  160.   TSystemProcessInformation = _SYSTEM_PROCESS_INFORMATION;
  161.   PSystemProcessInformation = ^TSystemProcessInformation;
  162.  
  163.   TTokenUser = packed record
  164.     User: TSIDAndAttributes;
  165.   end;
  166.   PTokenUser = ^TTokenUser;
  167.  
  168.   TTokenOwner = packed record
  169.     Owner: PSID;
  170.   end;
  171.   PTokenOwner = ^TTokenOwner;
  172.  
  173.   {TTokenPrivileges = packed record
  174.      PrivilegeCount: DWORD;
  175.      Privileges: array of TLUIDAndAttributes;
  176.   end;
  177.   PTokenPrivileges = ^TTokenPrivileges;}
  178.  
  179.   TTokenPrimaryGroup = packed record
  180.     PrimaryGroup: PSID;
  181.   end;
  182.   PTokenPrimaryGroup = ^TTokenPrimaryGroup;
  183.  
  184.   TTokenDefaultDACL = packed record
  185.     DefaultDacl: PACL;
  186.   end;
  187.   PTokenDefaultDACL = ^TTokenDefaultDACL;
  188.  
  189.   {TTokenInformationClass = (TokenPad,TokenUser,TokenGroups,TokenPrivileges,TokenOwner,
  190.                            TokenPrimaryGroup,TokenDefaultDacl,TokenSource,TokenType,
  191.                            TokenImpersonationLevel,TokenStatistics,TokenRestrictedSids,
  192.                            TokenSessionId);}
  193.  
  194.   TObjectAttributes = packed record
  195.      Length: DWORD;
  196.      RootDirectory: THandle;
  197.      ObjectName: PUnicodeString;
  198.      Attributes: DWORD;
  199.      SecurityDescriptor: Pointer;// Points to type SECURITY_DESCRIPTOR
  200.      SecurityQualityOfService: Pointer;// Points to type SECURITY_QUALITY_OF_SERVICE
  201.   end;
  202.   PObjectAttributes = ^TObjectAttributes;
  203.  
  204.   TNativeQueryInformationToken = function(TokenHandle: THandle;
  205.                                           TokenInformationClass: TTokenInformationClass;
  206.                                           TokenInformation :Pointer;
  207.                                           TokenInformationLength :DWORD;
  208.                                           ReturnLength :PDWORD): DWORD; stdcall;
  209.  
  210.   TNativeOpenProcessToken = function(ProcessHandle: THandle;
  211.                                      DesiredAccess: DWORD;
  212.                                      TokenHandle: PHandle) :DWORD; stdcall;
  213.  
  214.   TNativeOpenProcess = function(ProcessHandle: PHandle;
  215.                                 DesiredAccess: DWORD;
  216.                                 ObjectAttributes: PObjectAttributes;
  217.                                 ClientId: PClientID): DWORD; stdcall;
  218.  
  219.   TNativeOpenSection = function(SectionHandle: PHandle;
  220.                                 DesiredAccess: DWORD;
  221.                                 ObjectAttributes: PObjectAttributes): DWORD; stdcall;
  222.  
  223.   TNativeClose = function(Handle: THandle): DWORD; stdcall;
  224.  
  225.   TNativeQuerySystemInformation = function(SystemInformationClass: TSystemInformationClass;
  226.                                            SystemInformation: Pointer;
  227.                                            SystemInformationLength: DWORD;
  228.                                            ReturnLength: PDWORD): DWORD; stdcall;
  229.  
  230. const
  231.   NTDLL_DLL_Name = 'NTDLL.DLL';
  232.  
  233.   STATUS_SUCCESS = $00000000;
  234.   STATUS_INFO_LENGTH_MISMATCH = $C0000004;
  235.   STATUS_BUFFER_OVERFLOW = $80000005;
  236.  
  237.   //Valid values for the Attributes field
  238.   OBJ_INHERIT = $00000002;
  239.   OBJ_PERMANENT = $00000010;
  240.   OBJ_EXCLUSIVE = $00000020;
  241.   OBJ_CASE_INSENSITIVE = $00000040;
  242.   OBJ_OPENIF = $00000080;
  243.   OBJ_OPENLINK = $00000100;
  244.   OBJ_VALID_ATTRIBUTES = $000001F2;
  245.  
  246.  
  247. var
  248.   NTDLL_DLL: THandle = 0;
  249.  
  250.   ZwOpenSection: TNativeOpenSection = nil;
  251.   ZwClose: TNativeClose = nil;
  252.   ZwQueryInformationToken: TNativeQueryInformationToken = nil;
  253.   ZwOpenProcessToken: TNativeOpenProcessToken = nil;
  254.   ZwOpenProcess: TNativeOpenProcess = nil;
  255.   ZwQuerySystemInformation: TNativeQuerySystemInformation = nil;
  256.  
  257. implementation
  258.  
  259.