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.

44 lines
1.7 KiB

  1. using System;
  2. using System.IO;
  3. using FusionADF;
  4. namespace Microsoft.Fusion.ADF
  5. {
  6. public class DefaultAssemblyManifestImporter
  7. {
  8. public static IAssemblyManifestImport GetAssemblyManifestImport(string fileName)
  9. {
  10. DefaultAssemblyManifestImport retVal = null;
  11. AssemblyManifestParser amp = new AssemblyManifestParser();
  12. string fullPath = Path.GetFullPath(fileName);
  13. if(!File.Exists(fileName)) throw new FileNotFoundException("The path " + fullPath + " does not refer to a file.");
  14. else
  15. {
  16. bool checkInit = amp.InitFromFile(fileName);
  17. if(checkInit)
  18. {
  19. AssemblyIdentity impAssmID = amp.GetAssemblyIdentity();
  20. int numDepAssms = amp.GetNumDependentAssemblies();
  21. DependentAssemblyInfo[] impDepAssmInfoArr = new DependentAssemblyInfo[numDepAssms];
  22. for(int i = 0; i < numDepAssms; i++)
  23. {
  24. impDepAssmInfoArr[i] = amp.GetDependentAssemblyInfo(i);
  25. if(impDepAssmInfoArr[i] == null) throw new BadImageFormatException("Cannot access dependent assembly information from " + fullPath);
  26. }
  27. int numDepFiles = amp.GetNumDependentFiles();
  28. DependentFileInfo[] impDepFileInfoArr = new DependentFileInfo[numDepFiles];
  29. for(int i = 0; i < numDepFiles; i++)
  30. {
  31. impDepFileInfoArr[i] = amp.GetDependentFileInfo(i);
  32. if(impDepFileInfoArr[i] == null) throw new BadImageFormatException("Cannot access dependent file information from " + fullPath);
  33. }
  34. retVal = new DefaultAssemblyManifestImport(impAssmID, impDepAssmInfoArr, impDepFileInfoArr);
  35. }
  36. else throw new BadImageFormatException("The file " + fullPath + " is not an assembly.");
  37. }
  38. return retVal;
  39. }
  40. }
  41. }