From 2a0e92eaff32752e1654e5a364aca24cba47c4d0 Mon Sep 17 00:00:00 2001 From: de4dot Date: Thu, 15 Dec 2011 16:28:27 +0100 Subject: [PATCH] Assembly resolver now parses *.config files --- de4dot.code/AssemblyResolver.cs | 32 +++++++++++++++++++++++++++++++- de4dot.code/de4dot.code.csproj | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/de4dot.code/AssemblyResolver.cs b/de4dot.code/AssemblyResolver.cs index 68816726..938158a0 100644 --- a/de4dot.code/AssemblyResolver.cs +++ b/de4dot.code/AssemblyResolver.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; +using System.Xml; using Mono.Cecil; namespace de4dot.code { @@ -87,8 +88,11 @@ namespace de4dot.code { } public void addModule(ModuleDefinition module) { - if (module.FullyQualifiedName != "") + if (module.FullyQualifiedName != "") { addSearchDirectory(Path.GetDirectoryName(module.FullyQualifiedName)); + if (module.FullyQualifiedName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) + addConfigFile(module.FullyQualifiedName + ".config"); + } var assembly = module.Assembly; if (assembly != null) { @@ -100,6 +104,32 @@ namespace de4dot.code { } } + void addConfigFile(string configFilename) { + var dirName = Utils.getDirName(Utils.getFullPath(configFilename)); + addSearchDirectory(dirName); + + try { + using (var xmlStream = new FileStream(configFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) { + var doc = new XmlDocument(); + doc.Load(XmlReader.Create(xmlStream)); + foreach (var tmp in doc.GetElementsByTagName("probing")) { + var probingElem = tmp as XmlElement; + if (probingElem == null) + continue; + var privatePath = probingElem.GetAttribute("privatePath"); + if (string.IsNullOrEmpty(privatePath)) + continue; + foreach (var path in privatePath.Split(';')) + addSearchDirectory(Path.Combine(dirName, path)); + } + } + } + catch (IOException) { + } + catch (XmlException) { + } + } + public void removeModule(ModuleDefinition module) { var assembly = module.Assembly; if (assembly == null) diff --git a/de4dot.code/de4dot.code.csproj b/de4dot.code/de4dot.code.csproj index bb21bbb5..ab199156 100644 --- a/de4dot.code/de4dot.code.csproj +++ b/de4dot.code/de4dot.code.csproj @@ -45,6 +45,7 @@ +