public static ModuleDefinition ReadModule(string fileName, ReaderParameters parameters) { using (var stream = GetFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { return(ReadModule(stream, parameters)); } }
AssemblyDefinition SearchDirectory(AssemblyNameReference name, IEnumerable <string> directories, ReaderParameters parameters) { var extensions = new [] { ".exe", ".dll" }; foreach (var directory in directories) { foreach (var extension in extensions) { string file = Path.Combine(directory, name.Name + extension); if (File.Exists(file)) { return(GetAssembly(file, parameters)); } } } return(null); }
AssemblyDefinition GetCorlib(AssemblyNameReference reference, ReaderParameters parameters) { var version = reference.Version; var corlib = typeof(object).Assembly.GetName(); if (corlib.Version == version || IsZero(version)) { return(GetAssembly(typeof(object).Module.FullyQualifiedName, parameters)); } var path = Directory.GetParent( Directory.GetParent( typeof(object).Module.FullyQualifiedName).FullName ).FullName; if (on_mono) { 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) { path = Path.Combine(path, "4.0"); } else { throw new NotSupportedException("Version not supported: " + version); } } else { switch (version.Major) { case 1: if (version.MajorRevision == 3300) { path = Path.Combine(path, "v1.0.3705"); } else { path = Path.Combine(path, "v1.0.5000.0"); } break; case 2: path = Path.Combine(path, "v2.0.50727"); break; case 4: path = Path.Combine(path, "v4.0.30319"); break; default: throw new NotSupportedException("Version not supported: " + version); } } var file = Path.Combine(path, "mscorlib.dll"); if (File.Exists(file)) { return(GetAssembly(file, parameters)); } return(null); }
public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { if (name == null) { throw new ArgumentNullException("name"); } if (parameters == null) { parameters = new ReaderParameters(); } var assembly = SearchDirectory(name, directories, parameters); if (assembly != null) { return(assembly); } #if !SILVERLIGHT && !CF if (name.IsRetargetable) { // if the reference is retargetable, zero it name = new AssemblyNameReference(name.Name, new Version(0, 0, 0, 0)) { PublicKeyToken = Empty <byte> .Array, }; } var framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName); if (IsZero(name.Version)) { assembly = SearchDirectory(name, new [] { framework_dir }, parameters); if (assembly != null) { return(assembly); } } if (name.Name == "mscorlib") { assembly = GetCorlib(name, parameters); if (assembly != null) { return(assembly); } } assembly = GetAssemblyInGac(name, parameters); if (assembly != null) { return(assembly); } assembly = SearchDirectory(name, new [] { framework_dir }, parameters); if (assembly != null) { return(assembly); } #endif if (ResolveFailure != null) { assembly = ResolveFailure(this, name); if (assembly != null) { return(assembly); } } throw new AssemblyResolutionException(name); }