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.

283 lines
10 KiB

  1. #pragma once
  2. #include "stdinc.h"
  3. #include "fusionbuffer.h"
  4. class CAssemblyRecoveryInfo;
  5. enum SxsWFPResolveCodebase
  6. {
  7. CODEBASE_RESOLVED_URLHEAD_UNKNOWN,
  8. CODEBASE_RESOLVED_URLHEAD_FILE,
  9. CODEBASE_RESOLVED_URLHEAD_HTTP,
  10. CODEBASE_RESOLVED_URLHEAD_WINSOURCE,
  11. CODEBASE_RESOLVED_URLHEAD_CDROM
  12. };
  13. BOOL
  14. SxspDetermineCodebaseType(
  15. IN const CBaseStringBuffer &rcbuffUrlString,
  16. OUT SxsWFPResolveCodebase &rcbaseType,
  17. OUT CBaseStringBuffer *pbuffRemainder = NULL
  18. );
  19. #define CSMD_TOPLEVEL_CODEBASE (L"Codebase")
  20. #define CSMD_TOPLEVEL_CATALOG (L"Catalog")
  21. #define CSMD_TOPLEVEL_SHORTNAME (L"ShortName")
  22. #define CSMD_TOPLEVEL_SHORTCATALOG (L"ShortCatalogName")
  23. #define CSMD_TOPLEVEL_SHORTMANIFEST (L"ShortManifestName")
  24. #define CSMD_TOPLEVEL_MANIFESTHASH (L"ManifestSHA1Hash")
  25. #define CSMD_TOPLEVEL_FILES (L"Files")
  26. #define CSMD_TOPLEVEL_CODEBASES (L"Codebases")
  27. #define CSMD_TOPLEVEL_PUBLIC_KEY_TOKEN (L"PublicKeyToken")
  28. #define CSMD_CODEBASES_PROMPTSTRING (L"Prompt")
  29. #define CSMD_CODEBASES_URL (L"URL")
  30. #define CSMD_TOPLEVEL_IDENTITY (L"Identity")
  31. typedef CFusionArray<BYTE> CFusionByteArray;
  32. typedef CFusionArray<CStringBuffer> CFusionStringArray;
  33. class CFileInformationTableHelper;
  34. class CFileHashTableHelper;
  35. class CSecurityMetaData;
  36. class CFileHashTableHelper:
  37. public CCaseInsensitiveSimpleUnicodeStringTableHelper<CFusionByteArray>
  38. {
  39. public:
  40. static BOOL InitializeValue(const CFusionByteArray &vin, CFusionByteArray &rvstored)
  41. {
  42. FN_PROLOG_WIN32
  43. IFW32FALSE_EXIT(vin.Win32Clone(rvstored));
  44. FN_EPILOG
  45. }
  46. static BOOL UpdateValue(const CFusionByteArray &vin, CFusionByteArray &rvstored) { return InitializeValue( vin, rvstored ); }
  47. };
  48. typedef CCaseInsensitiveSimpleUnicodeStringTable<CFusionByteArray, CFileHashTableHelper> CFileHashTable;
  49. typedef CCaseInsensitiveSimpleUnicodeStringTableIter<CFusionByteArray, CFileHashTableHelper> CFileHashTableIter;
  50. //
  51. // Contains metadata about a file element. This is a collection with the name of
  52. // the file and a list (table) of the SHA1 hash elements.
  53. //
  54. class CMetaDataFileElement : CFileHashTable
  55. {
  56. CMetaDataFileElement( const CMetaDataFileElement& );
  57. CMetaDataFileElement& operator=( const CMetaDataFileElement& );
  58. friend CFileInformationTableHelper;
  59. friend CSecurityMetaData;
  60. BOOL ReadFromRegistry( CRegKey& hkThisFileNode );
  61. BOOL WriteToRegistry( CRegKey& hkThisFileNode ) const;
  62. public:
  63. CMetaDataFileElement();
  64. BOOL Initialize();
  65. BOOL Initialize( const CMetaDataFileElement& other );
  66. BOOL GetHashDataForKind( IN const ALG_ID aid, OUT CFusionByteArray& arrHashData, BOOL &bHadSuchData ) const;
  67. BOOL GetHashDataForKind( IN const CBaseStringBuffer& buffId, OUT CFusionByteArray& arrHashData, BOOL &bHadSuchData ) const;
  68. BOOL PutHashData( IN const ALG_ID aid, IN const CFusionByteArray& arrHashData );
  69. BOOL PutHashData( IN const CBaseStringBuffer& buffId, IN const CFusionByteArray& arrHashData );
  70. };
  71. //
  72. // Now another table, this time of file to metadata mappings
  73. //
  74. class CFileInformationTableHelper :
  75. public CCaseInsensitiveSimpleUnicodeStringTableHelper<CMetaDataFileElement>
  76. {
  77. public:
  78. static BOOL InitializeValue( const CMetaDataFileElement &vin, CMetaDataFileElement &stored ) { return stored.Initialize( vin ); }
  79. static BOOL UpdateValue( const CMetaDataFileElement &vin, CMetaDataFileElement &stored );
  80. };
  81. typedef CCaseInsensitiveSimpleUnicodeStringTable<CMetaDataFileElement, CFileInformationTableHelper> CFileInformationTable;
  82. typedef CCaseInsensitiveSimpleUnicodeStringTableIter<CMetaDataFileElement, CFileInformationTableHelper> CFileInformationTableIter;
  83. class CCodebaseInformation
  84. {
  85. friend CSecurityMetaData;
  86. public:
  87. CCodebaseInformation() : m_Type(CODEBASE_RESOLVED_URLHEAD_UNKNOWN) { }
  88. BOOL Initialize();
  89. BOOL Initialize(const CCodebaseInformation &other);
  90. const CBaseStringBuffer& GetCodebase() const { return m_Codebase; }
  91. BOOL SetCodebase(PCWSTR psz, SIZE_T cch) { return m_Codebase.Win32Assign(psz, cch); }
  92. BOOL SetCodebase(const CBaseStringBuffer & rsb) { return m_Codebase.Win32Assign(rsb); }
  93. const CBaseStringBuffer& GetPromptText() const { return m_PromptText; }
  94. BOOL SetPromptText(PCWSTR psz, SIZE_T cch) { return m_PromptText.Win32Assign(psz, cch); }
  95. BOOL SetPromptText(const CBaseStringBuffer & rsb) { return m_PromptText.Win32Assign(rsb); }
  96. const CBaseStringBuffer &GetReference() const { return m_Reference; }
  97. BOOL SetReference(const CBaseStringBuffer &r) { return m_Reference.Win32Assign(r); }
  98. BOOL Win32GetType(SxsWFPResolveCodebase& Type) const
  99. {
  100. FN_PROLOG_WIN32
  101. if (m_Type == CODEBASE_RESOLVED_URLHEAD_UNKNOWN)
  102. {
  103. IFW32FALSE_EXIT(::SxspDetermineCodebaseType(this->m_Codebase, this->m_Type));
  104. }
  105. Type = m_Type ;
  106. FN_EPILOG
  107. }
  108. BOOL SetType( SxsWFPResolveCodebase Type )
  109. {
  110. FN_PROLOG_WIN32
  111. INTERNAL_ERROR_CHECK(m_Type == CODEBASE_RESOLVED_URLHEAD_UNKNOWN);
  112. this->m_Type = Type;
  113. FN_EPILOG
  114. }
  115. protected:
  116. BOOL WriteToRegistryKey(const CRegKey &rhkCodebaseKey) const;
  117. BOOL ReadFromRegistryKey(const CRegKey &rhkCodebaseKey);
  118. CMediumStringBuffer m_Reference;
  119. CMediumStringBuffer m_Codebase;
  120. CMediumStringBuffer m_PromptText;
  121. mutable SxsWFPResolveCodebase m_Type;
  122. private:
  123. CCodebaseInformation( const CCodebaseInformation& );
  124. CCodebaseInformation& operator=( const CCodebaseInformation& );
  125. };
  126. MAKE_CFUSIONARRAY_READY(CCodebaseInformation, Initialize);
  127. class CCodebaseInformationList : public CFusionArray<CCodebaseInformation>
  128. {
  129. public:
  130. BOOL FindCodebase(const CBaseStringBuffer &rbuffReference, CCodebaseInformation *&rpCodebaseInformation);
  131. BOOL RemoveCodebase(const CBaseStringBuffer &rbuffReference, bool &rfRemoved);
  132. };
  133. class CSecurityMetaData
  134. {
  135. CCodebaseInformationList m_cilCodebases;
  136. CFusionByteArray m_baSignerPublicKeyToken;
  137. CFileInformationTable m_fitFileDataTable;
  138. CSmallStringBuffer m_buffShortNameOnDisk;
  139. CFusionByteArray m_baManifestSha1Hash;
  140. CStringBuffer m_buffTextualAssemblyIdentity;
  141. CStringBuffer m_buffShortCatalogName;
  142. CStringBuffer m_buffShortManifestName;
  143. CSecurityMetaData( const CSecurityMetaData& );
  144. CSecurityMetaData& operator=( const CSecurityMetaData& );
  145. //
  146. // Cheesy, but we always want to merge the two elements if one already exists.
  147. //
  148. BOOL MergeFileDataElement(
  149. const CMetaDataFileElement &pNewFileDataElement,
  150. const CMetaDataFileElement &rpOldFileDataElement,
  151. InsertOrUpdateIfDisposition &Disposition ) { Disposition = eUpdateValue; return TRUE; }
  152. BOOL LoadCodebasesFromKey( CRegKey& hkCodebasesSubkey );
  153. BOOL LoadFilesFromKey( CRegKey& hkCodebasesSubkey );
  154. BOOL WriteFilesIntoKey( CRegKey &rhkFilesKey ) const;
  155. public:
  156. //
  157. // Get information about a single item
  158. //
  159. enum FileAdditionDisposition {
  160. eFailIfAlreadyExists,
  161. eReplaceIfAlreadyExists,
  162. eMergeIfAlreadyExists
  163. };
  164. BOOL AddFileMetaData( const CBaseStringBuffer& rcbuffFileName, CMetaDataFileElement &rElementData, FileAdditionDisposition dispHowToAdd = eFailIfAlreadyExists );
  165. BOOL GetFileMetaData( const CBaseStringBuffer& rcbuffFileName, CMetaDataFileElement const* &rpElementData ) const;
  166. //
  167. // Full table that we can iterate over
  168. //
  169. const CFileInformationTable& GetFileDataTable() const { return m_fitFileDataTable; }
  170. //
  171. // Simplify the addition of a hash value
  172. //
  173. BOOL QuickAddFileHash( const CBaseStringBuffer& rcbuffFileName, ALG_ID aidHashAlg, const CBaseStringBuffer& rcbuffHashValue );
  174. //
  175. // All your codebases are belong to us.
  176. //
  177. const CCodebaseInformationList& GetCodeBaseList() const { return m_cilCodebases; }
  178. protected:
  179. friend CAssemblyRecoveryInfo;
  180. CCodebaseInformationList& GetCodeBaseList() { return m_cilCodebases; }
  181. public:
  182. //
  183. // Short path data
  184. //
  185. BOOL SetShortManifestPath(IN const CBaseStringBuffer &rcbuffShortManifestPath) { return m_buffShortManifestName.Win32Assign(rcbuffShortManifestPath); }
  186. const CBaseStringBuffer &GetShortManifestPath() const { return m_buffShortManifestName; }
  187. BOOL SetShortCatalogPath(IN const CBaseStringBuffer &rcbuffShortCatalogPath) { return m_buffShortCatalogName.Win32Assign(rcbuffShortCatalogPath); }
  188. const CBaseStringBuffer &GetShortCatalogPath() const { return this->m_buffShortCatalogName; };
  189. BOOL AddCodebase(
  190. const CBaseStringBuffer &rbuffReference,
  191. const CBaseStringBuffer &rbuffCodebase,
  192. const CBaseStringBuffer &rbuffPrompt );
  193. BOOL RemoveCodebase(const CBaseStringBuffer &rbuffReference, bool &rfRemoved);
  194. //
  195. // On-disk shortname?
  196. //
  197. BOOL SetInstalledDirShortName(const CBaseStringBuffer &rcbuffShortName) { return this->m_buffShortNameOnDisk.Win32Assign(rcbuffShortName); }
  198. const CBaseStringBuffer &GetInstalledDirShortName() const { return this->m_buffShortNameOnDisk; }
  199. //
  200. // Manifest hash?
  201. //
  202. BOOL SetManifestHash( const CFusionByteArray &rcbaManifestHash ) { return rcbaManifestHash.Win32Clone(this->m_baManifestSha1Hash); }
  203. const CFusionByteArray &GetManifestHash() const { return this->m_baManifestSha1Hash; }
  204. //
  205. // Identity
  206. //
  207. BOOL SetTextualIdentity( const CBaseStringBuffer &rcbuffIdentity ) { return m_buffTextualAssemblyIdentity.Win32Assign(rcbuffIdentity); }
  208. const CBaseStringBuffer &GetTextualIdentity() const { return this->m_buffTextualAssemblyIdentity; }
  209. //
  210. // Signer public key token
  211. //
  212. BOOL SetSignerPublicKeyTokenBits( const CFusionByteArray& rcbuffSignerPublicKeyBits );
  213. const CFusionByteArray& GetSignerPublicKeyTokenBits() const { return m_baSignerPublicKeyToken; }
  214. //
  215. // Dummy - Initialize() is what you -really- want.
  216. //
  217. CSecurityMetaData() { }
  218. BOOL Initialize();
  219. BOOL Initialize(const CSecurityMetaData &other);
  220. BOOL Initialize(const CBaseStringBuffer &rcbuffTextualIdentity);
  221. BOOL LoadFromRegistryKey(const CRegKey &rhkRegistryNode);
  222. #define SXSP_WRITE_PRIMARY_ASSEMBLY_INFO_INTO_REGISTRY_KEY_FLAG_REFRESH (0x00000001)
  223. BOOL WritePrimaryAssemblyInfoIntoRegistryKey(ULONG Flags, const CRegKey &rhkRegistryNode) const;
  224. BOOL WriteSecondaryAssemblyInfoIntoRegistryKey(const CRegKey &rhkRegistryNode) const;
  225. };