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.

309 lines
9.8 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  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. // Each Binary MOF file starts off with these signature bytes.
  116. #define BMOF_SIG 0x424d4f46
  117. // The following structures exactly describe the contents of a BMOF file.
  118. // These can be used to navigate the file using the various offsets and
  119. // lots of casting.
  120. typedef struct
  121. {
  122. DWORD dwSignature; // four characters, BMOF
  123. DWORD dwLength;
  124. DWORD dwVersion; // 0x1
  125. DWORD dwEncoding; // 0x1 = little endian, DWORD-aligned, no compression
  126. DWORD dwNumberOfObjects; // Total classes and instances in MOF
  127. // BYTE Info[]; // Blob containing array of WBEM_Object structs
  128. // First object is at offset 0.
  129. }WBEM_Binary_MOF;
  130. typedef struct // Describes a class or instance
  131. {
  132. DWORD dwLength;
  133. DWORD dwOffsetQualifierList;
  134. DWORD dwOffsetPropertyList;
  135. DWORD dwOffsetMethodList;
  136. DWORD dwType; // 0 = class, 1 = instance
  137. // BYTE Info[]; // Blob of qualifier set and properties
  138. }WBEM_Object;
  139. typedef struct
  140. {
  141. DWORD dwLength;
  142. DWORD dwNumberOfProperties;
  143. // BYTE Info[]; // Blob with all properties placed end-to-end
  144. }WBEM_PropertyList;
  145. typedef struct
  146. {
  147. DWORD dwLength; // Length of this struct
  148. DWORD dwType; // A VT_ type from WTYPES.H (VT_I4, VT_UI8, etc)
  149. DWORD dwOffsetName; // Offset in <Info> of the null-terminated name.
  150. DWORD dwOffsetValue; // Offset in <Info> of the value.
  151. DWORD dwOffsetQualifierSet; //
  152. // BYTE Info[]; // Contains qualifier set, name, and value
  153. }WBEM_Property;
  154. // Rough encoding example for a string:
  155. //
  156. // dwLength = 10;
  157. // dwType = VT_LPWSTR;
  158. // dwOffsetName = 0;
  159. // dwOffsetValue = 8;
  160. // dwOffsetQualifierSet = 0xFFFFFFFF; // Indicates not used
  161. //
  162. // Info[] = "CounterValue\0<default value>\0";
  163. typedef struct
  164. {
  165. DWORD dwLength;
  166. DWORD dwNumQualifiers;
  167. // BYTE Info[]; // Array of WBEM_Qualifiers placed end-to-end
  168. }WBEM_QualifierList;
  169. typedef struct
  170. {
  171. DWORD dwLength; // Length of this struct
  172. DWORD dwType; // A VT_ type from WTYPES.H (VT_I4, VT_UI8, etc)
  173. DWORD dwOffsetName; // Offset in <Info> of the null-terminated name.
  174. DWORD dwOffsetValue; // Offset in <Info> of the value.
  175. // BYTE Info[];
  176. }WBEM_Qualifier;
  177. // These structures and the helper functions that go with them can be used
  178. // to easily navigate a BMOF file. These structures "wrap" the above
  179. // structures so as to provide features such as searching and enumeration.
  180. typedef struct
  181. {
  182. WBEM_QualifierList * m_pql;
  183. WBEM_Qualifier * m_pInfo;
  184. DWORD m_CurrQual;
  185. WBEM_Qualifier * m_pCurr;
  186. }CBMOFQualList;
  187. typedef struct
  188. {
  189. WBEM_Object * m_pob;
  190. BYTE * m_pInfo;
  191. WBEM_PropertyList * m_ppl;
  192. DWORD m_CurrProp;
  193. WBEM_Property * m_pCurrProp;
  194. WBEM_PropertyList * m_pml;
  195. DWORD m_CurrMeth;
  196. WBEM_Property * m_pCurrMeth;
  197. }CBMOFObj;
  198. typedef struct
  199. {
  200. WBEM_Binary_MOF * m_pol;
  201. DWORD m_CurrObj;
  202. WBEM_Object * m_pInfo;
  203. WBEM_Object * m_pCurrObj;
  204. }CBMOFObjList;
  205. typedef struct
  206. {
  207. BYTE * m_pData;
  208. DWORD m_dwType;
  209. }CBMOFDataItem;
  210. // Using any of the following help functions requires that these two
  211. // functions be provided in another module and allow independence from
  212. // any particular allocation method.
  213. void * BMOFAlloc(size_t Size);
  214. void BMOFFree(void * pFree);
  215. // These functions wrap the object list and provider for enumeration of
  216. // the objects.
  217. CBMOFObjList * CreateObjList(BYTE * pBuff);
  218. void ResetObjList(CBMOFObjList * pol);
  219. CBMOFObj * NextObj(CBMOFObjList *pol);
  220. CBMOFObj * FindObj(CBMOFObjList *pol, WCHAR * pName);
  221. // These functions allow access to the parts of a class or instance object
  222. void ResetObj(CBMOFObj * pol);
  223. CBMOFQualList * GetQualList(CBMOFObj * pol);
  224. CBMOFQualList * GetPropQualList(CBMOFObj * pol, WCHAR * pName);
  225. CBMOFQualList * GetMethQualList(CBMOFObj * pol, WCHAR * pName);
  226. BOOL NextProp(CBMOFObj * pob, WCHAR ** ppName, CBMOFDataItem * pItem);
  227. BOOL NextMeth(CBMOFObj * pob, WCHAR ** ppName, CBMOFDataItem * pItem);
  228. BOOL FindProp(CBMOFObj * pob, WCHAR * pName, CBMOFDataItem * pItem);
  229. BOOL FindMeth(CBMOFObj * pob, WCHAR * pName, CBMOFDataItem * pItem);
  230. BOOL GetName(CBMOFObj * pob, WCHAR ** ppName);
  231. DWORD GetType(CBMOFObj * pob);
  232. WBEM_Property * FindPropPtr(CBMOFObj * pob, WCHAR * pName);
  233. WBEM_Property * FindMethPtr(CBMOFObj * pob, WCHAR * pName);
  234. // These functions provide easy access to a qualifier list.
  235. void ResetQualList(CBMOFQualList * pql);
  236. BOOL NextQual(CBMOFQualList * pql,WCHAR ** ppName, CBMOFDataItem * pItem);
  237. BOOL FindQual(CBMOFQualList * pql,WCHAR * pName, CBMOFDataItem * pItem);
  238. // These functions provide easy access to a data item. Note that data items
  239. // might be stored in arrays.
  240. int GetNumDimensions(CBMOFDataItem *);
  241. int GetNumElements(CBMOFDataItem *, long lDim);
  242. int GetData(CBMOFDataItem *, BYTE * pRet, long * plDims);
  243. // These functions are mainly useful to the above helper functions
  244. int iTypeSize(DWORD vtTest);
  245. BOOL SetValue(CBMOFDataItem * pItem, BYTE * pInfo, DWORD dwOffset, DWORD dwType);
  246. BOOL SetName(WCHAR ** ppName, BYTE * pInfo, DWORD dwOffset);
  247. CBMOFQualList * CreateQualList(WBEM_QualifierList *pql);
  248. CBMOFObj * CreateObj(WBEM_Object * pob);
  249. #ifdef __cplusplus
  250. }
  251. #endif
  252. #endif