From f652c4e8decb97a3d79dd35e10833ec005337623 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Sat, 23 Apr 2016 13:10:54 +0200 Subject: [PATCH] Added DependencyFinder tool --- .../DependencyFinder/DependencyFinder.csproj | 56 ++++++++++++++++ .../DependencyFinder/DependencyFinder.sln | 17 +++++ BuildTools/DependencyFinder/Program.cs | 64 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 27 ++++++++ BuildTools/DependencyFinder/packages.config | 4 ++ 5 files changed, 168 insertions(+) create mode 100644 BuildTools/DependencyFinder/DependencyFinder.csproj create mode 100644 BuildTools/DependencyFinder/DependencyFinder.sln create mode 100644 BuildTools/DependencyFinder/Program.cs create mode 100644 BuildTools/DependencyFinder/Properties/AssemblyInfo.cs create mode 100644 BuildTools/DependencyFinder/packages.config diff --git a/BuildTools/DependencyFinder/DependencyFinder.csproj b/BuildTools/DependencyFinder/DependencyFinder.csproj new file mode 100644 index 000000000..db9645ffb --- /dev/null +++ b/BuildTools/DependencyFinder/DependencyFinder.csproj @@ -0,0 +1,56 @@ + + + + Debug + x86 + {3E891818-579A-4C06-8066-4C702BFA5921} + Exe + DependencyFinder + DependencyFinder + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + false + ../../../../Duplicati/GUI/Duplicati.GUI.TrayIcon/bin/Debug + + + full + true + bin\Release + prompt + 4 + true + x86 + + + + + packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll + + + packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll + + + packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll + + + packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll + + + + + + + + + + + \ No newline at end of file diff --git a/BuildTools/DependencyFinder/DependencyFinder.sln b/BuildTools/DependencyFinder/DependencyFinder.sln new file mode 100644 index 000000000..cd8aea67c --- /dev/null +++ b/BuildTools/DependencyFinder/DependencyFinder.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyFinder", "DependencyFinder.csproj", "{3E891818-579A-4C06-8066-4C702BFA5921}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3E891818-579A-4C06-8066-4C702BFA5921}.Debug|x86.ActiveCfg = Debug|x86 + {3E891818-579A-4C06-8066-4C702BFA5921}.Debug|x86.Build.0 = Debug|x86 + {3E891818-579A-4C06-8066-4C702BFA5921}.Release|x86.ActiveCfg = Release|x86 + {3E891818-579A-4C06-8066-4C702BFA5921}.Release|x86.Build.0 = Release|x86 + EndGlobalSection +EndGlobal diff --git a/BuildTools/DependencyFinder/Program.cs b/BuildTools/DependencyFinder/Program.cs new file mode 100644 index 000000000..e819cac0b --- /dev/null +++ b/BuildTools/DependencyFinder/Program.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using Mono.Cecil; +using System.IO; +using System.Linq; + +namespace DependencyFinder +{ + class MainClass + { + public static void Main(string[] args) + { + var lst = + Directory.EnumerateFiles(args[0], "*.exe", SearchOption.AllDirectories).Union( + Directory.EnumerateFiles(args[0], "*.dll", SearchOption.AllDirectories)) + .Select(x => { + try { return AssemblyDefinition.ReadAssembly(x); } + catch { return null; } + }).Where(x => x != null) + .Distinct(); + + PoC(lst, Console.Out, new [] { args[0] }); + + } + + //Adapted from: https://stackoverflow.com/questions/9262464/tool-to-show-assembly-dependencies + public static void PoC(IEnumerable assemblies, TextWriter writer, IEnumerable searchfolders) + { + var resolver = new DefaultAssemblyResolver(); + searchfolders.ToList().ForEach(x => resolver.AddSearchDirectory(x)); + + //writer.WriteLine("digraph Dependencies {"); + var loaded = assemblies + .SelectMany(a => a.Modules.Cast()) + .SelectMany(m => m.AssemblyReferences.Cast()) + .Distinct() + .Select(asm => { + var dllname = asm.Name + ".dll"; + //Console.WriteLine("Probing for {0}", dllname); + try { return AssemblyDefinition.ReadAssembly(dllname); } + catch { } + try { return resolver.Resolve(asm.FullName); } + catch { } + + return null; + }) + .Where(assembly => assembly != null) + .ToList(); + + //loaded.ForEach(a => a.MainModule.ReadSymbols()); + + loaded.Select(x => x.FullName).Distinct().OrderBy(x => x).ToList().ForEach(x => writer.WriteLine("{0}", x)); + /*loaded.ForEach(a => + { + foreach (var r in a.MainModule.AssemblyReferences.Cast()) + writer.WriteLine(@"""{0}"" -> ""{1}"";", r.Name, a.Name.Name); + } );*/ + + //writer.WriteLine("}"); + } + + + } +} diff --git a/BuildTools/DependencyFinder/Properties/AssemblyInfo.cs b/BuildTools/DependencyFinder/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..637ec8aad --- /dev/null +++ b/BuildTools/DependencyFinder/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("DependencyFinder")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("kenneth")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/BuildTools/DependencyFinder/packages.config b/BuildTools/DependencyFinder/packages.config new file mode 100644 index 000000000..e304cab94 --- /dev/null +++ b/BuildTools/DependencyFinder/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file