Esempio n. 1
0
        public WeaverHelper(string assemblyToProcess)
        {
            var assemblyFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            BeforeAssemblyPath = Path.Combine(assemblyFolder, assemblyToProcess);
            AfterAssemblyPath  = BeforeAssemblyPath.Replace(".dll", "2.dll");

            var moduleDefinition = ModuleDefinition.ReadModule(BeforeAssemblyPath);
            var weavingTask      = new ModuleWeaver
            {
                ModuleDefinition = moduleDefinition,
                LogDebug         = s => System.Diagnostics.Debug.WriteLine(s, "Debug"),
                LogInfo          = s => System.Diagnostics.Debug.WriteLine(s, "Info"),
                LogWarning       = s => System.Diagnostics.Debug.WriteLine(s, "Warning"),
                LogError         = s => System.Diagnostics.Debug.WriteLine(s, "Error"),
            };

            weavingTask.Execute();

            moduleDefinition.Write(AfterAssemblyPath);

            //ProvideIlStepThrough(AfterAssemblyPath);

            Assembly = Assembly.LoadFile(AfterAssemblyPath);
        }
Esempio n. 2
0
    static AssemblyWeaver()
    {
        TestListener = new TestTraceListener();

        Debug.Listeners.Clear();
        Debug.Listeners.Add(TestListener);

        BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll");
        var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb");

#if (!DEBUG)
        BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release");
        beforePdbPath      = beforePdbPath.Replace("Debug", "Release");
#endif
        AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll");
        var afterPdbPath = beforePdbPath.Replace(".pdb", "2.pdb");

        File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true);
        if (File.Exists(beforePdbPath))
        {
            File.Copy(beforePdbPath, afterPdbPath, true);
        }

        var assemblyResolver = new MockAssemblyResolver();
        var readerParameters = new ReaderParameters();
        var writerParameters = new WriterParameters();

        if (File.Exists(afterPdbPath))
        {
            readerParameters.ReadSymbols  = true;
            writerParameters.WriteSymbols = true;
        }

        var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters);

        var weavingTask = new ModuleWeaver
        {
            ModuleDefinition = moduleDefinition,
            AssemblyResolver = assemblyResolver,
            LogError         = LogError,
            DefineConstants  = new List <string> {
                "DEBUG"
            }                                              // Always testing the debug weaver
        };

        weavingTask.Execute();
        moduleDefinition.Write(AfterAssemblyPath, writerParameters);

        Assembly = Assembly.LoadFile(AfterAssemblyPath);
    }
    static AssemblyWeaver()
    {
        BeforeAssemblyPath = Path.GetFullPath(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll");
        var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb");

#if (!DEBUG)
        BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release");
        beforePdbPath      = beforePdbPath.Replace("Debug", "Release");
#endif
        AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll");
        var afterPdbPath = beforePdbPath.Replace(".pdb", "2.pdb");

        File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true);
        if (File.Exists(beforePdbPath))
        {
            File.Copy(beforePdbPath, afterPdbPath, true);
        }

        var assemblyResolver = new MockAssemblyResolver();
        var readerParameters = new ReaderParameters();
        var writerParameters = new WriterParameters();

        if (File.Exists(afterPdbPath))
        {
            readerParameters.ReadSymbols  = true;
            writerParameters.WriteSymbols = true;
        }

        var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters);

        var weavingTask = new ModuleWeaver
        {
            ModuleDefinition = moduleDefinition,
            AssemblyResolver = assemblyResolver,
            LogInfo          = LogInfo,
            LogWarning       = LogWarning,
            LogError         = LogError,
            DefineConstants  = new[] { "DEBUG" }, // Always testing the debug weaver
            Config           = XElement.Parse("<Disguise EncryptStrings=\"Xor\" RenameMethod=\"Readable\" />")
        };

        weavingTask.Execute();
        moduleDefinition.Write(AfterAssemblyPath, writerParameters);

        Assembly = Assembly.LoadFile(AfterAssemblyPath);
    }
Esempio n. 4
0
    static AssemblyWeaver()
    {
        BeforeAssemblyPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"));
        var beforePdbPath = Path.ChangeExtension(BeforeAssemblyPath, "pdb");

#if (!DEBUG)
        BeforeAssemblyPath = BeforeAssemblyPath.Replace("Debug", "Release");
        beforePdbPath      = beforePdbPath.Replace("Debug", "Release");
#endif
        AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll");
        var afterPdbPath = beforePdbPath.Replace(".pdb", "2.pdb");

        File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true);
        if (File.Exists(beforePdbPath))
        {
            File.Copy(beforePdbPath, afterPdbPath, true);
        }

        var readerParameters = new ReaderParameters();
        var writerParameters = new WriterParameters();

        if (File.Exists(afterPdbPath))
        {
            readerParameters.ReadSymbols  = true;
            writerParameters.WriteSymbols = true;
        }

        using (var moduleDefinition = ModuleDefinition.ReadModule(BeforeAssemblyPath, readerParameters))
            using (var defaultAssemblyResolver = new DefaultAssemblyResolver())
            {
                var weavingTask = new ModuleWeaver
                {
                    ModuleDefinition = moduleDefinition,
                    AssemblyResolver = defaultAssemblyResolver,
                    LogInfo          = LogInfo,
                    LogWarning       = LogWarning,
                    LogError         = LogError,
                    DefineConstants  = new[] { "DEBUG" } // Always testing the debug weaver
                };

                weavingTask.Execute();
                moduleDefinition.Write(AfterAssemblyPath, writerParameters);
            }

        Assembly = Assembly.LoadFile(AfterAssemblyPath);
    }