Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
12 KiB

  1. //***************************************************************************
  2. //
  3. // (c) 1997 by Microsoft Corporation
  4. //
  5. // bmof.h
  6. //
  7. // a-davj 14-April-97 Created.
  8. //
  9. // Describes the format of binary MOF files. In addition, it defines some
  10. // structures which specify the details of the format and also defines some
  11. // addtional structures and helper functions for navigating a BMOF file.
  12. //
  13. //***************************************************************************
  14. #ifndef __BMOF__
  15. #define __BMOF__
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. // Binary mof files contain a large blob of data which consists of stuctures
  20. // which contain other structures, etc. The layout of that blob is detailed in
  21. // the following comments. However, the binary files are compressed and always
  22. // starts off with the following DWORDS
  23. // [Signature] [Compression Type, Always 1] [Compressed size] [Expanded size] The blob follows!
  24. // An example of decompressing the file is in test.c
  25. //
  26. // The following is a BNF description of the structures that make up
  27. // a BMOF file and also serve to illustrate the basic layout of WBEM
  28. // objects.
  29. //
  30. // --A MOF is zero or more objects
  31. //
  32. // WBEM_Binary_MOF ::= WBEM_Object*;
  33. //
  34. // --An object is a qualifier list (applying to the entire object) and
  35. // --a property list
  36. //
  37. // WBEM_Object ::= WBEM_QualifierList WBEM_PropertyList;
  38. //
  39. // --A property list is zero or more properties
  40. //
  41. // WBEM_PropertyList ::= WBEM_Property*; / zero or more properties
  42. //
  43. // --A property is a set of qualifiers applying to the property, and
  44. // --a type, a name, and a value
  45. //
  46. // WBEM_Property ::= WBEM_QualifierList* <type> <name> <value>;
  47. //
  48. // --A qualifier list is zero or more qualifiers
  49. //
  50. // WBEM_QualifierList ::= WBEM_Qualifier*; -- zero or more qualifiers
  51. //
  52. // --A qualifier is a type, a name, and a value. However, the supported types
  53. // --are not as extensive as for properties.
  54. //
  55. // WBEM_Qualifier ::= <type> <name> <value>;
  56. //
  57. //
  58. // Note that a qualifier set (a list of qualifiers) can be applied
  59. // to the entire object or to individual properties. However, qualifiers
  60. // cannot be applied to other qualifiers:
  61. //
  62. // object = quals + props
  63. // prop = quals + name + value
  64. // qual = name + value
  65. //
  66. // Information such as the name of a class, the super class, etc., are coded
  67. // as property values. Finding the value of the property __CLASS, for example,
  68. // gives the name of the class. All properties beginning with a double
  69. // underscore are well-known system properties common to all WBEM objects.
  70. // All other properties are user-defined.
  71. //
  72. // The list of predefined properties is found in WBEM documentation.
  73. //
  74. // Offsets are relative to their owning structure, not absolute to the
  75. // entire encoding image. This allows moving the subcomponents around
  76. // without rencoding everything.
  77. //
  78. // Note that an offset of 0xFFFFFFFF indicates that the field is not used.
  79. //
  80. // Both properties and qualifiers have value fields which contain data based
  81. // on Ole Automation types. Qualifiers are simple types (no arrays or
  82. // embedded objects) while property values might contain arrays and/or
  83. // embedded objects.
  84. //
  85. // One difference from Ole is that BSTRs are actually stored as WCHAR
  86. // strings even if the data type is marked as BSTR.
  87. //
  88. // In addition, some qualifiers or properties are actually aliases which
  89. // must be resolved later. Aliases are stored as BSTR values and the type
  90. // field is set to VT_BSTR | VT_BYREF. An array of alias strings is a bit
  91. // more complicated since not all the elements need be aliases. In the array
  92. // case, each actual alias string is prepended with a L'$' while each
  93. // "regular" string is prepended by a L' '.
  94. //
  95. // Currently, only scalars and single dimensional arrays are supported.
  96. // However, the BMOF file layout is designed so as to accommodate multi-
  97. // dimensional array in the future. For array data, the data is layout out
  98. //
  99. // ArrayData ::= ArrayHeaderData + RowOfData*;
  100. //
  101. // The ArrayHeaderData has the form;
  102. // dwtotalsize, dwNumDimenstions, dwMostSigDimension... dwLeastSigDimension
  103. //
  104. // Currently only 1 dimensional arrays are supported, a 5 element
  105. // array would start with;
  106. // dwSize, 1, 5
  107. //
  108. // After the header, one or more rows would follow. A row represents the
  109. // "most rapidly changing" data. Currently, there is only one row.
  110. //
  111. // The row format is;
  112. //
  113. // dwSizeOfRow, MostSigDimension ... dwLeastSignificentDimension+1,data
  114. // For a one dimensional array, it would just be
  115. // dwSizeOfRow, Data
  116. //
  117. // The extension for supporting qualifier flavors is to add the following data after the current blob.
  118. //
  119. // typedef struct
  120. // {
  121. // WCHAR wcSignature; // the string BMOFQUALFLAVOR11
  122. // DWORD dwNumPair;
  123. // // BYTE FlavorInfo[]; // Blob containing array of WBEM_Object structs
  124. // }WBEM_Binary_FLAVOR;
  125. //
  126. // The FlavorInfo blob will be a series of DWORD pairs of the form
  127. //
  128. // Typedef struct
  129. // {
  130. // DWORD dwOffsetInOriginalBlob;
  131. // DWORD dwFlavor;
  132. // }
  133. // Each Binary MOF file starts off with these signature bytes.
  134. #define BMOF_SIG 0x424d4f46
  135. // The following structures exactly describe the contents of a BMOF file.
  136. // These can be used to navigate the file using the various offsets and
  137. // lots of casting.
  138. typedef struct
  139. {
  140. DWORD dwSignature; // four characters, BMOF
  141. DWORD dwLength;
  142. DWORD dwVersion; // 0x1
  143. DWORD dwEncoding; // 0x1 = little endian, DWORD-aligned, no compression
  144. DWORD dwNumberOfObjects; // Total classes and instances in MOF
  145. // BYTE Info[]; // Blob containing array of WBEM_Object structs
  146. // First object is at offset 0.
  147. }WBEM_Binary_MOF;
  148. typedef struct // Describes a class or instance
  149. {
  150. DWORD dwLength;
  151. DWORD dwOffsetQualifierList;
  152. DWORD dwOffsetPropertyList;
  153. DWORD dwOffsetMethodList;
  154. DWORD dwType; // 0 = class, 1 = instance
  155. // BYTE Info[]; // Blob of qualifier set and properties
  156. }WBEM_Object;
  157. typedef struct
  158. {
  159. DWORD dwLength;
  160. DWORD dwNumberOfProperties;
  161. // BYTE Info[]; // Blob with all properties placed end-to-end
  162. }WBEM_PropertyList;
  163. typedef struct
  164. {
  165. DWORD dwLength; // Length of this struct
  166. DWORD dwType; // A VT_ type from WTYPES.H (VT_I4, VT_UI8, etc)
  167. DWORD dwOffsetName; // Offset in <Info> of the null-terminated name.
  168. DWORD dwOffsetValue; // Offset in <Info> of the value.
  169. DWORD dwOffsetQualifierSet; //
  170. // BYTE Info[]; // Contains qualifier set, name, and value
  171. }WBEM_Property;
  172. // Rough encoding example for a string:
  173. //
  174. // dwLength = 10;
  175. // dwType = VT_LPWSTR;
  176. // dwOffsetName = 0;
  177. // dwOffsetValue = 8;
  178. // dwOffsetQualifierSet = 0xFFFFFFFF; // Indicates not used
  179. //
  180. // Info[] = "CounterValue\0<default value>\0";
  181. typedef struct
  182. {
  183. DWORD dwLength;
  184. DWORD dwNumQualifiers;
  185. // BYTE Info[]; // Array of WBEM_Qualifiers placed end-to-end
  186. }WBEM_QualifierList;
  187. typedef struct
  188. {
  189. DWORD dwLength; // Length of this struct
  190. DWORD dwType; // A VT_ type from WTYPES.H (VT_I4, VT_UI8, etc)
  191. DWORD dwOffsetName; // Offset in <Info> of the null-terminated name.
  192. DWORD dwOffsetValue; // Offset in <Info> of the value.
  193. // BYTE Info[];
  194. }WBEM_Qualifier;
  195. // These structures and the helper functions that go with them can be used
  196. // to easily navigate a BMOF file. These structures "wrap" the above
  197. // structures so as to provide features such as searching and enumeration.
  198. typedef struct
  199. {
  200. WBEM_QualifierList * m_pql;
  201. WBEM_Qualifier * m_pInfo;
  202. DWORD m_CurrQual;
  203. WBEM_Qualifier * m_pCurr;
  204. }CBMOFQualList;
  205. typedef struct
  206. {
  207. WBEM_Object * m_pob;
  208. BYTE * m_pInfo;
  209. WBEM_PropertyList * m_ppl;
  210. DWORD m_CurrProp;
  211. WBEM_Property * m_pCurrProp;
  212. WBEM_PropertyList * m_pml;
  213. DWORD m_CurrMeth;
  214. WBEM_Property * m_pCurrMeth;
  215. }CBMOFObj;
  216. typedef struct
  217. {
  218. WBEM_Binary_MOF * m_pol;
  219. DWORD m_CurrObj;
  220. WBEM_Object * m_pInfo;
  221. WBEM_Object * m_pCurrObj;
  222. }CBMOFObjList;
  223. typedef struct
  224. {
  225. BYTE * m_pData;
  226. DWORD m_dwType;
  227. }CBMOFDataItem;
  228. //
  229. // Qualifier flavor definitions
  230. #define FlavorAmended 0x80
  231. #define FlavorDisableOverride 0x10
  232. #define FlavorToSubclass 0x02
  233. #define FlavorToInstance 0x01
  234. // Using any of the following help functions requires that these two
  235. // functions be provided in another module and allow independence from
  236. // any particular allocation method.
  237. //
  238. // redefine the BMOF allocation routines to be the same as the WMI allocation
  239. // routines.
  240. #define BMOFFree(p) WmipFree(p)
  241. #define BMOFAlloc(s) WmipAlloc(s)
  242. // These functions wrap the object list and provider for enumeration of
  243. // the objects.
  244. CBMOFObjList * _stdcall CreateObjList(BYTE * pBuff);
  245. void _stdcall ResetObjList(CBMOFObjList * pol);
  246. CBMOFObj * _stdcall NextObj(CBMOFObjList *pol);
  247. CBMOFObj * _stdcall FindObj(CBMOFObjList *pol, WCHAR * pName);
  248. // These functions allow access to the parts of a class or instance object
  249. void _stdcall ResetObj(CBMOFObj * pol);
  250. CBMOFQualList * _stdcall GetQualList(CBMOFObj * pol);
  251. CBMOFQualList * _stdcall GetPropQualList(CBMOFObj * pol, WCHAR * pName);
  252. CBMOFQualList * _stdcall GetMethQualList(CBMOFObj * pol, WCHAR * pName);
  253. BOOL _stdcall NextProp(CBMOFObj * pob, WCHAR ** ppName, CBMOFDataItem * pItem);
  254. BOOL _stdcall NextMeth(CBMOFObj * pob, WCHAR ** ppName, CBMOFDataItem * pItem);
  255. BOOL _stdcall FindProp(CBMOFObj * pob, WCHAR * pName, CBMOFDataItem * pItem);
  256. BOOL _stdcall FindMeth(CBMOFObj * pob, WCHAR * pName, CBMOFDataItem * pItem);
  257. BOOL _stdcall GetName(CBMOFObj * pob, WCHAR ** ppName);
  258. DWORD _stdcall GetType(CBMOFObj * pob);
  259. WBEM_Property * _stdcall FindPropPtr(CBMOFObj * pob, WCHAR * pName);
  260. WBEM_Property * _stdcall FindMethPtr(CBMOFObj * pob, WCHAR * pName);
  261. // These functions provide easy access to a qualifier list.
  262. void _stdcall ResetQualList(CBMOFQualList * pql);
  263. BOOL _stdcall NextQual(CBMOFQualList * pql,WCHAR ** ppName, CBMOFDataItem * pItem);
  264. BOOL _stdcall NextQualEx(CBMOFQualList * pql,WCHAR ** ppName, CBMOFDataItem * pItem,
  265. DWORD * pdwFlavor, BYTE * pBuff);
  266. BOOL _stdcall FindQual(CBMOFQualList * pql,WCHAR * pName, CBMOFDataItem * pItem);
  267. BOOL _stdcall FindQualEx(CBMOFQualList * pql,WCHAR * pName, CBMOFDataItem * pItem,
  268. DWORD * pdwFlavor, BYTE * pBuff);
  269. // These functions provide easy access to a data item. Note that data items
  270. // might be stored in arrays.
  271. int _stdcall GetNumDimensions(CBMOFDataItem *);
  272. int _stdcall GetNumElements(CBMOFDataItem *, long lDim);
  273. int _stdcall GetData(CBMOFDataItem *, BYTE * pRet, long * plDims);
  274. // These functions are mainly useful to the above helper functions
  275. int _stdcall iTypeSize(DWORD vtTest);
  276. BOOL _stdcall SetValue(CBMOFDataItem * pItem, BYTE * pInfo, DWORD dwOffset, DWORD dwType);
  277. BOOL _stdcall SetName(WCHAR ** ppName, BYTE * pInfo, DWORD dwOffset);
  278. CBMOFQualList * _stdcall CreateQualList(WBEM_QualifierList *pql);
  279. CBMOFObj * _stdcall CreateObj(WBEM_Object * pob);
  280. #ifdef __cplusplus
  281. }
  282. #endif
  283. #endif
  284.