Source code of Windows XP (NT5)
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.

334 lines
11 KiB

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