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.

251 lines
8.5 KiB

  1. using System;
  2. using System.Text;
  3. using System.Net;
  4. using System.IO;
  5. using System.Text.RegularExpressions;
  6. using System.Runtime.Remoting;
  7. using System.Globalization;
  8. using System.Security;
  9. using System.Security.Policy;
  10. using System.Security.Permissions;
  11. using System.Collections;
  12. using System.Runtime.InteropServices;
  13. using System.Reflection;
  14. using System.Configuration.Assemblies;
  15. using System.Threading;
  16. using System.Xml;
  17. using System.Xml.XPath;
  18. namespace Microsoft.Fusion.ADF
  19. {
  20. public enum FileType : int
  21. {
  22. Unknown = 0,
  23. RawFile = 1,
  24. ApplicationManifest = 2,
  25. ComponentManifest = 3
  26. }
  27. public interface IAssemblyManifestImport
  28. {
  29. AssemblyIdentity GetAssemblyIdentity();
  30. DependentFileInfo GetNextDependentFileInfo();
  31. DependentAssemblyInfo GetNextDependentAssemblyInfo();
  32. void ResetIterators();
  33. FileType GetFileType();
  34. }
  35. //----------------------------------------------------------
  36. // ApplicationManifestImport
  37. //----------------------------------------------------------
  38. public class ApplicationManifestImport : IAssemblyManifestImport
  39. {
  40. XmlDocument _xmlDocument;
  41. XPathNodeIterator _xPathFileIterator;
  42. XPathNodeIterator _xPathAssemblyIterator;
  43. AssemblyIdentity _assemblyIdentity;
  44. Uri _manifestUri;
  45. //----------------------------------------------------------
  46. // ctor
  47. //----------------------------------------------------------
  48. public ApplicationManifestImport(Uri manifestUri)
  49. {
  50. _manifestUri = manifestUri;
  51. _xmlDocument = new XmlDocument();
  52. _xmlDocument.Load(_manifestUri.ToString());
  53. _assemblyIdentity = GetAssemblyIdentity();
  54. _xPathFileIterator = null;
  55. _xPathAssemblyIterator = null;
  56. }
  57. //----------------------------------------------------------
  58. // GetActivationInfo
  59. //----------------------------------------------------------
  60. public ActivationInfo GetActivationInfo()
  61. {
  62. XPathNavigator xPathNavigator = _xmlDocument.CreateNavigator();
  63. XPathNodeIterator xPathNodeIterator = xPathNavigator.Select ("/assembly/application/activation");
  64. if (xPathNodeIterator.MoveNext() == false)
  65. return null;
  66. ActivationInfo ai = new ActivationInfo();
  67. string assemblyName = xPathNodeIterator.Current.GetAttribute("assemblyName", "");
  68. string assemblyClass = xPathNodeIterator.Current.GetAttribute("assemblyClass", "");
  69. string assemblyMethod = xPathNodeIterator.Current.GetAttribute("assemblyMethod", "");
  70. string assemblyMethodArgs = xPathNodeIterator.Current.GetAttribute("assemblyMethodArgs", "");
  71. ai["assemblyName"] = assemblyName;
  72. ai["assemblyClass"] = assemblyClass;
  73. ai["assemblyMethod"] = assemblyMethod;
  74. ai["assemblyMethodArgs"] = assemblyMethodArgs;
  75. return ai;
  76. }
  77. //----------------------------------------------------------
  78. // GetAssemblyIdentity
  79. //----------------------------------------------------------
  80. public AssemblyIdentity GetAssemblyIdentity()
  81. {
  82. if (_assemblyIdentity != null)
  83. goto exit;
  84. XPathNavigator myXPathNavigator = _xmlDocument.CreateNavigator();
  85. XPathNodeIterator myXPathNodeIterator = myXPathNavigator.Select ("/assembly/assemblyIdentity");
  86. myXPathNodeIterator.MoveNext();
  87. _assemblyIdentity = XMLToAssemblyId(myXPathNodeIterator);
  88. exit:
  89. return _assemblyIdentity;
  90. }
  91. //----------------------------------------------------------
  92. // GetNextDependentFileInfo
  93. //----------------------------------------------------------
  94. public DependentFileInfo GetNextDependentFileInfo()
  95. {
  96. if (_xPathFileIterator == null)
  97. {
  98. XPathNavigator myXPathNavigator = _xmlDocument.CreateNavigator();
  99. _xPathFileIterator = myXPathNavigator.Select ("/assembly/file");
  100. }
  101. if (_xPathFileIterator.MoveNext() == false)
  102. return null;
  103. DependentFileInfo dfi = new DependentFileInfo();
  104. dfi["name"] = _xPathFileIterator.Current.GetAttribute("name", "");
  105. dfi["hash"] = _xPathFileIterator.Current.GetAttribute("hash", "");
  106. return dfi;
  107. }
  108. //----------------------------------------------------------
  109. // GetNextDependentAssemblyInfo
  110. //----------------------------------------------------------
  111. public DependentAssemblyInfo GetNextDependentAssemblyInfo()
  112. {
  113. if (_xPathAssemblyIterator == null)
  114. {
  115. XPathNavigator myXPathNavigator = _xmlDocument.CreateNavigator();
  116. _xPathAssemblyIterator = myXPathNavigator.Select ("/assembly/dependency/dependentAssembly");
  117. }
  118. if (_xPathAssemblyIterator.MoveNext() == false)
  119. return null;
  120. XPathNodeIterator asmIter = _xPathAssemblyIterator.Current.Select("assemblyIdentity");
  121. asmIter.MoveNext();
  122. DependentAssemblyInfo dai = new DependentAssemblyInfo();
  123. dai.assemblyIdentity = XMLToAssemblyId(asmIter);
  124. XPathNodeIterator installIter = _xPathAssemblyIterator.Current.Select("install");
  125. installIter.MoveNext();
  126. dai["codeBase"] = installIter.Current.GetAttribute("codebase", "");
  127. return dai;
  128. }
  129. //----------------------------------------------------------
  130. // XMLToAssemblyId
  131. //----------------------------------------------------------
  132. private AssemblyIdentity XMLToAssemblyId(XPathNodeIterator xPathNodeIterator)
  133. {
  134. AssemblyIdentity assemblyIdentity = new AssemblyIdentity();
  135. assemblyIdentity["name"] =xPathNodeIterator.Current.GetAttribute("name", "");
  136. assemblyIdentity["version"] =xPathNodeIterator.Current.GetAttribute("version", "");
  137. assemblyIdentity["processorArchitecture"] =xPathNodeIterator.Current.GetAttribute("processorArchitecture", "");
  138. assemblyIdentity["publicKeyToken"] =xPathNodeIterator.Current.GetAttribute("publicKeyToken", "");
  139. assemblyIdentity["language"] =xPathNodeIterator.Current.GetAttribute("language", "");
  140. return assemblyIdentity;
  141. }
  142. //----------------------------------------------------------
  143. // ResetIterators
  144. //----------------------------------------------------------
  145. public void ResetIterators()
  146. {
  147. _xPathAssemblyIterator = null;
  148. _xPathFileIterator = null;
  149. }
  150. //----------------------------------------------------------
  151. // GetFileType()
  152. //----------------------------------------------------------
  153. public FileType GetFileType()
  154. {
  155. return FileType.ApplicationManifest;
  156. }
  157. //----------------------------------------------------------
  158. // GetSecurityInfo
  159. //----------------------------------------------------------
  160. public SecurityInfo GetSecurityInfo()
  161. {
  162. XPathNavigator xPathNavigator = _xmlDocument.CreateNavigator();
  163. XPathNodeIterator xPathNodeIterator = xPathNavigator.Select ("/assembly/Security");
  164. if (xPathNodeIterator.MoveNext() == false)
  165. return null;
  166. SecurityInfo si = new SecurityInfo();
  167. XPathNavigator xp = xPathNodeIterator.Current;
  168. // XmlNode xmlNode = ((IHasXmlNode) xp).GetNode();
  169. XmlNode xmlNode = ((IHasXmlNode) xp).GetNode();
  170. si["Security"] = xmlNode.OuterXml;
  171. return si;
  172. }
  173. }
  174. //----------------------------------------------------------
  175. // AssemblyIdentity
  176. //----------------------------------------------------------
  177. public class AssemblyIdentity : Hashtable
  178. {
  179. public string GetDirectoryName()
  180. {
  181. string pa = (string) this["processorArchitecture"];
  182. string name = (string) this["name"];
  183. string version = (string) this["version"];
  184. string pkt = (string) this["publicKeyToken"];
  185. string lan = (string) this["language"];
  186. string appDirName = pa + '_' + name + '_' + version + '_' + pkt + '_' + lan;
  187. return appDirName;
  188. }
  189. }
  190. //----------------------------------------------------------
  191. // StringTable
  192. //----------------------------------------------------------
  193. public class StringTable : Hashtable
  194. {
  195. public string this [string index]
  196. {
  197. get { return (string) this[(object) index]; }
  198. set { this[(object) index] = value; }
  199. }
  200. }
  201. //----------------------------------------------------------
  202. // DependentFileInfo
  203. //----------------------------------------------------------
  204. public class DependentFileInfo : StringTable
  205. { }
  206. //----------------------------------------------------------
  207. // DependentAssemblyInfo
  208. //----------------------------------------------------------
  209. public class DependentAssemblyInfo : StringTable
  210. {
  211. public AssemblyIdentity assemblyIdentity;
  212. }
  213. //----------------------------------------------------------
  214. // ActivationInfo
  215. //----------------------------------------------------------
  216. public class ActivationInfo : StringTable
  217. {}
  218. public class SecurityInfo : StringTable
  219. {}
  220. }