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.

141 lines
5.9 KiB

  1. //
  2. // BASIC DATABASE STRUCTURE
  3. //
  4. // The database file format was specifically designed to allow for a simple, extensible representation
  5. // of a hierarchical file like an XML file, and be forwards and backwards compatible. A future reader
  6. // should be able to read any current files, and future files should be readable by this code.
  7. //
  8. //
  9. // CORE BINARY FORMAT
  10. //
  11. // The file begins with a header of three DWORDs (defined in struct DB_HEADER):
  12. //
  13. // MajorVersion
  14. // MinorVersion
  15. // MagicNumber
  16. //
  17. // The Major version should only be changed if the new format would break old readers, i.e. NEVER.
  18. // The Minor version can be changed for informational purposes if there is a significant change
  19. // to the layout of the data.
  20. // The Magic number is there to ensure we don't try to read some random file with the same extension.
  21. //
  22. // Following the header are tags, packed end-to-end with no padding. All tags are of the form:
  23. //
  24. // TAG[SIZE][DATA...]
  25. //
  26. // Where SIZE and DATA are optional, depending on the type of TAG.
  27. //
  28. // TAG is 2 bytes long, SIZE is 4 bytes long, and DATA is anywhere from 0 to 2^32 bytes long.
  29. //
  30. // The top 4 bits of a TAG are reserved for internal database BASIC TYPE info.
  31. // This tells the database what kind of data is stored after the TAG, and if the tag has an
  32. // implied size. For example a TAG of basic type TAG_TYPE_BYTE has an implied size of 1 byte,
  33. // and does not require a SIZE. But a tag of basic type TAG_TYPE_STRING does not have an implied
  34. // size, and will therefore have a SIZE after the tag.
  35. //
  36. // The BASIC TYPES are:
  37. // TAG_TYPE_NULL (no SIZE, 0 bytes of DATA)
  38. // TAG_TYPE_BYTE (no SIZE, 1 byte of DATA)
  39. // TAG_TYPE_WORD (no SIZE, 2 bytes of DATA)
  40. // TAG_TYPE_DWORD (no SIZE, 4 bytes of DATA)
  41. // TAG_TYPE_QWORD (no SIZE, 8 bytes of DATA)
  42. // TAG_TYPE_STRINGREF (no SIZE, 4 bytes of DATA)
  43. // TAG_TYPE_LIST (SIZE, variable DATA)
  44. // TAG_TYPE_STRING (SIZE, variable DATA)
  45. // TAG_TYPE_BINARY (SIZE, variable DATA)
  46. //
  47. // Each of these types can be used for many different TAGs, by OR-ing the TAG_TYPE_x with a constant.
  48. // See SHIMTAGS.H and SHIMDB.H for examples.
  49. //
  50. // TAG_TYPE_STRINGREF is used for strings that should be placed in a stringtable by the database code.
  51. // This allows for efficient packing of duplicate strings. Tags of type STRING will be directly added
  52. // to the DB with no indirection.
  53. //
  54. // TAG_TYPE_LIST is defined to contain only more tags. Its SIZE is the combined size of all of its child
  55. // TAGs, including the TAG, DATA, and SIZE of each of them. This allows easy skipping over an entire
  56. // branch of the heirarchy.
  57. //
  58. // If new BASIC TYPES are defined later, they MUST have a SIZE associated with them, as the code assumes
  59. // that any type it doesn't recognize must have a SIZE. The first 5 types are really just a size optimization,
  60. // and new types should not try to have implied sizes.
  61. //
  62. //
  63. // THE SHIMDB LAYOUT
  64. //
  65. // Our layout for the application compatibility database mirrors closely the layout found in the DB.XML
  66. // file, found in the NT tree in WINDOWS\APPCOMPAT\DB, used to store information about apps that need
  67. // some kind of application compatibility fix applied to them. This comment block may get out of
  68. // date as new data is added to the database, so for the most current layout, consult
  69. // that file. One can also run the DUMPSDB.EXE utility (found in \WINDOWS\APPCOMPAT\DUMPSDB)
  70. // on an existing SDB to see the exact layout being used.
  71. //
  72. // The root contains only two tags: DATABASE (list) and STRINGTABLE (list).
  73. // The STRINGTABLE is used internally by the DB; all the useful data is under DATABASE.
  74. //
  75. // DATABASE contains a single LIBRARY (list) tag, 0 or more LAYER (list) tags, and 0 or more EXE (list) tags.
  76. //
  77. // LIBRARY contains 0 or more INEXCLUDE (list) tags, 0 or more DLL (list) tags, and 0 or more PATCH (list) tags
  78. //
  79. // an INEXCLUDE record contains potentially MODULE (string), API (string), INCLUDE (null, its existence
  80. // or nonexistence is treated like a boolean), and OFFSET (dword).
  81. //
  82. // a DLL record contains potentially NAME (string), SHORTNAME (string),
  83. // DESCRIPTION (string), DLL_BITS (binary),
  84. // and 0 or more INEXCLUDE (list) tags.
  85. //
  86. // a PATCH record contains potentially NAME (string),
  87. // DESCRIPTION (string), and PATCH_BITS (binary),
  88. //
  89. // a LAYER record contains exactly the same things that can be in an EXE record except MATCHING_FILE tags
  90. // and PATCH_REF tags.
  91. //
  92. // an EXE record contains potentially a NAME (string), KERNEL_FLAGS (qword), 0 or more
  93. // MATCHING_FILE (list) tags, 0 or more DLL_REF (list) tags, and 0 or more PATCH_REF (list) tags.
  94. //
  95. // a MATCHING_FILE record contains potentially a NAME (string), SIZE (dword), TIME (qword), and CHECKSUM (dword)
  96. //
  97. // a DLL_REF record contains potentially a NAME (string), DLL_TAGID (dword), and 0 or more INEXCLUDE (list)
  98. // tags.
  99. //
  100. // a PATCH_REF record contains potentially a NAME (string) and PATCH_TAGID (dword)
  101. //
  102. // Here's a map of where each tag is generally found, where "+" means there can be 0 or more, and [] means
  103. // the tag is optional:
  104. //
  105. // DATABASE
  106. // LIBRARY
  107. // [INEXCLUDE+]
  108. // [INCLUDE]
  109. // MODULE
  110. // [API]
  111. // [OFFSET]
  112. // [DLL+]
  113. // NAME
  114. // [SHORTNAME]
  115. // [DESCRIPTION]
  116. // [INEXCLUDE+]
  117. // [DLL_BITS]
  118. // [PATCH+]
  119. // NAME
  120. // [DESCRIPTION]
  121. // [PATCH_BITS]
  122. // [EXE+]
  123. // NAME
  124. // [APP_NAME]
  125. // [VENDOR_NAME]
  126. // [KERNEL_FLAGS]
  127. // [MATCHING_FILE+]
  128. // NAME
  129. // [SIZE]
  130. // [TIME]
  131. // [CHECKSUM]
  132. // [DLL_REF+]
  133. // NAME
  134. // [DLL_TAGID]
  135. // [INEXCLUDE+]
  136. // [PATCH_REF+]
  137. // NAME
  138. // [PATCH_TAGID]
  139. // [STRINGTABLE]
  140. // STRINGTABLE_ITEM+
  141. //