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.

2555 lines
67 KiB

  1. /*--
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. shimdb.h
  5. Abstract:
  6. header for the database file access functions used by the App Compat shimming system
  7. Author:
  8. dmunsil 02/02/2000
  9. Revision History:
  10. Notes:
  11. This "database" is more of a tagged file, designed to mimic the structure of an XML
  12. file. An XML file can be converted into this packed data format easily, and all strings
  13. will by default be packed into a stringtable and referenced by a DWORD identifier, so files
  14. that contain a lot of common strings (like the XML used by the App Compat tema) will not
  15. bloat.
  16. To see the actual tags used by the shimdb, look in shimtags.h.
  17. For the high-level interface used by the loader in NTDLL, look at ntbaseapi.c
  18. --*/
  19. #ifndef _SHIMDB_H_
  20. #define _SHIMDB_H_
  21. /*++
  22. Supported configurations:
  23. UNICODE with NT apis
  24. ANSI with WIN32 apis
  25. By default the library is UNICODE
  26. To use (and link) Win32 library
  27. --*/
  28. #ifdef SDB_ANSI_LIB
  29. #define LPCTSTR LPCSTR
  30. #define LPTSTR LPSTR
  31. #define TCHAR CHAR
  32. #else
  33. #define LPCTSTR LPCWSTR
  34. #define LPTSTR LPWSTR
  35. #define TCHAR WCHAR
  36. #endif
  37. #define SDBAPI STDAPICALLTYPE
  38. typedef WORD TAG;
  39. typedef WORD TAG_TYPE;
  40. typedef DWORD TAGID;
  41. typedef DWORD TAG_OFFSET;
  42. typedef DWORD STRINGREF;
  43. typedef DWORD INDEXID;
  44. #define TAGID_NULL 0
  45. #define STRINGREF_NULL 0
  46. #define INDEXID_NULL ((INDEXID)-1)
  47. #define TAG_NULL 0
  48. #define TAGID_ROOT 0 // implied root list tag that can be passed in as a parent
  49. #define TAG_SIZE_UNFINISHED 0xFFFFFFFF
  50. //
  51. // define TAGREF so we can use tags accross databases
  52. //
  53. typedef DWORD TAGREF;
  54. ///////////////////////////////////////////////////////////////////////////////
  55. //
  56. // TAG TYPES
  57. //
  58. //
  59. // The most significant 4 bits tell you the basic type and size of data,
  60. // and the lower 12 are the specific tag.
  61. //
  62. // In this way, even if we add more tags to the db, older readers can read
  63. // the data because the type is either implied (for the first 5 types)
  64. // or supplied (for all other types).
  65. //
  66. // WARNING: it is important that only the first 5 types have implied sizes.
  67. // any future types should use a size or backwards compatibility will not be
  68. // maintained.
  69. //
  70. // The following tags have an implied size.
  71. //
  72. #define TAG_TYPE_NULL 0x1000 // implied size 0
  73. #define TAG_TYPE_BYTE 0x2000 // implied size 1
  74. #define TAG_TYPE_WORD 0x3000 // implied size 2
  75. #define TAG_TYPE_DWORD 0x4000 // implied size 4
  76. #define TAG_TYPE_QWORD 0x5000 // implied size 8
  77. #define TAG_TYPE_STRINGREF 0x6000 // implied size 4, for strings that should be tokenized
  78. //
  79. // These tags have a size after them (the size is type TAG_OFFSET)
  80. //
  81. #define TAG_TYPE_LIST 0x7000
  82. #define TAG_TYPE_STRING 0x8000
  83. #define TAG_TYPE_BINARY 0x9000
  84. #define TAGREF_NULL 0
  85. #define TAGREF_ROOT 0
  86. //
  87. // Special define for stripping out just the type from a tag.
  88. //
  89. #define TAG_STRIP_TYPE 0xF000
  90. //
  91. // This macro strips off the lower bits of the TAG and returns the upper bits, which
  92. // give the basic type of tag. All the tag types are defined above.
  93. //
  94. // The type info is purely used internally by the DB to tell whether the tag has
  95. // an implied size, or if the DB needs to do something special with the data before
  96. // handing it back to the caller.
  97. //
  98. #define GETTAGTYPE(tag) ((tag) & TAG_STRIP_TYPE)
  99. typedef PVOID HSDB;
  100. struct tagHOOKAPI;
  101. typedef struct tagHOOKAPIEX {
  102. DWORD dwShimID;
  103. struct tagHOOKAPI* pTopOfChain;
  104. struct tagHOOKAPI* pNext;
  105. } HOOKAPIEX, *PHOOKAPIEX;
  106. typedef struct tagHOOKAPI {
  107. char* pszModule; // the name of the module
  108. char* pszFunctionName; // the name of the API in the module
  109. PVOID pfnNew; // pointer to the new stub API
  110. PVOID pfnOld; // pointer to the old API
  111. DWORD dwFlags; // used internally - important info about status
  112. union {
  113. struct tagHOOKAPI* pNextHook; // used internally - (obsolete -- old mechanism)
  114. PHOOKAPIEX pHookEx; // used internally - pointer to an internal extended
  115. // info struct
  116. };
  117. } HOOKAPI, *PHOOKAPI;
  118. //
  119. // OBSOLETE !
  120. //
  121. // If the hook DLL ever patches LoadLibraryA/W it must call PatchNewModules
  122. // so that the shim knows to patch any new loaded DLLs
  123. //
  124. typedef VOID (*PFNPATCHNEWMODULES)(VOID);
  125. typedef PHOOKAPI (*PFNGETHOOKAPIS)(LPSTR pszCmdLine,
  126. LPWSTR pwszShim,
  127. DWORD* pdwHooksCount);
  128. //
  129. // These structures are part of the protocol between NTVDM and the shim engine
  130. // for patching task "import tables"
  131. //
  132. typedef struct tagAPIDESC {
  133. char* pszModule;
  134. char* pszApi;
  135. } APIDESC, *PAPIDESC;
  136. typedef struct tagVDMTABLE {
  137. int nApiCount;
  138. PVOID* ppfnOrig;
  139. APIDESC* pApiDesc;
  140. } VDMTABLE, *PVDMTABLE;
  141. //
  142. // Shim engine notification events
  143. //
  144. #define SN_STATIC_DLLS_INITIALIZED 1
  145. #define SN_PROCESS_DYING 2
  146. #define SN_DLL_LOADING 3
  147. //
  148. // This is the prototype for the notification function
  149. // that the shim engine calls into the shim DLLs for various
  150. // reasons (defined above).
  151. //
  152. typedef void (*PFNNOTIFYSHIMS)(int nReason, UINT_PTR extraInfo);
  153. #define SHIM_COMMAND_LINE_MAX_BUFFER 1024
  154. ///////////////////////////////////////////////////////////////////////////////
  155. //
  156. // PATCH STRUCTURES
  157. //
  158. typedef struct _PATCHOP {
  159. DWORD dwOpcode; // Opcode to be performed
  160. DWORD dwNextOpcode; // Relative offset to next opcode
  161. #pragma warning( disable : 4200 )
  162. BYTE data[]; // Data for this operation type is dependent
  163. // on the op-code.
  164. #pragma warning( default : 4200 )
  165. } PATCHOP, *PPATCHOP;
  166. typedef struct _RELATIVE_MODULE_ADDRESS {
  167. DWORD address; // Relative address from beginning of loaded module
  168. BYTE reserved[3]; // Reserved for system use
  169. WCHAR moduleName[32]; // Module name for this address.
  170. } RELATIVE_MODULE_ADDRESS, *PRELATIVE_MODULE_ADDRESS;
  171. typedef struct _PATCHWRITEDATA {
  172. DWORD dwSizeData; // Size of patch data in bytes
  173. RELATIVE_MODULE_ADDRESS rva; // Relative address where this patch data is
  174. // to be applied.
  175. #pragma warning( disable : 4200 )
  176. BYTE data[]; // Patch data bytes.
  177. #pragma warning( default : 4200 )
  178. } PATCHWRITEDATA, *PPATCHWRITEDATA;
  179. typedef struct _PATCHMATCHDATA {
  180. DWORD dwSizeData; // Size of matching data data in bytes
  181. RELATIVE_MODULE_ADDRESS rva; // Relative address where this patch data is
  182. // to be verified.
  183. #pragma warning( disable : 4200 )
  184. BYTE data[]; // Matching data bytes.
  185. #pragma warning( default : 4200 )
  186. } PATCHMATCHDATA, *PPATCHMATCHDATA;
  187. typedef enum _PATCHOPCODES {
  188. PEND = 0, // no more opcodes
  189. PSAA, // Set Activate Address, SETACTIVATEADDRESS
  190. PWD, // Patch Write Data, PATCHWRITEDATA
  191. PNOP, // No Operation
  192. PMAT, // Patch match the matching bytes but do not replace the bytes.
  193. } PATCHOPCODES;
  194. //
  195. // HEADER STRUCTURE
  196. //
  197. #define SHIMDB_MAGIC 0x66626473 // 'sdbf' (reversed because of little-endian ordering)
  198. #define SHIMDB_MAJOR_VERSION 2 // Don't change this unless fundamentals
  199. // change (like TAG size, etc.)
  200. #define SHIMDB_MINOR_VERSION 0 // This is for info only -- ignored on read
  201. typedef struct _DB_HEADER {
  202. DWORD dwMajorVersion;
  203. DWORD dwMinorVersion;
  204. DWORD dwMagic;
  205. } DB_HEADER, *PDB_HEADER;
  206. //
  207. // INDEX_RECORD STRUCTURE
  208. //
  209. #pragma pack (push, 4)
  210. typedef struct _INDEX_RECORD {
  211. ULONGLONG ullKey;
  212. TAGID tiRef;
  213. } INDEX_RECORD;
  214. typedef INDEX_RECORD UNALIGNED *PINDEX_RECORD;
  215. #pragma pack (pop)
  216. //
  217. // Forward declaration.
  218. //
  219. struct _DB;
  220. typedef struct _DB* PDB;
  221. //
  222. // This flag is used in apphelp entries.
  223. // When set, it denotes entries that only have apphelp information.
  224. //
  225. #define SHIMDB_APPHELP_ONLY 0x00000001
  226. typedef enum _PATH_TYPE {
  227. DOS_PATH,
  228. NT_PATH
  229. } PATH_TYPE;
  230. typedef struct _FIND_INFO {
  231. TAGID tiIndex;
  232. TAGID tiCurrent;
  233. TAGID tiEndIndex; // last record after FindFirst if index is UNIQUE
  234. TAG tName;
  235. DWORD dwIndexRec;
  236. DWORD dwFlags;
  237. ULONGLONG ullKey; // calculated key for this entry
  238. union {
  239. LPCTSTR szName;
  240. DWORD dwName; // for dword search
  241. GUID* pguidName;
  242. };
  243. } FIND_INFO, *PFIND_INFO;
  244. #define SDB_MAX_LAYERS 8
  245. #define SDB_MAX_EXES 4
  246. #define SDB_MAX_SDBS 16
  247. typedef struct tagSDBQUERYRESULT {
  248. TAGREF atrExes[SDB_MAX_EXES];
  249. TAGREF atrLayers[SDB_MAX_LAYERS];
  250. DWORD dwLayerFlags;
  251. TAGREF trAppHelp; // If there is an apphelp to display, the EXE
  252. // entry will be here.
  253. DWORD dwExeCount; // number of elements in atrexes
  254. DWORD dwLayerCount; // number of elements in atrLayers
  255. GUID guidID; // last exe's GUID
  256. DWORD dwFlags; // last exe's flags
  257. //
  258. // New entries are here to preserve compatibility.
  259. // Only some entries will be valid in this map.
  260. //
  261. DWORD dwCustomSDBMap; // entry map, technically not needed
  262. GUID rgGuidDB[SDB_MAX_SDBS];
  263. } SDBQUERYRESULT, *PSDBQUERYRESULT;
  264. //
  265. // Information related to TAG_DRIVER tag in the db.
  266. // Use SdbReadDriverInformation to retrieve this struct.
  267. //
  268. typedef struct tagENTRYINFO {
  269. GUID guidID; // guid ID for this entry
  270. DWORD dwFlags; // registry flags for this exe
  271. TAGID tiData; // optional id for a TAG_DATA tag
  272. GUID guidDB; // optional guid for the database where
  273. // this entry is located
  274. } SDBENTRYINFO, *PSDBENTRYINFO;
  275. //
  276. // Flags used by SDBDATABASEINFO.dwFlags
  277. //
  278. #define DBINFO_GUID_VALID 0x00000001
  279. #define DBINFO_SDBALLOC 0x10000000
  280. typedef struct tagSDBDATABASEINFO {
  281. DWORD dwFlags; // flags -- which struct members are valid (and
  282. // perhaps flags relevant to db content in the future
  283. DWORD dwVersionMajor; // major version
  284. DWORD dwVersionMinor; // minor version (time stamp)
  285. LPTSTR pszDescription; // description, optional
  286. GUID guidDB; // database id
  287. } SDBDATABASEINFO, *PSDBDATABASEINFO;
  288. #if defined(_WIN64)
  289. #define DEFAULT_IMAGE IMAGE_FILE_MACHINE_IA64
  290. #else
  291. #define DEFAULT_IMAGE IMAGE_FILE_MACHINE_I386
  292. #endif
  293. //
  294. // special image type -- which represents a mixture of image types
  295. // depending on the component. It is used (as name implies) by MSI
  296. // this value is not used by any of the IMAGE_FILE_MACHINE_* constants
  297. //
  298. #define IMAGE_FILE_MSI 0x7FFF
  299. ///////////////////////////////////////////////////////////////////////////////
  300. //
  301. // APIs to read/write/access the shim database
  302. //
  303. //
  304. // READ functions
  305. //
  306. BYTE
  307. SDBAPI
  308. SdbReadBYTETag(
  309. IN PDB pdb,
  310. IN TAGID tiWhich,
  311. IN BYTE jDefault
  312. );
  313. WORD
  314. SDBAPI
  315. SdbReadWORDTag(
  316. IN PDB pdb,
  317. IN TAGID tiWhich,
  318. IN WORD wDefault
  319. );
  320. DWORD
  321. SDBAPI
  322. SdbReadDWORDTag(
  323. IN PDB pdb,
  324. IN TAGID tiWhich,
  325. IN DWORD dwDefault
  326. );
  327. ULONGLONG
  328. SDBAPI
  329. SdbReadQWORDTag(
  330. IN PDB pdb,
  331. IN TAGID tiWhich,
  332. IN ULONGLONG qwDefault
  333. );
  334. BOOL
  335. SDBAPI
  336. SdbReadBinaryTag(
  337. IN PDB pdb,
  338. IN TAGID tiWhich,
  339. OUT PBYTE pBuffer,
  340. IN DWORD dwBufferSize
  341. );
  342. BOOL
  343. SDBAPI
  344. SdbReadStringTag(
  345. IN PDB pdb,
  346. IN TAGID tiWhich,
  347. OUT LPTSTR pwszBuffer,
  348. IN DWORD cchBufferSize
  349. );
  350. LPTSTR
  351. SDBAPI
  352. SdbGetStringTagPtr(
  353. IN PDB pdb,
  354. IN TAGID tiWhich
  355. );
  356. BYTE
  357. SDBAPI
  358. SdbReadBYTETagRef(
  359. IN HSDB hSDB,
  360. IN TAGREF trWhich,
  361. IN BYTE jDefault
  362. );
  363. WORD
  364. SDBAPI
  365. SdbReadWORDTagRef(
  366. IN HSDB hSDB,
  367. IN TAGREF trWhich,
  368. IN WORD wDefault
  369. );
  370. DWORD
  371. SDBAPI
  372. SdbReadDWORDTagRef(
  373. IN HSDB hSDB,
  374. IN TAGREF trWhich,
  375. IN DWORD dwDefault
  376. );
  377. ULONGLONG
  378. SDBAPI
  379. SdbReadQWORDTagRef(
  380. IN HSDB hSDB,
  381. IN TAGREF trWhich,
  382. IN ULONGLONG qwDefault
  383. );
  384. BOOL
  385. SDBAPI
  386. SdbReadStringTagRef(
  387. IN HSDB hSDB,
  388. IN TAGREF trWhich,
  389. OUT LPTSTR pwszBuffer,
  390. IN DWORD cchBufferSize
  391. );
  392. //
  393. // GENERAL ACCESS FUNCTIONS
  394. //
  395. TAGID
  396. SDBAPI
  397. SdbGetFirstChild(
  398. IN PDB pdb,
  399. IN TAGID tiParent
  400. );
  401. TAGID
  402. SDBAPI
  403. SdbGetNextChild(
  404. IN PDB pdb,
  405. IN TAGID tiParent,
  406. IN TAGID tiPrev
  407. );
  408. TAG
  409. SDBAPI
  410. SdbGetTagFromTagID(
  411. IN PDB pdb,
  412. IN TAGID tiWhich
  413. );
  414. DWORD
  415. SDBAPI
  416. SdbGetTagDataSize(
  417. IN PDB pdb,
  418. IN TAGID tiWhich
  419. );
  420. PVOID
  421. SDBAPI
  422. SdbGetBinaryTagData(
  423. IN PDB pdb,
  424. IN TAGID tiWhich
  425. );
  426. BOOL
  427. SDBAPI
  428. SdbIsTagrefFromMainDB(
  429. TAGREF trWhich
  430. );
  431. BOOL
  432. SDBAPI
  433. SdbIsTagrefFromLocalDB(
  434. TAGREF trWhich
  435. );
  436. typedef struct tagATTRINFO *PATTRINFO;
  437. //////////////////////////////////////////////////////////////////////////
  438. // Grab Matching Information Function Declaration
  439. //
  440. //
  441. // Filters available for SdbGrabMatchingInfo
  442. //
  443. #define GRABMI_FILTER_NORMAL 0
  444. #define GRABMI_FILTER_PRIVACY 1
  445. #define GRABMI_FILTER_DRIVERS 2
  446. #define GRABMI_FILTER_VERBOSE 3
  447. #define GRABMI_FILTER_SYSTEM 4
  448. #define GRABMI_FILTER_THISFILEONLY 5
  449. #define GRABMI_FILTER_NOCLOSE 0x10000000
  450. #define GRABMI_FILTER_APPEND 0x20000000
  451. #define GRABMI_FILTER_LIMITFILES 0x40000000
  452. #define GRABMI_FILTER_NORECURSE 0x80000000
  453. #define GRABMI_IMPOSED_FILE_LIMIT 25
  454. typedef enum GMI_RESULT {
  455. GMI_FAILED = FALSE,
  456. GMI_SUCCESS = TRUE,
  457. GMI_CANCELLED = -1
  458. } GMI_RESULT;
  459. BOOL
  460. SDBAPI
  461. SdbGrabMatchingInfo(
  462. LPCTSTR szMatchingPath,
  463. DWORD dwFilter,
  464. LPCTSTR szFile
  465. );
  466. typedef BOOL (CALLBACK* PFNGMIProgressCallback)(
  467. LPVOID lpvCallbackParam, // application-defined parameter
  468. LPCTSTR lpszRoot, // root directory path
  469. LPCTSTR lpszRelative, // relative path
  470. PATTRINFO pAttrInfo, // attributes
  471. LPCWSTR pwszXML // resulting xml
  472. );
  473. GMI_RESULT
  474. SDBAPI
  475. SdbGrabMatchingInfoEx(
  476. LPCTSTR szMatchingPath,
  477. DWORD dwFilter,
  478. LPCTSTR szFile,
  479. PFNGMIProgressCallback pfnCallback,
  480. LPVOID lpvCallbackParam
  481. );
  482. //
  483. // Module-type constants
  484. //
  485. #define MT_UNKNOWN_MODULE 0
  486. #define MT_DOS_MODULE 1
  487. #define MT_W16_MODULE 2
  488. #define MT_W32_MODULE 3
  489. //////////////////////////////////////////////////////////////////////////
  490. //
  491. // TAGREF functions
  492. //
  493. //////////////////////////////////////////////////////////////////////////
  494. BOOL
  495. SDBAPI
  496. SdbTagIDToTagRef(
  497. IN HSDB hSDB,
  498. IN PDB pdb,
  499. IN TAGID tiWhich,
  500. OUT TAGREF* ptrWhich
  501. );
  502. BOOL
  503. SDBAPI
  504. SdbTagRefToTagID(
  505. IN HSDB hSDB,
  506. IN TAGREF trWhich,
  507. OUT PDB* ppdb,
  508. OUT TAGID* ptiWhich
  509. );
  510. //
  511. // SEARCH functions
  512. //
  513. TAGID
  514. SDBAPI
  515. SdbFindFirstTag(
  516. IN PDB pdb,
  517. IN TAGID tiParent,
  518. IN TAG tTag
  519. );
  520. TAGID
  521. SDBAPI
  522. SdbFindNextTag(
  523. IN PDB pdb,
  524. IN TAGID tiParent,
  525. IN TAGID tiPrev
  526. );
  527. TAGID
  528. SDBAPI
  529. SdbFindFirstNamedTag(
  530. IN PDB pdb,
  531. IN TAGID tiParent,
  532. IN TAG tToFind,
  533. IN TAG tName,
  534. IN LPCTSTR pszName
  535. );
  536. TAGREF
  537. SDBAPI
  538. SdbFindFirstTagRef(
  539. IN HSDB hSDB,
  540. IN TAGREF trParent,
  541. IN TAG tTag
  542. );
  543. TAGREF
  544. SDBAPI
  545. SdbFindNextTagRef(
  546. IN HSDB hSDB,
  547. IN TAGREF trParent,
  548. IN TAGREF trPrev
  549. );
  550. //
  551. // DB access APIs
  552. //
  553. //
  554. // Flags for SdbInitDatabase.
  555. //
  556. #define HID_DOS_PATHS 0x00000001 // use DOS paths
  557. #define HID_DATABASE_FULLPATH 0x00000002 // pszDatabasePath is a full path to the main db
  558. #define HID_NO_DATABASE 0x00000004 // do not open database at this time
  559. #define HID_DATABASE_TYPE_MASK 0xF00F0000 // mask that shows whether we have any
  560. // database type-related bits
  561. //
  562. // The flags could be OR'd with SDB_DATABASE_* bits
  563. //
  564. HSDB
  565. SDBAPI
  566. SdbInitDatabase(
  567. IN DWORD dwFlags,
  568. IN LPCTSTR pszDatabasePath
  569. );
  570. HSDB
  571. SDBAPI
  572. SdbInitDatabaseEx(
  573. IN DWORD dwFlags,
  574. IN LPCTSTR pszDatabasePath,
  575. IN USHORT uExeType
  576. );
  577. VOID
  578. SDBAPI
  579. SdbSetImageType(
  580. IN HSDB hSDB,
  581. IN USHORT uExeType
  582. );
  583. HSDB
  584. SDBAPI
  585. SdbInitDatabaseInMemory(
  586. IN LPVOID pDatabaseImage,
  587. IN DWORD dwImageSize
  588. );
  589. VOID
  590. SDBAPI
  591. SdbReleaseDatabase(
  592. IN HSDB hSDB
  593. );
  594. //
  595. // Information - retrieval functions
  596. //
  597. BOOL
  598. SDBAPI
  599. SdbGetDatabaseVersion(
  600. IN LPCTSTR pwszFileName,
  601. OUT LPDWORD lpdwMajor,
  602. OUT LPDWORD lpdwMinor
  603. );
  604. BOOL
  605. SDBAPI
  606. SdbGetDatabaseInformation(
  607. IN PDB pdb,
  608. OUT PSDBDATABASEINFO pSdbInfo
  609. );
  610. BOOL
  611. SDBAPI
  612. SdbGetDatabaseID(
  613. IN PDB pdb,
  614. OUT GUID* pguidDB
  615. );
  616. DWORD
  617. SDBAPI
  618. SdbGetDatabaseDescription(
  619. IN PDB pdb,
  620. OUT LPTSTR pszDatabaseDescription,
  621. IN DWORD BufferSize
  622. );
  623. VOID
  624. SDBAPI
  625. SdbFreeDatabaseInformation(
  626. IN PSDBDATABASEINFO pDBInfo
  627. );
  628. BOOL
  629. SDBAPI
  630. SdbGetDatabaseInformationByName(
  631. IN LPCTSTR pszDatabase,
  632. OUT PSDBDATABASEINFO* ppdbInfo
  633. );
  634. #define SDBTYPE_SYSMAIN 0x00000001
  635. #define SDBTYPE_SYSTEST 0x00000002
  636. #define SDBTYPE_MSI 0x00000003
  637. #define SDBTYPE_SHIM 0x00000004 // primarily shim db
  638. #define SDBTYPE_APPHELP 0x00000005 // primarily type apphelp
  639. #define SDBTYPE_CUSTOM 0x00010000 // this is an "OR" bit
  640. //
  641. // The function below exists only in user mode on win32 platform
  642. //
  643. BOOL
  644. SDBAPI
  645. SdbUnregisterDatabase(
  646. IN GUID* pguidDB
  647. );
  648. BOOL
  649. SDBAPI
  650. SdbGetDatabaseRegPath(
  651. IN GUID* pguidDB,
  652. OUT LPTSTR pszDatabasePath,
  653. IN DWORD dwBufferSize // size (in tchars) of the buffer
  654. );
  655. /////////////////////////////////////////////////////////////////
  656. //
  657. // Database types
  658. // for SdbResolveDatabase and SdbRegisterDatabase
  659. //
  660. //
  661. // flag that indicates that the database is the default one
  662. // WILL NOT be set for custom databases
  663. //
  664. #define SDB_DATABASE_MAIN 0x80000000
  665. #define SDB_DATABASE_TEST 0x40000000 // systest.sdb will have 0xc00000000
  666. //
  667. // types - one or more apply depending on the contents of the database
  668. // (see HID_DATABASE_TYPE values, they should match database types 1:1)
  669. #define SDB_DATABASE_SHIM 0x00010000 // set when database contains apps to be fixed by shimming
  670. #define SDB_DATABASE_MSI 0x00020000 // set when database contains msi entries
  671. #define SDB_DATABASE_DRIVERS 0x00040000 // set when database contains drivers to be blocked
  672. #define SDB_DATABASE_DETAILS 0x00080000 // set when the db contains apphelp details
  673. #define SDB_DATABASE_TYPE_MASK 0xF00F0000
  674. //
  675. // These constants should be used when derefencing "main" databases
  676. //
  677. #define SDB_DATABASE_MAIN_SHIM (SDB_DATABASE_SHIM | SDB_DATABASE_MSI | SDB_DATABASE_MAIN)
  678. #define SDB_DATABASE_MAIN_MSI (SDB_DATABASE_MSI | SDB_DATABASE_MAIN)
  679. #define SDB_DATABASE_MAIN_DRIVERS (SDB_DATABASE_DRIVERS | SDB_DATABASE_MAIN)
  680. #define SDB_DATABASE_MAIN_TEST (SDB_DATABASE_TEST | SDB_DATABASE_MAIN | SDB_DATABASE_SHIM | SDB_DATABASE_MSI)
  681. #define SDB_DATABASE_MAIN_DETAILS (SDB_DATABASE_DETAILS | SDB_DATABASE_MAIN)
  682. //
  683. // These are internal GUIDs that always reference certain global databases
  684. //
  685. #define GUID_SZ_SYSMAIN_SDB _T("{11111111-1111-1111-1111-111111111111}");
  686. #define GUID_SZ_APPHELP_SDB _T("{22222222-2222-2222-2222-222222222222}");
  687. #define GUID_SZ_SYSTEST_SDB _T("{33333333-3333-3333-3333-333333333333}");
  688. #define GUID_SZ_DRVMAIN_SDB _T("{F9AB2228-3312-4A73-B6F9-936D70E112EF}"};
  689. //
  690. // the following GUIDs are actually declared in sdbapi.c
  691. //
  692. EXTERN_C const GUID FAR GUID_SYSMAIN_SDB;
  693. EXTERN_C const GUID FAR GUID_APPHELP_SDB;
  694. EXTERN_C const GUID FAR GUID_SYSTEST_SDB;
  695. EXTERN_C const GUID FAR GUID_DRVMAIN_SDB;
  696. EXTERN_C const GUID FAR GUID_MSIMAIN_SDB;
  697. BOOL
  698. SDBAPI
  699. SdbGetStandardDatabaseGUID(
  700. IN DWORD dwDatabaseType,
  701. OUT GUID* pGuidDB
  702. );
  703. BOOL
  704. SDBAPI
  705. SdbRegisterDatabase(
  706. IN LPCTSTR pszDatabasePath,
  707. IN DWORD dwDatabaseType
  708. );
  709. BOOL
  710. SDBAPI
  711. SdbRegisterDatabaseEx(
  712. IN LPCTSTR pszDatabasePath,
  713. IN DWORD dwDatabaseType,
  714. IN PULONGLONG pTimeStamp
  715. );
  716. DWORD
  717. SDBAPI
  718. SdbResolveDatabase(
  719. IN HSDB hSDB,
  720. IN GUID* pguidDB, // pointer to the database guid to resolve
  721. OUT LPDWORD lpdwDatabaseType, // optional pointer to the database type
  722. OUT LPTSTR pszDatabasePath, // optional pointer to the database path
  723. IN DWORD dwBufferSize // size of the buffer pszDatabasePath in tchars
  724. );
  725. PDB
  726. SdbGetPDBFromGUID(
  727. IN HSDB hSDB, // HSDB
  728. IN GUID* pguidDB // the guid of the DB
  729. );
  730. BOOL
  731. SdbGetDatabaseGUID(
  732. IN HSDB hSDB, // HSDB of the sdbContext (optional)
  733. IN PDB pdb, // PDB of the database in question
  734. OUT GUID* pguidDB // the guid of the DB
  735. );
  736. TAGREF
  737. SDBAPI
  738. SdbFindMsiPackageByID(
  739. IN HSDB hSDB,
  740. IN GUID* pguidID
  741. );
  742. void
  743. SdbpGetAppPatchDir(
  744. IN HSDB hSDB,
  745. IN LPTSTR szAppPatchPath,
  746. IN DWORD cchSize
  747. );
  748. //
  749. // GUID manipulation apis - not platform dependent
  750. //
  751. BOOL
  752. SDBAPI
  753. SdbGUIDFromString(
  754. IN LPCTSTR lpszGuid,
  755. OUT GUID* pGuid
  756. );
  757. BOOL
  758. SDBAPI
  759. SdbGUIDToString(
  760. IN GUID* pGuid,
  761. OUT LPTSTR pszGuid,
  762. IN DWORD cchSize
  763. );
  764. BOOL
  765. SDBAPI
  766. SdbIsNullGUID(
  767. IN GUID* pGuid
  768. );
  769. //
  770. // open/create and close database.
  771. //
  772. PDB
  773. SDBAPI
  774. SdbOpenDatabase(
  775. IN LPCTSTR pwszPath,
  776. IN PATH_TYPE eType
  777. );
  778. BOOL
  779. SDBAPI
  780. SdbOpenLocalDatabase(
  781. IN HSDB hSDB,
  782. IN LPCTSTR pwszLocalDatabase
  783. );
  784. BOOL
  785. SDBAPI
  786. SdbCloseLocalDatabase(
  787. IN HSDB hSDB
  788. );
  789. PDB
  790. SDBAPI
  791. SdbCreateDatabase(
  792. IN LPCWSTR pwszPath,
  793. IN PATH_TYPE eType
  794. );
  795. void
  796. SDBAPI
  797. SdbCloseDatabase(
  798. IN PDB pdb
  799. );
  800. //
  801. // Search the database looking for an entry for the specified exe.
  802. //
  803. //
  804. // Flags for SdbGetMatchingExe dwFlags
  805. //
  806. #define SDBGMEF_IGNORE_ENVIRONMENT 0x00000001
  807. BOOL
  808. SdbGetMatchingExe(
  809. IN HSDB hSDB OPTIONAL,
  810. IN LPCTSTR pwszPath,
  811. IN LPCTSTR szModuleName,
  812. IN LPCTSTR pwszEnvironment,
  813. IN DWORD dwFlags,
  814. OUT PSDBQUERYRESULT pQueryResult
  815. );
  816. void
  817. SdbReleaseMatchingExe(
  818. IN HSDB hSDB,
  819. IN TAGREF trExe
  820. );
  821. TAGREF
  822. SDBAPI
  823. SdbGetDatabaseMatch(
  824. IN HSDB hSDB,
  825. IN LPCTSTR szPath,
  826. IN HANDLE FileHandle OPTIONAL,
  827. IN LPVOID pImageBase OPTIONAL,
  828. IN DWORD dwImageSize OPTIONAL
  829. );
  830. TAGREF
  831. SdbGetLayerTagReg(
  832. IN HSDB hSDB,
  833. IN LPCTSTR szLayer
  834. );
  835. PDB
  836. SDBAPI
  837. SdbGetLocalPDB(
  838. IN HSDB hSDB
  839. );
  840. LPTSTR
  841. SDBAPI
  842. SdbGetLayerName(
  843. IN HSDB hSDB,
  844. IN TAGREF trLayer
  845. );
  846. TAGREF
  847. SDBAPI
  848. SdbGetNamedLayer(
  849. IN HSDB hSDB, // database context
  850. IN TAGREF trLayerRef // tagref of a record referencing a layer
  851. );
  852. #define SBCE_ADDITIVE 0x00000001
  853. #define SBCE_INCLUDESYSTEMEXES 0x00000002
  854. #define SBCE_INHERITENV 0x00000004
  855. DWORD
  856. SdbBuildCompatEnvVariables(
  857. IN HSDB hSDB,
  858. IN SDBQUERYRESULT* psdbQuery,
  859. IN DWORD dwFlags,
  860. IN LPCWSTR pwszParentEnv OPTIONAL, // Environment which contains vars we
  861. // shall inherit from
  862. OUT LPWSTR pBuffer,
  863. IN DWORD cbSize, // size of the buffer in tchars
  864. OUT LPDWORD lpdwShimsCount OPTIONAL
  865. );
  866. //
  867. // MSI-specific functionality
  868. //
  869. typedef enum tagSDBMSILOOKUPSTATE {
  870. LOOKUP_NONE = 0, // this should be the first state
  871. LOOKUP_LOCAL,
  872. LOOKUP_CUSTOM,
  873. LOOKUP_TEST,
  874. LOOKUP_MAIN,
  875. LOOKUP_DONE // this should be the last state
  876. } SDBMSILOOKUPSTATE;
  877. typedef struct tagSDBMSIFINDINFO {
  878. TAGREF trMatch; // tagref of the matching package
  879. GUID guidID; // guid of this current package
  880. FIND_INFO sdbFindInfo; // standard sdb find info
  881. // this is used to persist the state of the current search
  882. //
  883. SDBMSILOOKUPSTATE sdbLookupState;
  884. DWORD dwCustomIndex;
  885. } SDBMSIFINDINFO, *PSDBMSIFINDINFO;
  886. typedef struct tagSDBMSITRANSFORMINFO {
  887. LPCTSTR lpszTransformName; // name of the transform
  888. TAGREF trTransform; // tagref of this transform
  889. TAGREF trFile; // tagref of file for this transform (bits)
  890. } SDBMSITRANSFORMINFO, *PSDBMSITRANSFORMINFO;
  891. //
  892. // Information for any individual MSI package
  893. //
  894. typedef struct tagMSIPACKAGEINFO {
  895. GUID guidID; // unique guid for this entry
  896. GUID guidMsiPackageID; // guid (non-unique, for this entry)
  897. GUID guidDatabaseID; // guid of the database where this had been found
  898. DWORD dwPackageFlags; // Package flags (see below)
  899. } MSIPACKAGEINFO, *PMSIPACKAGEINFO;
  900. #define MSI_PACKAGE_HAS_APPHELP 0x00000001
  901. #define MSI_PACKAGE_HAS_SHIMS 0x00000002
  902. TAGREF
  903. SDBAPI
  904. SdbFindFirstMsiPackage_Str(
  905. IN HSDB hSDB,
  906. IN LPCTSTR lpszGuid,
  907. IN LPCTSTR lpszLocalDB,
  908. OUT PSDBMSIFINDINFO pFindInfo
  909. );
  910. TAGREF
  911. SDBAPI
  912. SdbFindFirstMsiPackage(
  913. IN HSDB hSDB, // in HSDB context
  914. IN GUID* pGuidID, // in GUID that we're looking for
  915. IN LPCTSTR lpszLocalDB, // in optional path to local db, dos path style
  916. OUT PSDBMSIFINDINFO pFindInfo // pointer to our search context
  917. );
  918. TAGREF
  919. SDBAPI
  920. SdbFindNextMsiPackage(
  921. IN HSDB hSDB,
  922. IN OUT PSDBMSIFINDINFO pFindInfo
  923. );
  924. BOOL
  925. SDBAPI
  926. SdbGetMsiPackageInformation(
  927. IN HSDB hSDB,
  928. IN TAGREF trMatch,
  929. OUT PMSIPACKAGEINFO pPackageInfo
  930. );
  931. DWORD
  932. SDBAPI
  933. SdbEnumMsiTransforms(
  934. IN HSDB hSDB, // in HSDB context
  935. IN TAGREF trMatch, // matched entry
  936. OUT TAGREF* ptrBuffer, // array of tagrefs to fill with msi transform "fixes"
  937. IN OUT DWORD* pdwBufferSize // pointer to the buffer size, receives the number of
  938. // bytes written
  939. );
  940. BOOL
  941. SDBAPI
  942. SdbReadMsiTransformInfo(
  943. IN HSDB hSDB, // HSDB context
  944. IN TAGREF trTransformRef, // reference to a transform, returned
  945. // by SdbEnumMsiTransforms
  946. OUT PSDBMSITRANSFORMINFO pTransformInfo // information structure
  947. );
  948. BOOL
  949. SDBAPI
  950. SdbCreateMsiTransformFile(
  951. IN HSDB hSDB, // context
  952. IN LPCTSTR lpszFileName, // filename to write data to
  953. IN PSDBMSITRANSFORMINFO pTransformInfo // pointer to the transform structure
  954. );
  955. TAGREF
  956. SDBAPI
  957. SdbFindCustomActionForPackage(
  958. IN HSDB hSDB,
  959. IN TAGREF trPackage,
  960. IN LPCTSTR lpszCustomAction);
  961. #define SdbGetFirstMsiTransformForPackage(hSDB, trPackage) \
  962. (SdbFindFirstTagRef((hSDB), (trPackage), TAG_MSI_TRANSFORM_REF))
  963. #define SdbGetNextMsiTransformForPackage(hSDB, trPackage, trPrevMatch) \
  964. (SdbFindNextTagRef((hSDB), (trPackage), (trPrevMatch)))
  965. //
  966. // "disable" registry entry masks
  967. //
  968. #define SHIMREG_DISABLE_SHIM 0x00000001
  969. #define SHIMREG_DISABLE_APPHELP 0x00000002 // disables apphelp
  970. #define SHIMREG_APPHELP_NOUI 0x00000004 // suppress apphelp ui
  971. #define SHIMREG_APPHELP_CANCEL 0x10000000 // returns CANCEL as a default action
  972. #define SHIMREG_DISABLE_SXS 0x00000010
  973. #define SHIMREG_DISABLE_LAYER 0x00000020
  974. #define SHIMREG_DISABLE_DRIVER 0x00000040
  975. BOOL
  976. SDBAPI
  977. SdbSetEntryFlags(
  978. IN GUID* pGuidID,
  979. IN DWORD dwFlags
  980. );
  981. BOOL
  982. SDBAPI
  983. SdbGetEntryFlags(
  984. IN GUID* pGuid,
  985. OUT LPDWORD lpdwFlags
  986. );
  987. //
  988. // Flags used by Get/SetPermLayerKeys
  989. //
  990. #define GPLK_USER 0x00000001
  991. #define GPLK_MACHINE 0x00000002
  992. #define GPLK_ALL (GPLK_USER | GPLK_MACHINE)
  993. BOOL
  994. SDBAPI
  995. SdbGetPermLayerKeys(
  996. LPCTSTR szPath,
  997. LPTSTR szLayers,
  998. LPDWORD pdwBytes,
  999. DWORD dwFlags
  1000. );
  1001. BOOL
  1002. SDBAPI
  1003. SdbSetPermLayerKeys(
  1004. LPCTSTR szPath,
  1005. LPCTSTR szLayers,
  1006. BOOL bMachine
  1007. );
  1008. BOOL
  1009. SDBAPI
  1010. SdbDeletePermLayerKeys(
  1011. LPCTSTR szPath,
  1012. BOOL bMachine
  1013. );
  1014. BOOL
  1015. SdbGetNthUserSdb(
  1016. IN HSDB hSDB, // context
  1017. IN LPCTSTR wszItemName, // item name (foo.exe or layer name)
  1018. IN BOOL bLayer, // true if layer name
  1019. IN OUT LPDWORD pdwIndex, // (0-based)
  1020. OUT GUID* pGuidDB // database guid
  1021. );
  1022. //
  1023. // APIs to pack/unpack appcompat data package.
  1024. //
  1025. BOOL
  1026. SdbPackAppCompatData(
  1027. IN HSDB hSDB,
  1028. IN PSDBQUERYRESULT pSdbQuery,
  1029. OUT PVOID* ppData,
  1030. OUT LPDWORD pdwSize
  1031. );
  1032. BOOL
  1033. SdbUnpackAppCompatData(
  1034. IN HSDB hSDB,
  1035. IN LPCWSTR pwszExeName,
  1036. IN PVOID pAppCompatData,
  1037. OUT PSDBQUERYRESULT pSdbQuery
  1038. );
  1039. DWORD
  1040. SdbGetAppCompatDataSize(
  1041. IN PVOID pAppCompatData
  1042. );
  1043. //
  1044. // DLL functions
  1045. //
  1046. BOOL
  1047. SdbGetDllPath(
  1048. IN HSDB hSDB,
  1049. IN TAGREF trDllRef,
  1050. OUT LPTSTR pwszBuffer,
  1051. IN DWORD cchBufferSize
  1052. );
  1053. //
  1054. // PATCH functions
  1055. //
  1056. BOOL
  1057. SdbReadPatchBits(
  1058. IN HSDB hSDB,
  1059. IN TAGREF trPatchRef,
  1060. OUT PVOID pBuffer,
  1061. OUT LPDWORD lpdwBufferSize
  1062. );
  1063. //
  1064. // SDBDRIVERINFO query function
  1065. //
  1066. BOOL
  1067. SDBAPI
  1068. SdbReadEntryInformation(
  1069. IN HSDB hSDB,
  1070. IN TAGREF trDriver,
  1071. OUT PSDBENTRYINFO pEntryInfo
  1072. );
  1073. DWORD
  1074. SDBAPI
  1075. SdbQueryData(
  1076. IN HSDB hSDB,
  1077. IN TAGREF trExe,
  1078. IN LPCTSTR lpszPolicyName, // if this is null, will try to return all the policy names
  1079. OUT LPDWORD lpdwDataType,
  1080. OUT LPVOID lpBuffer, // buffer to fill with information
  1081. IN OUT LPDWORD lpdwBufferSize
  1082. );
  1083. DWORD
  1084. SDBAPI
  1085. SdbQueryDataEx(
  1086. IN HSDB hSDB, // database handle
  1087. IN TAGREF trExe, // tagref of the matching exe
  1088. IN LPCTSTR lpszDataName, // if this is null, will try to return all the policy names
  1089. OUT LPDWORD lpdwDataType, // pointer to data type (REG_SZ, REG_BINARY, etc)
  1090. OUT LPVOID lpBuffer, // buffer to fill with information
  1091. IN OUT LPDWORD lpdwBufferSize, // pointer to buffer size
  1092. OUT TAGREF* ptrData // optional pointer to the retrieved data tag
  1093. );
  1094. DWORD
  1095. SdbQueryDataExTagID(
  1096. IN PDB pdb, // database handle
  1097. IN TAGID tiExe, // tagref of the matching exe
  1098. IN LPCTSTR lpszDataName, // if this is null, will try to return all the policy names
  1099. OUT LPDWORD lpdwDataType, // pointer to data type (REG_SZ, REG_BINARY, etc)
  1100. OUT LPVOID lpBuffer, // buffer to fill with information
  1101. IN OUT LPDWORD lpcbBufferSize, // pointer to buffer size (in bytes)
  1102. OUT TAGID* ptiData // optional pointer to the retrieved data tag
  1103. );
  1104. //
  1105. // Defines to keep kernel-mode code more readable
  1106. //
  1107. #define SdbQueryDriverInformation SdbQueryData
  1108. #define SdbReadDriverInformation SdbReadEntryInformation
  1109. #define SDBDRIVERINFO SDBENTRYINFO;
  1110. #define PSDBDRIVERINFO PSDBENTRYINFO;
  1111. //
  1112. // Query attribute APIs
  1113. //
  1114. PVOID
  1115. SdbGetFileInfo(
  1116. IN HSDB hSDB,
  1117. IN LPCTSTR pwszFilePath,
  1118. IN HANDLE hFile OPTIONAL,
  1119. IN LPVOID pImageBase OPTIONAL,
  1120. IN DWORD dwImageSize OPTIONAL,
  1121. IN BOOL bNoCache
  1122. );
  1123. VOID
  1124. SdbFreeFileInfo(
  1125. IN PVOID pFileInfo
  1126. );
  1127. //
  1128. // Get item from item ref
  1129. //
  1130. TAGREF
  1131. SdbGetItemFromItemRef(
  1132. IN HSDB hSDB,
  1133. IN TAGREF trItemRef,
  1134. IN TAG tagItemKey,
  1135. IN TAG tagItemTAGID,
  1136. IN TAG tagItem
  1137. );
  1138. #define SdbGetShimFromShimRef(hSDB, trShimRef) \
  1139. (SdbGetItemFromItemRef(hSDB, trShimRef, TAG_NAME, TAG_SHIM_TAGID, TAG_SHIM))
  1140. #define SdbGetPatchFromPatchRef(hSDB, trPatchRef) \
  1141. (SdbGetItemFromItemRef(hSDB, trPatchRef, TAG_NAME, TAG_PATCH_TAGID, TAG_PATCH))
  1142. #define SdbGetFlagFromFlagRef(hSDB, trFlagRef) \
  1143. (SdbGetItemFromItemRef(hSDB, trFlagRef, TAG_NAME, TAG_FLAG_TAGID, TAG_FLAG))
  1144. // INDEX functions
  1145. BOOL SdbDeclareIndex(
  1146. IN PDB pdb,
  1147. IN TAG tWhich,
  1148. IN TAG tKey,
  1149. IN DWORD dwEntries,
  1150. IN BOOL bUniqueKey,
  1151. OUT INDEXID* piiIndex
  1152. );
  1153. BOOL
  1154. SdbStartIndexing(
  1155. IN PDB pdb,
  1156. IN INDEXID iiWhich
  1157. );
  1158. BOOL
  1159. SdbStopIndexing(
  1160. IN PDB pdb,
  1161. IN INDEXID iiWhich
  1162. );
  1163. BOOL
  1164. SdbCommitIndexes(
  1165. IN PDB pdb
  1166. );
  1167. TAGID
  1168. SdbFindFirstDWORDIndexedTag(
  1169. IN PDB pdb,
  1170. IN TAG tWhich,
  1171. IN TAG tKey,
  1172. IN DWORD dwName,
  1173. OUT FIND_INFO* pFindInfo
  1174. );
  1175. TAGID
  1176. SdbFindNextDWORDIndexedTag(
  1177. IN PDB pdb,
  1178. OUT FIND_INFO* pFindInfo
  1179. );
  1180. TAGID
  1181. SdbFindFirstStringIndexedTag(
  1182. IN PDB pdb,
  1183. IN TAG tWhich,
  1184. IN TAG tKey,
  1185. IN LPCTSTR pwszName,
  1186. OUT FIND_INFO* pFindInfo
  1187. );
  1188. TAGID
  1189. SdbFindNextStringIndexedTag(
  1190. IN PDB pdb,
  1191. OUT FIND_INFO* pFindInfo
  1192. );
  1193. TAGID
  1194. SdbFindFirstGUIDIndexedTag(
  1195. IN PDB pdb,
  1196. IN TAG tWhich,
  1197. IN TAG tKey,
  1198. IN GUID* pGuidName,
  1199. OUT FIND_INFO* pFindInfo
  1200. );
  1201. TAGID
  1202. SdbFindNextGUIDIndexedTag(
  1203. IN PDB pdb,
  1204. OUT FIND_INFO* pFindInfo
  1205. );
  1206. ULONGLONG
  1207. SdbMakeIndexKeyFromString(
  1208. IN LPCTSTR pwszKey
  1209. );
  1210. //
  1211. // These macros allow to make a key from dword or a guid
  1212. //
  1213. #define MAKEKEYFROMDWORD(dwValue) \
  1214. ((ULONGLONG)(dwValue))
  1215. #if defined(_WIN64)
  1216. ULONGLONG
  1217. SdbMakeIndexKeyFromGUID(
  1218. IN GUID* pGuid
  1219. );
  1220. #define MAKEKEYFROMGUID(pGuid) SdbMakeIndexKeyFromGUID(pGuid)
  1221. #else /* ! WIN64 */
  1222. #define MAKEKEYFROMGUID(pGuid) \
  1223. ((ULONGLONG)((*(PULONGLONG)(pGuid)) ^ (*((PULONGLONG)(pGuid) + 1))))
  1224. #endif /* WIN64 */
  1225. TAGID
  1226. SdbGetIndex(
  1227. IN PDB pdb,
  1228. IN TAG tWhich,
  1229. IN TAG tKey,
  1230. OUT LPDWORD lpdwFlags OPTIONAL
  1231. );
  1232. #define SdbIsIndexAvailable(pdb, tWhich, tKey) \
  1233. (SdbGetIndex(pdb, tWhich, tKey, NULL))
  1234. //
  1235. // WRITE FUNCTIONS
  1236. //
  1237. TAGID
  1238. SdbBeginWriteListTag(
  1239. IN PDB pdb,
  1240. IN TAG tTag
  1241. );
  1242. BOOL
  1243. SdbEndWriteListTag(
  1244. IN PDB pdb,
  1245. IN TAGID tiList
  1246. );
  1247. BOOL
  1248. SdbWriteStringTagDirect(
  1249. IN PDB pdb,
  1250. IN TAG tTag,
  1251. IN LPCWSTR pwszData
  1252. );
  1253. BOOL
  1254. SdbWriteStringRefTag(
  1255. IN PDB pdb,
  1256. IN TAG tTag,
  1257. IN STRINGREF srData
  1258. );
  1259. BOOL
  1260. SdbWriteNULLTag(
  1261. IN PDB pdb,
  1262. IN TAG tTag
  1263. );
  1264. BOOL
  1265. SdbWriteBYTETag(
  1266. IN PDB pdb,
  1267. IN TAG tTag,
  1268. IN BYTE jData
  1269. );
  1270. BOOL
  1271. SdbWriteWORDTag(
  1272. IN PDB pdb,
  1273. IN TAG tTag,
  1274. IN WORD wData
  1275. );
  1276. BOOL
  1277. SdbWriteDWORDTag(
  1278. IN PDB pdb,
  1279. IN TAG tTag,
  1280. IN DWORD dwData
  1281. );
  1282. BOOL
  1283. SdbWriteQWORDTag(
  1284. IN PDB pdb,
  1285. IN TAG tTag,
  1286. IN ULONGLONG qwData
  1287. );
  1288. BOOL
  1289. SdbWriteStringTag(
  1290. IN PDB pdb,
  1291. IN TAG tTag,
  1292. IN LPCWSTR pwszData
  1293. );
  1294. BOOL
  1295. SdbWriteBinaryTag(
  1296. IN PDB pdb,
  1297. IN TAG tTag,
  1298. IN PBYTE pBuffer,
  1299. IN DWORD dwSize
  1300. );
  1301. BOOL
  1302. SdbWriteBinaryTagFromFile(
  1303. IN PDB pdb,
  1304. IN TAG tTag,
  1305. IN LPCWSTR pwszPath
  1306. );
  1307. ////////////////////////////////////////////////////////////////////////////////////////////
  1308. //
  1309. // Attribute retrieval
  1310. //
  1311. //
  1312. //
  1313. // Attribute Information
  1314. // identified by a tag
  1315. //
  1316. //
  1317. typedef struct tagATTRINFO {
  1318. TAG tAttrID; // tag for this attribute (includes type)
  1319. DWORD dwFlags; // flags : such as "not avail" or "not there yet"
  1320. union { // anonymous union with values
  1321. ULONGLONG ullAttr; // QWORD value (TAG_TYPE_QWORD)
  1322. DWORD dwAttr; // DWORD value (TAG_TYPE_DWORD)
  1323. TCHAR* lpAttr; // WCHAR* value (TAG_TYPE_STRINGREF)
  1324. };
  1325. } ATTRINFO, *PATTRINFO;
  1326. //
  1327. // Flags that go into ATTRINFO's dwFlags field
  1328. //
  1329. //
  1330. #define ATTRIBUTE_AVAILABLE 0x00000001 // this will be set if attribute was obtained
  1331. #define ATTRIBUTE_FAILED 0x00000002 // this will be set if we tried to get it
  1332. // and failed
  1333. BOOL
  1334. SDBAPI
  1335. SdbGetFileAttributes(
  1336. IN LPCTSTR lpwszFileName,
  1337. OUT PATTRINFO* ppAttrInfo,
  1338. OUT LPDWORD lpdwAttrCount);
  1339. BOOL
  1340. SDBAPI
  1341. SdbFreeFileAttributes(
  1342. IN PATTRINFO pFileAttributes);
  1343. BOOL
  1344. SDBAPI
  1345. SdbFormatAttribute(
  1346. IN PATTRINFO pAttrInfo,
  1347. OUT LPTSTR pchBuffer,
  1348. IN DWORD dwBufferSize);
  1349. ////////////////////////////////////////////////////////////////////////////////////////////
  1350. //
  1351. //
  1352. // High-level functions to extract information related to apphelp
  1353. //
  1354. //
  1355. typedef struct tagAPPHELP_DATA {
  1356. DWORD dwFlags; // flags (if any)
  1357. DWORD dwSeverity; // can be none APPTYPE_NONE (0)
  1358. DWORD dwHTMLHelpID; // help id
  1359. LPTSTR szAppName;
  1360. TAGREF trExe; // matched on this exe (in apphelp section)
  1361. LPTSTR szURL; // URL
  1362. LPTSTR szLink; // link text
  1363. LPTSTR szAppTitle; // title
  1364. LPTSTR szContact; // contact info
  1365. LPTSTR szDetails; // details
  1366. //
  1367. // non-apphelp data (this is managed by the host app
  1368. //
  1369. DWORD dwData;
  1370. } APPHELP_DATA, *PAPPHELP_DATA;
  1371. BOOL
  1372. SdbReadApphelpData(
  1373. IN HSDB hSDB,
  1374. IN TAGREF trExe,
  1375. OUT PAPPHELP_DATA pData
  1376. );
  1377. BOOL
  1378. SdbReadApphelpDetailsData(
  1379. IN PDB pdbDetails,
  1380. OUT PAPPHELP_DATA pData
  1381. );
  1382. ////////////////////////////////////////////////////////////////////////////////////////////
  1383. //
  1384. //
  1385. // A few functions from apphelp.dll
  1386. //
  1387. //
  1388. BOOL
  1389. SDBAPI
  1390. SetPermLayers(
  1391. IN LPCWSTR pwszPath, // path to the file to set a permanent layer on
  1392. IN LPCWSTR pwszLayers, // layers to apply to the file, separated by spaces
  1393. IN BOOL bMachine // TRUE if the layers should be persisted per machine
  1394. );
  1395. BOOL
  1396. SDBAPI
  1397. GetPermLayers(
  1398. IN LPCWSTR pwszPath, // path to the file to set a permanent layer on
  1399. OUT LPWSTR pwszLayers, // layers to apply to the file, separated by spaces
  1400. OUT DWORD* pdwBytes, // input: number of bytes available; output is number of bytes needed
  1401. IN DWORD dwFlags
  1402. );
  1403. BOOL
  1404. SDBAPI
  1405. AllowPermLayer(
  1406. IN LPCWSTR pwszPath // path to the file to check whether you can set a permanent layer on
  1407. );
  1408. typedef struct _NTVDM_FLAGS {
  1409. DWORD dwWOWCompatFlags;
  1410. DWORD dwWOWCompatFlagsEx;
  1411. DWORD dwUserWOWCompatFlags;
  1412. DWORD dwWOWCompatFlags2;
  1413. DWORD dwWOWCompatFlagsFE;
  1414. DWORD dwFlagsInfoSize; // size of the memory area pointed to by pFlagsInfo
  1415. PVOID pFlagsInfo; // pointer that is used to store flags-related information
  1416. } NTVDM_FLAGS, *PNTVDM_FLAGS;
  1417. //
  1418. // Macros we use to obtain flags command lines
  1419. //
  1420. #define MAKEQWORD(dwLow, dwHigh) \
  1421. ( ((ULONGLONG)(dwLow)) | ( ((ULONGLONG)(dwHigh)) << 32) )
  1422. #define GET_WOWCOMPATFLAGS_CMDLINE(pFlagInfo, dwFlag, ppCmdLine) \
  1423. SdbQueryFlagInfo(pFlagInfo, TAG_FLAGS_NTVDM1, MAKEQWORD(dwFlag, 0), ppCmdLine)
  1424. #define GET_WOWCOMPATFLAGSEX_CMDLINE(pFlagInfo, dwFlag, ppCmdLine) \
  1425. SdbQueryFlagInfo(pFlagInfo, TAG_FLAGS_NTVDM1, MAKEQWORD(0, dwFlag), ppCmdLine)
  1426. #define GET_USERWOWCOMPATFLAGS_CMDLINE(pFlagInfo, dwFlag, ppCmdLine) \
  1427. SdbQueryFlagInfo(pFlagInfo, TAG_FLAGS_NTVDM2, MAKEQWORD(dwFlag, 0), ppCmdLine)
  1428. #define GET_WOWCOMPATFLAGS2_CMDLINE(pFlagInfo, dwFlag, ppCmdLine) \
  1429. SdbQueryFlagInfo(pFlagInfo, TAG_FLAGS_NTVDM2, MAKEQWORD(0, dwFlag), ppCmdLine)
  1430. #define GET_WOWCOMPATFLAGSFE_CMDLINE(pFlagInfo, dwFlag, ppCmdLine) \
  1431. SdbQueryFlagInfo(pFlagInfo, TAG_FLAGS_NTVDM3, MAKEQWORD(dwFlag, 0), ppCmdLine)
  1432. typedef struct _APPHELP_INFO {
  1433. //
  1434. // html help id mode
  1435. //
  1436. DWORD dwHtmlHelpID; // html help id
  1437. DWORD dwSeverity; // must have
  1438. LPCTSTR lpszAppName;
  1439. GUID guidID; // entry guid
  1440. //
  1441. // Conventional mode
  1442. //
  1443. TAGID tiExe; // the TAGID of the exe entry within the DB
  1444. GUID guidDB; // the guid of the DB that has the EXE entry
  1445. BOOL bOfflineContent;
  1446. BOOL bUseHTMLHelp;
  1447. LPCTSTR lpszChmFile;
  1448. LPCTSTR lpszDetailsFile;
  1449. //
  1450. // preserve users choice on the dialog if user chooses to persist settings
  1451. //
  1452. BOOL bPreserveChoice;
  1453. //
  1454. // TRUE if msi mode (matters for ia64 platform)
  1455. //
  1456. BOOL bMSI;
  1457. } APPHELP_INFO, *PAPPHELP_INFO;
  1458. ////////////////////////////////////////////////////////////////////////////////////////////
  1459. //
  1460. //
  1461. // Functions to access apphelp functionality
  1462. //
  1463. //
  1464. // prototypes which are exported for ntvdm shim support
  1465. typedef void (*LPFNSE_REMOVENTVDM)(HANDLE);
  1466. typedef BOOL (*LPFNSE_SHIMNTVDM)(LPCWSTR, HSDB, SDBQUERYRESULT*, PVDMTABLE);
  1467. // Max size of compat layer buffer
  1468. #define COMPATLAYERMAXLEN 256
  1469. BOOL
  1470. ApphelpGetNTVDMInfo(
  1471. IN LPCWSTR pwszPath, // path to the app in NT format
  1472. IN LPCWSTR pwszModule, // module name
  1473. IN LPCWSTR pEnvironment, // pointer to the environment of the task that is
  1474. // being created or NULL if we are to use the main NTVDM
  1475. // environment block.
  1476. OUT LPWSTR pszCompatLayer, // The new compat layer variable. with format:
  1477. // "Alpha Bravo Charlie" -- allow COMPATLAYERMAXLEN chars for this.
  1478. OUT PNTVDM_FLAGS pFlags, // The flags
  1479. OUT PAPPHELP_INFO pAHInfo, // If there is apphelp to display, this will be filled
  1480. // in with non-null values
  1481. OUT HSDB* phSDB, // The handle to the database.
  1482. OUT PSDBQUERYRESULT pQueryResult // The query result.
  1483. );
  1484. BOOL
  1485. ApphelpShowDialog(
  1486. IN PAPPHELP_INFO pAHInfo, // the info necessary to find the apphelp data
  1487. IN PHANDLE phProcess // [optional] returns the process handle of
  1488. // the process displaying the apphelp.
  1489. // When the process completes, the return value
  1490. // (from GetExitCodeProcess()) will be zero
  1491. // if the app should not run, or non-zero
  1492. // if it should run.
  1493. );
  1494. typedef PVOID HAPPHELPINFOCONTEXT;
  1495. typedef enum tagAPPHELPINFORMATIONCLASS {
  1496. ApphelpFlags,
  1497. ApphelpExeName,
  1498. ApphelpAppName,
  1499. ApphelpVendorName,
  1500. ApphelpHtmlHelpID,
  1501. ApphelpProblemSeverity,
  1502. ApphelpLinkURL,
  1503. ApphelpLinkText,
  1504. ApphelpTitle,
  1505. ApphelpDetails,
  1506. ApphelpContact,
  1507. ApphelpHelpCenterURL,
  1508. ApphelpExeTagID,
  1509. ApphelpDatabaseGUID // this is guid of a database containing the match
  1510. } APPHELPINFORMATIONCLASS;
  1511. PDB
  1512. SDBAPI
  1513. SdbOpenApphelpDetailsDatabase(
  1514. IN LPCWSTR pwsDetailsDatabasePath OPTIONAL
  1515. );
  1516. HAPPHELPINFOCONTEXT
  1517. SDBAPI
  1518. SdbOpenApphelpInformation(
  1519. IN GUID* pguidDB,
  1520. IN GUID* pguidID
  1521. );
  1522. HAPPHELPINFOCONTEXT
  1523. SDBAPI
  1524. SdbOpenApphelpInformationByID(
  1525. IN HSDB hSDB,
  1526. IN TAGREF trEntry,
  1527. IN DWORD dwDatabaseType // pass the type of db you are using
  1528. );
  1529. BOOL
  1530. SDBAPI
  1531. SdbCloseApphelpInformation(
  1532. IN HAPPHELPINFOCONTEXT hctx
  1533. );
  1534. DWORD
  1535. SDBAPI
  1536. SdbQueryApphelpInformation(
  1537. IN HAPPHELPINFOCONTEXT hctx,
  1538. IN APPHELPINFORMATIONCLASS InfoClass,
  1539. OUT LPVOID pBuffer, // may be NULL
  1540. IN DWORD cbSize // may be 0 if pBuffer is NULL
  1541. );
  1542. BOOL
  1543. SDBAPI
  1544. SdbQueryFlagMask(
  1545. IN HSDB hSDB,
  1546. IN SDBQUERYRESULT* pQueryResult,
  1547. IN TAG tMaskType,
  1548. OUT ULONGLONG* pullFlags,
  1549. IN OUT PVOID* ppFlagInfo OPTIONAL
  1550. );
  1551. BOOL
  1552. SDBAPI
  1553. SdbEscapeApphelpURL(
  1554. OUT LPWSTR szResult, // escaped string (output)
  1555. IN OUT LPDWORD pdwCount, // count of tchars in the buffer pointed to by szResult
  1556. IN LPCWSTR szToEscape // string to escape
  1557. );
  1558. BOOL
  1559. SDBAPI
  1560. SdbSetApphelpDebugParameters(
  1561. IN HAPPHELPINFOCONTEXT hctx,
  1562. IN LPCWSTR pszDetailsDatabase OPTIONAL,
  1563. IN BOOL bOfflineContent OPTIONAL, // pass FALSE
  1564. IN BOOL bUseHtmlHelp OPTIONAL, // pass FALSE
  1565. IN LPCWSTR pszChmFile OPTIONAL // pass NULL
  1566. );
  1567. BOOL
  1568. SdbShowApphelpDialog( // returns TRUE if success, whether we should run the app is in pRunApp
  1569. IN PAPPHELP_INFO pAHInfo, // the info necessary to find the apphelp data
  1570. OUT PHANDLE phProcess, // [optional] returns the process handle of
  1571. // the process displaying the apphelp.
  1572. // When the process completes, the return value
  1573. // (from GetExitCodeProcess()) will be zero
  1574. // if the app should not run, or non-zero
  1575. // if it should run.
  1576. IN OUT BOOL* pRunApp
  1577. );
  1578. //
  1579. // WOW cmd line for flags interface
  1580. // instead of calling SdbQueryFlagInfo the macros above should be used
  1581. //
  1582. BOOL
  1583. SDBAPI
  1584. SdbQueryFlagInfo(
  1585. IN PVOID pvFlagInfo,
  1586. IN TAG tFlagType,
  1587. IN ULONGLONG ullFlagMask,
  1588. OUT LPCTSTR * ppCmdLine
  1589. );
  1590. BOOL
  1591. SDBAPI
  1592. SdbFreeFlagInfo(
  1593. IN PVOID pvFlagInfo
  1594. );
  1595. ////////////////////////////////////////////////////////////////////////////////////////////
  1596. //
  1597. // App Verifier macros/defs
  1598. //
  1599. //
  1600. typedef enum _VLOG_LEVEL {
  1601. VLOG_LEVEL_INFO,
  1602. VLOG_LEVEL_WARNING,
  1603. VLOG_LEVEL_ERROR
  1604. } VLOG_LEVEL, *PVLOG_LEVEL;
  1605. typedef enum _AVRF_INFO_ID {
  1606. // INFO ID type actually being passed in PVOID param
  1607. // ------- -----------------------------------------
  1608. AVRF_INFO_NUM_SHIMS, // LPDWORD (preallocated) (szName should be NULL)
  1609. AVRF_INFO_SHIM_NAMES, // LPWSTR * (array of same size as value of AVRF_INFO_NUM_SHIMS)
  1610. // (array is preallocated, strings are allocated by shim)
  1611. // (szName should be NULL)
  1612. AVRF_INFO_DESCRIPTION, // LPWSTR (allocated by shim)
  1613. AVRF_INFO_FRIENDLY_NAME, // LPWSTR (allocated by shim)
  1614. AVRF_INFO_INCLUDE_EXCLUDE, // LPWSTR (allocated by shim)
  1615. AVRF_INFO_FLAGS, // LPDWORD (preallocated)
  1616. AVRF_INFO_OPTIONS_PAGE, // LPPROPSHEETPAGE (preallocated)
  1617. AVRF_INFO_VERSION, // LPDWORD (preallocated), HIWORD=major version, LOWORD=minor version
  1618. AVRF_INFO_GROUPS // LPDWORD (preallocated)
  1619. } AVRF_INFO_ID, *PAVRF_INFO_ID;
  1620. //
  1621. // FLAGS for verifier shims (all flags default to FALSE)
  1622. //
  1623. #define AVRF_FLAG_NO_DEFAULT 0x00000001 // this shim should not be turned on by default
  1624. #define AVRF_FLAG_NO_WIN2K 0x00000002 // this shim should not be used on win2K
  1625. #define AVRF_FLAG_NO_SHIM 0x00000004 // this "shim" is a placeholder and shouldn't actually
  1626. // be applied to an app
  1627. #define AVRF_FLAG_NO_TEST 0x00000008 // this "shim" is not a test, and is purely for adding
  1628. // a page to the options dialog
  1629. #define AVRF_FLAG_NOT_SETUP 0x00000010 // this shim is not appropriate for setup apps
  1630. #define AVRF_FLAG_ONLY_SETUP 0x00000020 // this shim is only appropriate for setup apps
  1631. #define AVRF_FLAG_RUN_ALONE 0x00000040 // this shim should be run by itself with no other shims applied
  1632. #define AVRF_FLAG_INTERNAL_ONLY 0x00000080 // this shim is for Microsoft internal use only
  1633. #define AVRF_FLAG_EXTERNAL_ONLY 0x00000100 // this shim if for external use only - not for MS users
  1634. //
  1635. // GROUPS for verifier shims (by default, shims are in no groups)
  1636. //
  1637. #define AVRF_GROUP_SETUP 0x00000001 // suitable for checking setup programs
  1638. #define AVRF_GROUP_NON_SETUP 0x00000002 // suitable for checking non-setup programs (can be both)
  1639. #define AVRF_GROUP_LOGO 0x00000004 // shims that are useful for logo testing
  1640. //
  1641. // magic number tells us if we're using the same shim interface
  1642. //
  1643. #define VERIFIER_SHIMS_MAGIC 'avfr'
  1644. typedef DWORD (*_pfnGetVerifierMagic)(void);
  1645. typedef BOOL (*_pfnQueryShimInfo)(LPCWSTR szName, AVRF_INFO_ID eInfo, PVOID pInfo);
  1646. //
  1647. // special callback, so a shim can be notified when it is activated or deactivated for a
  1648. // specific application.
  1649. //
  1650. typedef BOOL (*_pfnActivateCallback)(LPCWSTR szAppName, BOOL bActivate);
  1651. //
  1652. // Where we store default verifier shim settings
  1653. //
  1654. #define AVRF_DEFAULT_SETTINGS_NAME TEXT("{default}")
  1655. #define AVRF_DEFAULT_SETTINGS_NAME_W L"{default}"
  1656. #define AVRF_DEFAULT_SETTINGS_NAME_A "{default}"
  1657. typedef struct _SHIM_DESCRIPTION {
  1658. LPWSTR szName;
  1659. LPWSTR szDescription;
  1660. LPWSTR szExcludes; // comma separated module names
  1661. LPWSTR szIncludes; // comma separated module names
  1662. DWORD dwFlags;
  1663. } SHIM_DESCRIPTION, *PSHIM_DESCRIPTION;
  1664. #define ENUM_SHIMS_MAGIC 'enum'
  1665. typedef DWORD (*_pfnEnumShims)(PSHIM_DESCRIPTION pShims, DWORD dwMagic);
  1666. typedef BOOL (*_pfnIsVerifierDLL)(void);
  1667. ////////////////////////////////////////////////////////////////////////////////////////////
  1668. //
  1669. // Miscelaneous macros/defs
  1670. //
  1671. //
  1672. //
  1673. // Apphelp types
  1674. //
  1675. #define APPHELP_TYPE_MASK 0x000000FF
  1676. #define APPHELP_NONE 0x00000000
  1677. #define APPHELP_NOBLOCK 0x00000001
  1678. #define APPHELP_HARDBLOCK 0x00000002
  1679. #define APPHELP_MINORPROBLEM 0x00000003
  1680. #define APPHELP_REINSTALL 0x00000004
  1681. #define APPHELP_VERSIONSUB 0x00000005
  1682. #define APPHELP_SHIM 0x00000006
  1683. //
  1684. // Match modes for EXEs
  1685. //
  1686. #define MATCH_NORMAL 0
  1687. #define MATCH_EXCLUSIVE 1
  1688. #define MATCH_ADDITIVE 2
  1689. //
  1690. // the struct below packs into a WORD
  1691. // older compilers won't like this union
  1692. // (because of nameless members)
  1693. //
  1694. // Tell compiler to be quite about the nameless member.
  1695. #pragma warning (disable : 4201 )
  1696. typedef union tagMATCHMODE {
  1697. struct {
  1698. USHORT Type : 4; // type of match
  1699. USHORT Flags: 4; // flags for matching
  1700. // future expansion here
  1701. };
  1702. WORD wMatchMode; // we use this to init from the database
  1703. DWORD dwMatchMode; // this is the "whole" match mode
  1704. } MATCHMODE, *PMATCHMODE;
  1705. #pragma warning (default : 4201 )
  1706. //
  1707. // match modes:
  1708. //
  1709. // normal -- find a match, we're done
  1710. // additive -- keep the match, then keep matching according to flags
  1711. // exclusive -- keep the match, throw away all other matches
  1712. //
  1713. static const MATCHMODE MatchModeDefaultMain = { { MATCH_NORMAL, 0 } };
  1714. #define MATCHMODE_DEFAULT_MAIN (MatchModeDefaultMain.wMatchMode)
  1715. static const MATCHMODE MatchModeDefaultCustom = { { MATCH_ADDITIVE, 0 } };
  1716. #define MATCHMODE_DEFAULT_CUSTOM (MatchModeDefaultCustom.wMatchMode)
  1717. #define MAKE_MATCHMODE(dwMatchMode, Type, Flags) \
  1718. { \
  1719. ((PMATCHMODE)&(dwMatchMode))->Type = Type; \
  1720. ((PMATCHMODE)&(dwMatchMode))->Flags = Flags; \
  1721. }
  1722. //
  1723. // Pre-defined match modes for shimdbc
  1724. //
  1725. static const MATCHMODE MatchModeNormal = { { MATCH_NORMAL, 0 } };
  1726. static const MATCHMODE MatchModeAdditive = { { MATCH_ADDITIVE, 0 } };
  1727. static const MATCHMODE MatchModeExclusive = { { MATCH_EXCLUSIVE, 0 } };
  1728. #define MATCHMODE_NORMAL_SHIMDBC (MatchModeNormal.wMatchMode)
  1729. #define MATCHMODE_ADDITIVE_SHIMDBC (MatchModeAdditive.wMatchMode)
  1730. #define MATCHMODE_EXCLUSIVE_SHIMDBC (MatchModeExclusive.wMatchMode)
  1731. //
  1732. // Layer flags
  1733. //
  1734. #define LAYER_FLAG_NONE 0x00000000 // None
  1735. #define LAYER_APPLY_TO_SYSTEM_EXES 0x00000001 // Apply to exes in system32 (including sub dir) and windir
  1736. #define LAYER_USE_NO_EXE_ENTRIES 0x00000002 // Do not use any EXE entries
  1737. //
  1738. // Runtime platform flags
  1739. //
  1740. #define RUNTIME_PLATFORM_FLAG_NOT 0x80000000
  1741. #define RUNTIME_PLATFORM_FLAG_NOT_ELEMENT 0x00000080
  1742. #define RUNTIME_PLATFORM_FLAG_VALID 0x00000040
  1743. #define RUNTIME_PLATFORM_MASK_ELEMENT 0x000000FF
  1744. #define RUNTIME_PLATFORM_MASK_VALUE 0x0000003F
  1745. #define RUNTIME_PLATFORM_ANY 0xC0000000 // no valid bits + NOT + flag
  1746. //
  1747. // Shimdbc compile-time platform (OS_PLATFORM) flags
  1748. //
  1749. #define OS_PLATFORM_NONE 0x00000000
  1750. #define OS_PLATFORM_I386 0x00000001
  1751. #define OS_PLATFORM_IA64 0x00000002
  1752. #define OS_PLATFORM_ALL 0xFFFFFFFF
  1753. //
  1754. // These definitions are used for OS SKU attribute tags on EXE entries
  1755. //
  1756. #define OS_SKU_NONE 0x00000000 // None
  1757. #define OS_SKU_PER 0x00000001 // Personal
  1758. #define OS_SKU_PRO 0x00000002 // Professional
  1759. #define OS_SKU_SRV 0x00000004 // Server
  1760. #define OS_SKU_ADS 0x00000008 // Advanced Server
  1761. #define OS_SKU_DTC 0x00000010 // Datacenter
  1762. #define OS_SKU_BLA 0x00000020 // Blade Server
  1763. #define OS_SKU_TAB 0x00000040 // TabletPC
  1764. #define OS_SKU_MED 0x00000080 // eHome
  1765. #define OS_SKU_SBS 0x00000100 // Small business server
  1766. #define OS_SKU_ALL 0xFFFFFFFF
  1767. #ifndef ARRAYSIZE
  1768. #define ARRAYSIZE(rg) (sizeof(rg)/sizeof((rg)[0]))
  1769. #endif
  1770. #ifndef OFFSETOF
  1771. #define OFFSETOF offsetof
  1772. #endif
  1773. #define CHARCOUNT(sz) (sizeof(sz) / sizeof(sz[0]))
  1774. //
  1775. // our reg key locations
  1776. //
  1777. #define APPCOMPAT_LOCATION TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags")
  1778. #define APPCOMPAT_KEY_PATH APPCOMPAT_LOCATION
  1779. #define APPCOMPAT_KEY_PATH_CUSTOM APPCOMPAT_LOCATION TEXT("\\Custom")
  1780. #define APPCOMPAT_KEY_PATH_INSTALLEDSDB APPCOMPAT_LOCATION TEXT("\\InstalledSDB")
  1781. #define POLICY_KEY_APPCOMPAT TEXT("Software\\Policies\\Microsoft\\Windows\\AppCompat")
  1782. #define POLICY_VALUE_DISABLE_ENGINE TEXT("DisableEngine")
  1783. #define POLICY_VALUE_DISABLE_WIZARD TEXT("DisableWizard")
  1784. #define POLICY_VALUE_DISABLE_PROPPAGE TEXT("DisablePropPage")
  1785. #define POLICY_VALUE_APPHELP_LOG TEXT("LogAppHelpEvents")
  1786. // NT API versions
  1787. #define APPCOMPAT_KEY_PATH_MACHINE TEXT("\\Registry\\Machine\\") APPCOMPAT_LOCATION
  1788. #define APPCOMPAT_KEY_PATH_NT TEXT("\\") APPCOMPAT_LOCATION
  1789. #define APPCOMPAT_PERM_LAYER_PATH TEXT("\\") APPCOMPAT_LOCATION TEXT("\\Layers")
  1790. #define APPCOMPAT_KEY_PATH_MACHINE_CUSTOM APPCOMPAT_KEY_PATH_MACHINE TEXT("\\Custom")
  1791. #define APPCOMPAT_KEY_PATH_MACHINE_INSTALLEDSDB APPCOMPAT_KEY_PATH_MACHINE TEXT("\\InstalledSDB")
  1792. //
  1793. // our reg key locations
  1794. //
  1795. #define POLICY_VALUE_APPHELP_LOG_A "LogAppHelpEvents"
  1796. //
  1797. // our reg key locations
  1798. //
  1799. #define APPCOMPAT_LOCATION_W L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags"
  1800. #define APPCOMPAT_KEY_PATH_W APPCOMPAT_LOCATION_W
  1801. #define APPCOMPAT_KEY_PATH_CUSTOM_W APPCOMPAT_LOCATION_W L"\\Custom"
  1802. #define APPCOMPAT_KEY_PATH_INSTALLEDSDB_W APPCOMPAT_LOCATION_W L"\\InstalledSDB"
  1803. #define POLICY_KEY_APPCOMPAT_W L"Software\\Policies\\Microsoft\\Windows\\AppCompat"
  1804. #define POLICY_VALUE_DISABLE_ENGINE_W L"DisableEngine"
  1805. #define POLICY_VALUE_DISABLE_WIZARD_W L"DisableWizard"
  1806. #define POLICY_VALUE_DISABLE_PROPPAGE_W L"DisablePropPage"
  1807. #define POLICY_VALUE_APPHELP_LOG_W L"LogAppHelpEvents"
  1808. //
  1809. // LUA all-users redirection location
  1810. //
  1811. #define LUA_REDIR ("%ALLUSERSPROFILE%\\Application Data\\Redirected")
  1812. #define LUA_REDIR_W TEXT("%ALLUSERSPROFILE%\\Application Data\\Redirected")
  1813. //
  1814. // debug output support
  1815. //
  1816. typedef enum tagSHIMDBGLEVEL {
  1817. sdlError = 1,
  1818. sdlWarning = 2,
  1819. sdlFail = 1, // this means we have failed some api, not necessarily fatal
  1820. sdlInfo = 3,
  1821. sdlUser = 4
  1822. } SHIMDBGLEVEL;
  1823. typedef enum _SHIMVIEWER_OPTION {
  1824. SHIMVIEWER_OPTION_UNINITIAZED,
  1825. SHIMVIEWER_OPTION_NO,
  1826. SHIMVIEWER_OPTION_YES
  1827. } SHIMVIEWER_OPTION;
  1828. //
  1829. // This flag marks the debug out for shimviewer
  1830. //
  1831. #define sdlLogShimViewer 0x00000080UL
  1832. #define sdlMask 0x0000007FUL
  1833. #define SHIMVIEWER_DATA_SIZE 1024
  1834. #define SHIMVIEWER_DATA_PREFIX L"SHIMVIEW:"
  1835. #define SHIMVIEWER_DATA_PREFIX_LEN (sizeof(SHIMVIEWER_DATA_PREFIX)/sizeof(WCHAR) - 1)
  1836. #define FILTER_DBG_LEVEL(level) ((int)((level) & sdlMask))
  1837. extern int __cdecl ShimDbgPrint(INT iDebugLevel, PCH FunctionName, PCH Format, ...);
  1838. #if DBG // Define _DEBUG_SPEW when compiling checked
  1839. #ifndef _DEBUG_SPEW
  1840. #define _DEBUG_SPEW
  1841. #endif
  1842. #endif // DBG
  1843. #ifdef _DEBUG_SPEW
  1844. //
  1845. // This value is a large number (initiallly)
  1846. // We will initialize it from the environment upon the first call
  1847. // to ShimDbgPrint
  1848. //
  1849. extern int g_iShimDebugLevel;
  1850. #define DBGPRINT( _x_ ) \
  1851. { \
  1852. if (g_iShimDebugLevel) { \
  1853. ShimDbgPrint _x_; \
  1854. } \
  1855. }
  1856. #else
  1857. #define DBGPRINT(_x_)
  1858. #endif // _DEBUG_SPEW
  1859. //
  1860. // This is an option controlled by the ShowDebugInfo value under
  1861. // HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags.
  1862. //
  1863. #define APPCOMPAT_KEY_PATH_W_WITH_SLASH L"\\" APPCOMPAT_LOCATION_W
  1864. #define SHIMENG_SHOW_DEBUG_INFO L"ShowDebugInfo"
  1865. extern SHIMVIEWER_OPTION g_eShimViewerOption;
  1866. SHIMVIEWER_OPTION
  1867. SdbGetShowDebugInfoOption(
  1868. void
  1869. );
  1870. ///////////////////////////////////////////////////////////////////////////////
  1871. //
  1872. // SHIM TAGS
  1873. //
  1874. //
  1875. // Function to get the tag names given a tag ID.
  1876. //
  1877. // WARNING !!! : If you add new tags make sure you update SdbApi\attributes.c
  1878. // with the name of the tag in the global gaTagInfo.
  1879. //
  1880. LPCTSTR
  1881. SDBAPI
  1882. SdbTagToString(
  1883. TAG tag
  1884. );
  1885. //
  1886. // LIST types for shimdb
  1887. //
  1888. #define TAG_DATABASE (0x1 | TAG_TYPE_LIST)
  1889. #define TAG_LIBRARY (0x2 | TAG_TYPE_LIST)
  1890. #define TAG_INEXCLUDE (0x3 | TAG_TYPE_LIST)
  1891. #define TAG_SHIM (0x4 | TAG_TYPE_LIST)
  1892. #define TAG_PATCH (0x5 | TAG_TYPE_LIST)
  1893. #define TAG_APP (0x6 | TAG_TYPE_LIST)
  1894. #define TAG_EXE (0x7 | TAG_TYPE_LIST)
  1895. #define TAG_MATCHING_FILE (0x8 | TAG_TYPE_LIST)
  1896. #define TAG_SHIM_REF (0x9 | TAG_TYPE_LIST)
  1897. #define TAG_PATCH_REF (0xA | TAG_TYPE_LIST)
  1898. #define TAG_LAYER (0xB | TAG_TYPE_LIST)
  1899. #define TAG_FILE (0xC | TAG_TYPE_LIST)
  1900. #define TAG_APPHELP (0xD | TAG_TYPE_LIST)
  1901. #define TAG_LINK (0xE | TAG_TYPE_LIST) // Description list w/lang ids and urls
  1902. #define TAG_DATA (0xF | TAG_TYPE_LIST)
  1903. #define TAG_MSI_TRANSFORM (0x10| TAG_TYPE_LIST)
  1904. #define TAG_MSI_TRANSFORM_REF (0x11| TAG_TYPE_LIST)
  1905. #define TAG_MSI_PACKAGE (0x12| TAG_TYPE_LIST)
  1906. #define TAG_FLAG (0x13| TAG_TYPE_LIST)
  1907. #define TAG_MSI_CUSTOM_ACTION (0x14| TAG_TYPE_LIST)
  1908. #define TAG_FLAG_REF (0x15| TAG_TYPE_LIST)
  1909. #define TAG_ACTION (0x16| TAG_TYPE_LIST)
  1910. //
  1911. // STRINGREF types for shimdb
  1912. //
  1913. #define TAG_NAME (0x1 | TAG_TYPE_STRINGREF)
  1914. #define TAG_DESCRIPTION (0x2 | TAG_TYPE_STRINGREF)
  1915. #define TAG_MODULE (0x3 | TAG_TYPE_STRINGREF)
  1916. #define TAG_API (0x4 | TAG_TYPE_STRINGREF)
  1917. #define TAG_VENDOR (0x5 | TAG_TYPE_STRINGREF)
  1918. #define TAG_APP_NAME (0x6 | TAG_TYPE_STRINGREF)
  1919. #define TAG_COMMAND_LINE (0x8 | TAG_TYPE_STRINGREF)
  1920. #define TAG_COMPANY_NAME (0x9 | TAG_TYPE_STRINGREF)
  1921. #define TAG_DLLFILE (0xA | TAG_TYPE_STRINGREF)
  1922. #define TAG_WILDCARD_NAME (0xB | TAG_TYPE_STRINGREF)
  1923. #define TAG_PRODUCT_NAME (0x10 | TAG_TYPE_STRINGREF)
  1924. #define TAG_PRODUCT_VERSION (0x11 | TAG_TYPE_STRINGREF)
  1925. #define TAG_FILE_DESCRIPTION (0x12 | TAG_TYPE_STRINGREF)
  1926. #define TAG_FILE_VERSION (0x13 | TAG_TYPE_STRINGREF)
  1927. #define TAG_ORIGINAL_FILENAME (0x14 | TAG_TYPE_STRINGREF)
  1928. #define TAG_INTERNAL_NAME (0x15 | TAG_TYPE_STRINGREF)
  1929. #define TAG_LEGAL_COPYRIGHT (0x16 | TAG_TYPE_STRINGREF)
  1930. #define TAG_16BIT_DESCRIPTION (0x17 | TAG_TYPE_STRINGREF)
  1931. #define TAG_APPHELP_DETAILS (0x18 | TAG_TYPE_STRINGREF) // Details in single language
  1932. #define TAG_LINK_URL (0x19 | TAG_TYPE_STRINGREF)
  1933. #define TAG_LINK_TEXT (0x1A | TAG_TYPE_STRINGREF)
  1934. #define TAG_APPHELP_TITLE (0x1B | TAG_TYPE_STRINGREF)
  1935. #define TAG_APPHELP_CONTACT (0x1C | TAG_TYPE_STRINGREF)
  1936. #define TAG_SXS_MANIFEST (0x1D | TAG_TYPE_STRINGREF)
  1937. #define TAG_DATA_STRING (0x1E | TAG_TYPE_STRINGREF)
  1938. #define TAG_MSI_TRANSFORM_FILE (0x1F | TAG_TYPE_STRINGREF)
  1939. #define TAG_16BIT_MODULE_NAME (0x20 | TAG_TYPE_STRINGREF)
  1940. #define TAG_LAYER_DISPLAYNAME (0x21 | TAG_TYPE_STRINGREF)
  1941. #define TAG_COMPILER_VERSION (0x22 | TAG_TYPE_STRINGREF)
  1942. #define TAG_ACTION_TYPE (0x23 | TAG_TYPE_STRINGREF)
  1943. #define TAG_STRINGTABLE (0x801 | TAG_TYPE_LIST)
  1944. //
  1945. // DWORD types for shimdb
  1946. //
  1947. #define TAG_SIZE (0x1 | TAG_TYPE_DWORD)
  1948. #define TAG_OFFSET (0x2 | TAG_TYPE_DWORD)
  1949. #define TAG_CHECKSUM (0x3 | TAG_TYPE_DWORD)
  1950. #define TAG_SHIM_TAGID (0x4 | TAG_TYPE_DWORD)
  1951. #define TAG_PATCH_TAGID (0x5 | TAG_TYPE_DWORD)
  1952. #define TAG_MODULE_TYPE (0x6 | TAG_TYPE_DWORD)
  1953. #define TAG_VERDATEHI (0x7 | TAG_TYPE_DWORD)
  1954. #define TAG_VERDATELO (0x8 | TAG_TYPE_DWORD)
  1955. #define TAG_VERFILEOS (0x9 | TAG_TYPE_DWORD)
  1956. #define TAG_VERFILETYPE (0xA | TAG_TYPE_DWORD)
  1957. #define TAG_PE_CHECKSUM (0xB | TAG_TYPE_DWORD)
  1958. #define TAG_PREVOSMAJORVER (0xC | TAG_TYPE_DWORD)
  1959. #define TAG_PREVOSMINORVER (0xD | TAG_TYPE_DWORD)
  1960. #define TAG_PREVOSPLATFORMID (0xE | TAG_TYPE_DWORD)
  1961. #define TAG_PREVOSBUILDNO (0xF | TAG_TYPE_DWORD)
  1962. #define TAG_PROBLEMSEVERITY (0x10 | TAG_TYPE_DWORD)
  1963. #define TAG_LANGID (0x11 | TAG_TYPE_DWORD)
  1964. #define TAG_VER_LANGUAGE (0x12 | TAG_TYPE_DWORD)
  1965. #define TAG_ENGINE (0x14 | TAG_TYPE_DWORD)
  1966. #define TAG_HTMLHELPID (0x15 | TAG_TYPE_DWORD)
  1967. #define TAG_INDEX_FLAGS (0x16 | TAG_TYPE_DWORD)
  1968. #define TAG_FLAGS (0x17 | TAG_TYPE_DWORD)
  1969. #define TAG_DATA_VALUETYPE (0x18 | TAG_TYPE_DWORD)
  1970. #define TAG_DATA_DWORD (0x19 | TAG_TYPE_DWORD)
  1971. #define TAG_LAYER_TAGID (0x1A | TAG_TYPE_DWORD)
  1972. #define TAG_MSI_TRANSFORM_TAGID (0x1B | TAG_TYPE_DWORD)
  1973. #define TAG_LINKER_VERSION (0x1C | TAG_TYPE_DWORD)
  1974. #define TAG_LINK_DATE (0x1D | TAG_TYPE_DWORD)
  1975. #define TAG_UPTO_LINK_DATE (0x1E | TAG_TYPE_DWORD)
  1976. #define TAG_OS_SERVICE_PACK (0x1F | TAG_TYPE_DWORD)
  1977. #define TAG_FLAG_TAGID (0x20 | TAG_TYPE_DWORD)
  1978. #define TAG_RUNTIME_PLATFORM (0x21 | TAG_TYPE_DWORD)
  1979. #define TAG_OS_SKU (0x22 | TAG_TYPE_DWORD)
  1980. #define TAG_TAGID (0x801| TAG_TYPE_DWORD)
  1981. //
  1982. // STRING types
  1983. //
  1984. #define TAG_STRINGTABLE_ITEM (0x801 | TAG_TYPE_STRING)
  1985. //
  1986. // NULL types for shimdb (existence/nonexistence is treated like a BOOL)
  1987. //
  1988. #define TAG_INCLUDE (0x1 | TAG_TYPE_NULL)
  1989. #define TAG_GENERAL (0x2 | TAG_TYPE_NULL)
  1990. #define TAG_MATCH_LOGIC_NOT (0x3 | TAG_TYPE_NULL)
  1991. #define TAG_APPLY_ALL_SHIMS (0x4 | TAG_TYPE_NULL)
  1992. #define TAG_USE_SERVICE_PACK_FILES (0x5 | TAG_TYPE_NULL)
  1993. //
  1994. // QWORD types for shimdb
  1995. //
  1996. #define TAG_TIME (0x1 | TAG_TYPE_QWORD)
  1997. #define TAG_BIN_FILE_VERSION (0x2 | TAG_TYPE_QWORD)
  1998. #define TAG_BIN_PRODUCT_VERSION (0x3 | TAG_TYPE_QWORD)
  1999. #define TAG_MODTIME (0x4 | TAG_TYPE_QWORD)
  2000. #define TAG_FLAG_MASK_KERNEL (0x5 | TAG_TYPE_QWORD)
  2001. #define TAG_UPTO_BIN_PRODUCT_VERSION (0x6 | TAG_TYPE_QWORD)
  2002. #define TAG_DATA_QWORD (0x7 | TAG_TYPE_QWORD)
  2003. #define TAG_FLAG_MASK_USER (0x8 | TAG_TYPE_QWORD)
  2004. #define TAG_FLAGS_NTVDM1 (0x9 | TAG_TYPE_QWORD)
  2005. #define TAG_FLAGS_NTVDM2 (0xA | TAG_TYPE_QWORD)
  2006. #define TAG_FLAGS_NTVDM3 (0xB | TAG_TYPE_QWORD)
  2007. #define TAG_FLAG_MASK_SHELL (0xC | TAG_TYPE_QWORD)
  2008. #define TAG_UPTO_BIN_FILE_VERSION (0xD | TAG_TYPE_QWORD)
  2009. #define TAG_FLAG_MASK_FUSION (0xE | TAG_TYPE_QWORD)
  2010. //
  2011. // BINARY types for shimdb
  2012. //
  2013. #define TAG_PATCH_BITS (0x2 | TAG_TYPE_BINARY)
  2014. #define TAG_FILE_BITS (0x3 | TAG_TYPE_BINARY)
  2015. #define TAG_EXE_ID (0x4 | TAG_TYPE_BINARY)
  2016. #define TAG_DATA_BITS (0x5 | TAG_TYPE_BINARY)
  2017. #define TAG_MSI_PACKAGE_ID (0x6 | TAG_TYPE_BINARY) // msi package id is a guid
  2018. #define TAG_DATABASE_ID (0x7 | TAG_TYPE_BINARY) // database guid
  2019. #define TAG_INDEX_BITS (0x801 | TAG_TYPE_BINARY)
  2020. //
  2021. // INDEX types for shimdb
  2022. //
  2023. #define TAG_INDEXES (0x802 | TAG_TYPE_LIST)
  2024. #define TAG_INDEX (0x803 | TAG_TYPE_LIST)
  2025. //
  2026. // WORD types
  2027. //
  2028. #define TAG_MATCH_MODE (0x1 | TAG_TYPE_WORD)
  2029. #define TAG_TAG (0x801 | TAG_TYPE_WORD)
  2030. #define TAG_INDEX_TAG (0x802 | TAG_TYPE_WORD)
  2031. #define TAG_INDEX_KEY (0x803 | TAG_TYPE_WORD)
  2032. //
  2033. // let the typedefs take the course..
  2034. //
  2035. #undef LPCTSTR
  2036. #undef LPTSTR
  2037. #undef TCHAR
  2038. #endif // _SHIMDB_H_