예제 #1
0
 private AssemblyDefinition GetAssemblyInNetGac(AssemblyNameReference reference, ReaderParameters parameters)
 {
     string[] array = new string[]
     {
         "GAC_MSIL",
         "GAC_32",
         "GAC_64",
         "GAC"
     };
     string[] array2 = new string[]
     {
         string.Empty,
         "v4.0_"
     };
     for (int i = 0; i < 2; i++)
     {
         for (int j = 0; j < array.Length; j++)
         {
             string text         = Path.Combine(this.gac_paths[i], array[j]);
             string assemblyFile = BaseAssemblyResolver.GetAssemblyFile(reference, array2[i], text);
             if (Directory.Exists(text) && File.Exists(assemblyFile))
             {
                 return(this.GetAssembly(assemblyFile, parameters));
             }
         }
     }
     return(null);
 }
예제 #2
0
        private static Collection <string> GetDefaultMonoGacPaths()
        {
            Collection <string> collection = new Collection <string>(1);
            string currentMonoGac          = BaseAssemblyResolver.GetCurrentMonoGac();

            if (currentMonoGac != null)
            {
                collection.Add(currentMonoGac);
            }
            string environmentVariable = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX");

            if (string.IsNullOrEmpty(environmentVariable))
            {
                return(collection);
            }
            string[] array = environmentVariable.Split(new char[]
            {
                Path.PathSeparator
            });
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text = array2[i];
                if (!string.IsNullOrEmpty(text))
                {
                    string text2 = Path.Combine(Path.Combine(Path.Combine(text, "lib"), "mono"), "gac");
                    if (Directory.Exists(text2) && !collection.Contains(currentMonoGac))
                    {
                        collection.Add(text2);
                    }
                }
            }
            return(collection);
        }
예제 #3
0
 private AssemblyDefinition GetAssemblyInMonoGac(AssemblyNameReference reference, ReaderParameters parameters)
 {
     for (int i = 0; i < this.gac_paths.Count; i++)
     {
         string gac          = this.gac_paths[i];
         string assemblyFile = BaseAssemblyResolver.GetAssemblyFile(reference, string.Empty, gac);
         if (File.Exists(assemblyFile))
         {
             return(this.GetAssembly(assemblyFile, parameters));
         }
     }
     return(null);
 }
예제 #4
0
 private AssemblyDefinition GetAssemblyInGac(AssemblyNameReference reference, ReaderParameters parameters)
 {
     if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0)
     {
         return(null);
     }
     if (this.gac_paths == null)
     {
         this.gac_paths = BaseAssemblyResolver.GetGacPaths();
     }
     if (BaseAssemblyResolver.on_mono)
     {
         return(this.GetAssemblyInMonoGac(reference, parameters));
     }
     return(this.GetAssemblyInNetGac(reference, parameters));
 }
예제 #5
0
        private static Collection <string> GetGacPaths()
        {
            if (BaseAssemblyResolver.on_mono)
            {
                return(BaseAssemblyResolver.GetDefaultMonoGacPaths());
            }
            Collection <string> collection = new Collection <string>(2);
            string environmentVariable     = Environment.GetEnvironmentVariable("WINDIR");

            if (environmentVariable == null)
            {
                return(collection);
            }
            collection.Add(Path.Combine(environmentVariable, "assembly"));
            collection.Add(Path.Combine(environmentVariable, Path.Combine("Microsoft.NET", "assembly")));
            return(collection);
        }
예제 #6
0
        public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (parameters == null)
            {
                parameters = new ReaderParameters();
            }
            AssemblyDefinition assemblyDefinition = this.SearchDirectory(name, this.directories, parameters);

            if (assemblyDefinition != null)
            {
                return(assemblyDefinition);
            }
            if (name.IsRetargetable)
            {
                name = new AssemblyNameReference(name.Name, Mixin.ZeroVersion)
                {
                    PublicKeyToken = Empty <byte> .Array
                };
            }
            string directoryName = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName);

            if (BaseAssemblyResolver.IsZero(name.Version))
            {
                assemblyDefinition = this.SearchDirectory(name, new string[]
                {
                    directoryName
                }, parameters);
                if (assemblyDefinition != null)
                {
                    return(assemblyDefinition);
                }
            }
            if (name.Name == "mscorlib")
            {
                assemblyDefinition = this.GetCorlib(name, parameters);
                if (assemblyDefinition != null)
                {
                    return(assemblyDefinition);
                }
            }
            assemblyDefinition = this.GetAssemblyInGac(name, parameters);
            if (assemblyDefinition != null)
            {
                return(assemblyDefinition);
            }
            assemblyDefinition = this.SearchDirectory(name, new string[]
            {
                directoryName
            }, parameters);
            if (assemblyDefinition != null)
            {
                return(assemblyDefinition);
            }
            if (this.ResolveFailure != null)
            {
                assemblyDefinition = this.ResolveFailure(this, name);
                if (assemblyDefinition != null)
                {
                    return(assemblyDefinition);
                }
            }
            throw new AssemblyResolutionException(name);
        }
예제 #7
0
        private AssemblyDefinition GetCorlib(AssemblyNameReference reference, ReaderParameters parameters)
        {
            Version      version = reference.Version;
            AssemblyName name    = typeof(object).Assembly.GetName();

            if (name.Version == version || BaseAssemblyResolver.IsZero(version))
            {
                return(this.GetAssembly(typeof(object).Module.FullyQualifiedName, parameters));
            }
            string path = Directory.GetParent(Directory.GetParent(typeof(object).Module.FullyQualifiedName).FullName).FullName;

            if (!BaseAssemblyResolver.on_mono)
            {
                switch (version.Major)
                {
                case 1:
                    if (version.MajorRevision == 3300)
                    {
                        path = Path.Combine(path, "v1.0.3705");
                        goto IL_170;
                    }
                    path = Path.Combine(path, "v1.0.5000.0");
                    goto IL_170;

                case 2:
                    path = Path.Combine(path, "v2.0.50727");
                    goto IL_170;

                case 4:
                    path = Path.Combine(path, "v4.0.30319");
                    goto IL_170;
                }
                throw new NotSupportedException("Version not supported: " + version);
            }
            if (version.Major == 1)
            {
                path = Path.Combine(path, "1.0");
            }
            else
            {
                if (version.Major == 2)
                {
                    if (version.MajorRevision == 5)
                    {
                        path = Path.Combine(path, "2.1");
                    }
                    else
                    {
                        path = Path.Combine(path, "2.0");
                    }
                }
                else
                {
                    if (version.Major != 4)
                    {
                        throw new NotSupportedException("Version not supported: " + version);
                    }
                    path = Path.Combine(path, "4.0");
                }
            }
IL_170:
            string text = Path.Combine(path, "mscorlib.dll");

            if (File.Exists(text))
            {
                return(this.GetAssembly(text, parameters));
            }
            return(null);
        }