IEnumerable <ModuleDef> LoadSourceModules() { var ev = Fire(new NetfuserEvent.LoadSourceModules(this)); if (ev.Sources.Count == 0) { throw Error("at least one source module must be added"); } var rejected = new HashSet <ModuleDef>(); foreach (var source in ev.Sources) { if (source.EntryPoint != null && !rejected.Contains(source)) { var evm = Fire(new NetfuserEvent.SelectMainModule(this, source) { IsMain = true }); if (evm.IsMain) { _mainSourceModule = source; break; } rejected.Add(source); } } if (_mainSourceModule == null) { foreach (var source in ev.Sources) { if (!rejected.Contains(source)) { var evm = Fire(new NetfuserEvent.SelectMainModule(this, source)); if (evm.IsMain) { _mainSourceModule = source; break; } rejected.Add(source); } } } if (_mainSourceModule != null) { _mainSourceModule.Assembly.TryGetOriginalTargetFrameworkAttribute(out var fw, out var ver, out _); if (fw == ".NETCoreApp") { _defaultAssemblyResolver.UseGAC = false; _defaultAssemblyResolver.EnableFrameworkRedirect = false; var bitness = (_mainSourceModule?.GetPointerSize(IntPtr.Size) ?? IntPtr.Size) * 8; var dotNetCorePaths = new DotNetCorePathProvider().TryGetDotNetCorePaths(ver, bitness); _defaultAssemblyResolver.PreSearchPaths.AddRange(dotNetCorePaths); } } return(ev.Sources); }
IDsDocument LookupFromSearchPaths(IAssembly asmName, ModuleDef sourceModule, Version dotNetCoreAppVersion) { IDsDocument document; if (sourceModule != null) { var sourceModuleLocationExists = File.Exists(sourceModule.Location); string sourceModuleDir = sourceModuleLocationExists ? Path.GetDirectoryName(sourceModule.Location) : null; if (sourceModuleLocationExists) { document = TryFindFromDir(asmName, dirPath: sourceModuleDir); if (document != null) { return(document); } } int bitness; string dotNetCorePath; if (dotNetCoreAppVersion != null) { bitness = sourceModule.GetPointerSize(IntPtr.Size) * 8; dotNetCorePath = dotNetCorePaths.TryGetDotNetCorePath(dotNetCoreAppVersion, bitness); } else { bitness = -1; dotNetCorePath = null; } if (dotNetCorePath != null) { document = TryFindFromDir(asmName, dirPath: dotNetCorePath); if (document != null) { return(document); } } if (sourceModuleLocationExists) { document = TryLoadFromDir(asmName, exactCheck: false, dirPath: sourceModuleDir); if (document != null) { return(document); } } if (dotNetCorePath != null) { document = TryLoadFromDir(asmName, exactCheck: false, dirPath: dotNetCorePath); if (document != null) { return(document); } } } return(null); }
IDsDocument LookupFromSearchPaths(IAssembly asmName, ModuleDef sourceModule, string sourceModuleDir, Version dotNetCoreAppVersion) { IDsDocument document; if (sourceModuleDir == null && sourceModule != null && !string.IsNullOrEmpty(sourceModule.Location)) { try { sourceModuleDir = Path.GetDirectoryName(sourceModule.Location); } catch (ArgumentException) { } catch (PathTooLongException) { } } if (sourceModuleDir != null) { document = TryFindFromDir(asmName, dirPath: sourceModuleDir); if (document != null) return document; } int bitness; string[] dotNetCorePaths; if (dotNetCoreAppVersion != null) { bitness = (sourceModule?.GetPointerSize(IntPtr.Size) ?? IntPtr.Size) * 8; dotNetCorePaths = dotNetCorePathProvider.TryGetDotNetCorePaths(dotNetCoreAppVersion, bitness); } else { bitness = -1; dotNetCorePaths = null; } if (dotNetCorePaths != null) { foreach (var path in dotNetCorePaths) { document = TryFindFromDir(asmName, dirPath: path); if (document != null) return document; } } if (sourceModuleDir != null) { document = TryLoadFromDir(asmName, checkVersion: false, checkPublicKeyToken: false, dirPath: sourceModuleDir); if (document != null) return document; } if (dotNetCorePaths != null) { foreach (var path in dotNetCorePaths) { document = TryLoadFromDir(asmName, checkVersion: false, checkPublicKeyToken: false, dirPath: path); if (document != null) return document; } } return null; }
internal static ServerClrVersion GetServerClrVersion(ModuleDef module) { switch (module.GetPointerSize()) { default: case 4: if (module.IsClr40) return ServerClrVersion.CLR_v40_x86; return ServerClrVersion.CLR_v20_x86; case 8: if (module.IsClr40) return ServerClrVersion.CLR_v40_x64; return ServerClrVersion.CLR_v20_x64; } }
public static ServerClrVersion GetServerClrVersion(ModuleDef module) { switch (module.GetPointerSize()) { default: case 4: if (module.IsClr40) { return(ServerClrVersion.CLR_v40_x86); } return(ServerClrVersion.CLR_v20_x86); case 8: if (module.IsClr40) { return(ServerClrVersion.CLR_v40_x64); } return(ServerClrVersion.CLR_v20_x64); } }