Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
        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[] dotNetCorePaths;
                if (dotNetCoreAppVersion != null)
                {
                    bitness         = sourceModule.GetPointerSize(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 (sourceModuleLocationExists)
                {
                    document = TryLoadFromDir(asmName, exactCheck: false, dirPath: sourceModuleDir);
                    if (document != null)
                    {
                        return(document);
                    }
                }
                if (dotNetCorePaths != null)
                {
                    foreach (var path in dotNetCorePaths)
                    {
                        document = TryLoadFromDir(asmName, exactCheck: false, dirPath: path);
                        if (document != null)
                        {
                            return(document);
                        }
                    }
                }
            }

            return(null);
        }