示例#1
0
        public void CheckSignAttribute()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='auto' />" +
                @"<Module file='$(InPath){2}AssemblyForSigning2.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            var assembly = Path.Combine(TestHelper.InputPath, "AssemblyForSigning2.dll");

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            if (!File.Exists(assembly))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "AssemblyForSigning2.dll"), assembly, true);
            }

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(assembly);

            Assert.True(inAssmDef.MainModule.Attributes.HasFlag(ModuleAttributes.StrongNameSigned));

            AssemblyDefinition outAssmDef =
                AssemblyDefinition.ReadAssembly(Path.Combine(outputPath, "AssemblyForSigning2.dll"));

            Assert.True(outAssmDef.MainModule.Attributes.HasFlag(ModuleAttributes.StrongNameSigned));
        }
示例#2
0
        public void CheckGeneric()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath)\..\dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Module file='$(InPath)\System.Windows.Controls.DataVisualization.Toolkit.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..\System.Windows.Controls.DataVisualization.Toolkit.dll"), Path.Combine(TestHelper.InputPath, "System.Windows.Controls.DataVisualization.Toolkit.dll"), true);
            File.Copy(Path.Combine(TestHelper.InputPath, @"..\WPFToolkit.dll"), Path.Combine(TestHelper.InputPath, "WPFToolkit.dll"), true);

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "System.Windows.Controls.DataVisualization.Toolkit.dll"));

            TypeDefinition classAType = inAssmDef.MainModule.GetType("System.Windows.Controls.DataVisualization.Charting.NullableConverter`1");
            var            type       = map.GetClass(new TypeKey(classAType));

            Assert.True(type.Status == ObfuscationStatus.Renamed, "Type should have been renamed.");
        }
示例#3
0
        public void CheckCannotObfuscateSigned()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='OptimizeMethods' value='false' />" +
                @"<Module file='$(InPath){2}WpfApplication1.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "WpfApplication1.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "WpfApplication1.dll"),
                          destFileName, true);
            }

            var obfuscator = TestHelper.Obfuscate(xml);

            Assert.False(obfuscator.Project.Settings.Optimize);
        }
        public void CheckCrossAssembly()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"								<Module file='$(InPath){2}AssemblyF.dll'>"+
                @"								</Module>"+
                @"								<Module file='$(InPath){2}AssemblyG.dll' />"+
                @"								</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            // Directory.Delete (TestHelper.OutputPath, true);
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "AssemblyG.dll"), Path.Combine(TestHelper.InputPath, "AssemblyG.dll"), true);
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "AssemblyF.dll"), Path.Combine(TestHelper.InputPath, "AssemblyF.dll"), true);

            var exception = Assert.Throws <ObfuscarException> (() => TestHelper.Obfuscate(xml));

            Assert.True(exception.Message.StartsWith("Inconsistent virtual method obfuscation"));

            Assert.False(File.Exists(Path.Combine(TestHelper.OutputPath, @"AssemblyG.dll")));
            Assert.False(File.Exists(Path.Combine(TestHelper.OutputPath, @"AssemblyF.dll")));
        }
示例#5
0
        // TODO: till Mono Cecil support overwriting.         [Fact]
        public void CheckOverwriting()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath)\..\dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Module file='$(InPath){2}WeifenLuo.WinFormsUI.Docking.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.InputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "WeifenLuo.WinFormsUI.Docking.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "WeifenLuo.WinFormsUI.Docking.dll"),
                          destFileName, true);
            }

            var map = TestHelper.Obfuscate(xml).Mapping;

            File.Delete(destFileName);
        }
示例#6
0
        public void CheckCannotObfuscateSigned( )
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Module file='$(InPath)\WpfApplication1.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath);

            TestHelper.CleanInput( );

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..\WpfApplication1.dll"), Path.Combine(TestHelper.InputPath, "WpfApplication1.dll"));

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "WpfApplication1.dll"));

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.OutputPath, "WpfApplication1.dll"));

            TypeDefinition classAType = inAssmDef.MainModule.GetType("WpfApplication1.MainWindow");
            var            obfuscated = map.GetClass(new TypeKey(classAType));

            Assert.IsTrue(obfuscated.Status == ObfuscationStatus.Skipped);
        }
示例#7
0
        public void CheckGeneric()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath)\..\dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Module file='$(InPath)\WindowsFormsApplication1.exe' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..\WindowsFormsApplication1.exe"),
                      Path.Combine(TestHelper.InputPath, "WindowsFormsApplication1.exe"), true);

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.OutputPath, "WindowsFormsApplication1.exe"));

            Assert.False(outAssmDef.MainModule.Resources.Any(item => item.Name == "WindowsFormsApplication1.Properties.Resources.resources"));
            Assert.False(outAssmDef.MainModule.Resources.Any(item => item.Name == "WindowsFormsApplication1.CustomForm.resources"));
            Assert.False(outAssmDef.MainModule.Resources.Any(item => item.Name == "WindowsFormsApplication1.CustomForm1.resources"));
            Assert.False(outAssmDef.MainModule.Resources.Any(item => item.Name == "WindowsFormsApplication1.Form1.resources"));
            Assert.False(outAssmDef.MainModule.Resources.Any(item => item.Name == "WindowsFormsApplication1.UserControl1.resources"));
        }
示例#8
0
        public void CheckGeneric()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath){2}..{2}dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Module file='$(InPath){2}DelaySigned.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();
            var assembly = Path.Combine(TestHelper.InputPath, "DelaySigned.dll");

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "DelaySigned.dll"), assembly, true);

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(assembly);

            Assert.False(inAssmDef.MainModule.Attributes.HasFlag(ModuleAttributes.StrongNameSigned));

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(Path.Combine(TestHelper.OutputPath, "DelaySigned.dll"));

            Assert.True(outAssmDef.MainModule.Attributes.HasFlag(ModuleAttributes.StrongNameSigned));
        }
示例#9
0
        public void CheckPortable()
        {
            string xml = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='HideStrings' value='false' />" +
                @"<Var name='KeyFile' value='$(InPath)\..\dockpanelsuite.snk' />" +
                @"<Module file='$(InPath)\SharpSnmpLib.Portable.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..\SharpSnmpLib.Portable.dll"), Path.Combine(TestHelper.InputPath, "SharpSnmpLib.Portable.dll"));

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "SharpSnmpLib.Portable.dll"));

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.OutputPath, "SharpSnmpLib.Portable.dll"));

            var corlibs = outAssmDef.MainModule.AssemblyReferences.Where(reference => reference.Name == "mscorlib");

            Assert.AreEqual(1, corlibs.Count());
            Assert.AreEqual("2.0.5.0", corlibs.First().Version.ToString());
        }
示例#10
0
        public void CheckNetStandard20()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='SuppressIldasm' value='false' />" +
                @"<Var name='HideStrings' value='false' />" +
                @"<Module file='$(InPath){2}NetStandard20.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "NetStandard20.dll"),
                      Path.Combine(TestHelper.InputPath, "NetStandard20.dll"), true);

            var map = TestHelper.Obfuscate(xml, true).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "NetStandard20.dll"));

            Assert.Equal(1, inAssmDef.MainModule.AssemblyReferences.Count);
            Assert.Equal("netstandard", inAssmDef.MainModule.AssemblyReferences[0].Name);

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(outputPath, "NetStandard20.dll"));

            Assert.Equal(1, outAssmDef.MainModule.AssemblyReferences.Count);
            Assert.Equal("netstandard", outAssmDef.MainModule.AssemblyReferences[0].Name);
        }
示例#11
0
        public void CheckGeneric()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath)\..\dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Module file='$(InPath){2}WeifenLuo.WinFormsUI.Docking.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "WeifenLuo.WinFormsUI.Docking.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "WeifenLuo.WinFormsUI.Docking.dll"),
                          destFileName, true);
            }

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "WeifenLuo.WinFormsUI.Docking.dll"));

            TypeDefinition classAType = inAssmDef.MainModule.GetType(
                "WeifenLuo.WinFormsUI.Docking.AutoHideStripBase/TabCollection/<System.Collections.Generic.IEnumerable<WeifenLuo.WinFormsUI.Docking.AutoHideStripBase.Tab>.GetEnumerator>d__0");
            var type = map.GetClass(new TypeKey(classAType));

            Assert.True(type.Status == ObfuscationStatus.Renamed, "Type should have been renamed.");
        }
示例#12
0
        public void CheckGeneric()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath){2}..{2}dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Module file='$(InPath){2}Microsoft.Practices.Unity.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "Microsoft.Practices.Unity.dll"),
                      Path.Combine(TestHelper.InputPath, "Microsoft.Practices.Unity.dll"), true);
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "Microsoft.Practices.ServiceLocation.dll"),
                      Path.Combine(TestHelper.InputPath, "Microsoft.Practices.ServiceLocation.dll"), true);

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "Microsoft.Practices.Unity.dll"));

            TypeDefinition classAType =
                inAssmDef.MainModule.GetType("Microsoft.Practices.ObjectBuilder2.PolicyListExtensions");
            var type = map.GetClass(new TypeKey(classAType));

            Assert.True(type.Status == ObfuscationStatus.Renamed, "Type should have been renamed.");

            var method1 = FindByFullName(classAType,
                                         "System.Void Microsoft.Practices.ObjectBuilder2.PolicyListExtensions::Clear(Microsoft.Practices.ObjectBuilder2.IPolicyList,System.Object)");
            var m1 = map.GetMethod(new MethodKey(method1));

            Assert.True(m1.Status == ObfuscationStatus.Renamed, "Instance method should have been renamed.");

            var classB = inAssmDef.MainModule.GetType("Microsoft.Practices.ObjectBuilder2.IPolicyList");
            var typeB  = map.GetClass(new TypeKey(classB));

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(outputPath, "Microsoft.Practices.Unity.dll"));

            var name       = type.StatusText.Substring(27);
            var obfuscated = outAssmDef.MainModule.GetType(name);
            var method2    = FindByFullName(obfuscated,
                                            "System.Void " + name + "::" + m1.StatusText + "(" + typeB.StatusText.Substring(27) +
                                            ",System.Object)");

            Assert.NotNull(method2);
            var first  = method2.Parameters[0].Name;
            var second = method2.Parameters[1].Name;

            Assert.Equal("", first);
            Assert.Equal("", second);
        }
示例#13
0
        public void CheckNetStandard()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Var name='HideStrings' value='true' />" +
                @"<Var name='KeyFile' value='$(InPath){2}SigningKey.snk' />" +
                @"<Module file='$(InPath){2}SharpSnmpLib.NetStandard.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "SharpSnmpLib.NetStandard.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "SharpSnmpLib.NetStandard.dll"),
                          destFileName, true);
            }


            string destFileName1 = Path.Combine(TestHelper.InputPath, "System.ComponentModel.TypeConverter.dll");

            if (!File.Exists(destFileName1))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "System.ComponentModel.TypeConverter.dll"),
                          destFileName1, true);
            }

            var map = TestHelper.Obfuscate(xml, true).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "SharpSnmpLib.NetStandard.dll"));

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(outputPath, "SharpSnmpLib.NetStandard.dll"));

            var corlibs = outAssmDef.MainModule.AssemblyReferences.Where(reference => reference.Name == "mscorlib");

            Assert.Empty(corlibs);

            var runtime =
                outAssmDef.MainModule.AssemblyReferences.Where(reference => reference.Name == "System.Runtime");

            Assert.Single(runtime);
            Assert.Equal("4.0.20.0", runtime.First().Version.ToString());
        }
示例#14
0
        public void CheckGeneric()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath){2}..{2}dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='OptimizeMethods' value='false' />" +
                @"<Module file='$(InPath){2}FSharp.Compiler.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "FSharp.Core.dll"),
                      Path.Combine(TestHelper.InputPath, "FSharp.Core.dll"), true);
            File.Copy(Path.Combine(TestHelper.InputPath, @"..", "FSharp.Compiler.dll"),
                      Path.Combine(TestHelper.InputPath, "FSharp.Compiler.dll"), true);

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "FSharp.Compiler.dll"));
            {
                TypeDefinition classAType =
                    inAssmDef.MainModule.GetType("Microsoft.FSharp.Compiler.AbstractIL.IL/ldargs@2513");
                var type = map.GetClass(new TypeKey(classAType));
                Assert.True(type.Status == ObfuscationStatus.Renamed, "Type should have been renamed.");

                var method1 = FindByFullName(classAType,
                                             "System.Int32 Microsoft.FSharp.Compiler.AbstractIL.IL/ldargs@2513::GenerateNext(System.Collections.Generic.IEnumerable`1<Microsoft.FSharp.Compiler.AbstractIL.IL/ILInstr>&)");
                var m1 = map.GetMethod(new MethodKey(method1));
                Assert.True(m1.Status == ObfuscationStatus.Skipped, "Instance method should have been skipped.");
                Assert.Equal(m1.StatusText, "external base class or interface");
            }

            {
                TypeDefinition classAType =
                    inAssmDef.MainModule.GetType("Microsoft.FSharp.Compiler.AbstractIL.IL/mkILMethods@2352");
                var type = map.GetClass(new TypeKey(classAType));
                Assert.True(type.Status == ObfuscationStatus.Renamed, "Type should have been renamed.");

                var method1 = FindByFullName(classAType,
                                             "System.Tuple`2<Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.AbstractIL.IL/ILMethodDef>,Microsoft.FSharp.Collections.FSharpMap`2<System.String,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.AbstractIL.IL/ILMethodDef>>> Microsoft.FSharp.Compiler.AbstractIL.IL/mkILMethods@2352::Invoke(Microsoft.FSharp.Compiler.AbstractIL.IL/ILMethodDef,System.Tuple`2<Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.AbstractIL.IL/ILMethodDef>,Microsoft.FSharp.Collections.FSharpMap`2<System.String,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.AbstractIL.IL/ILMethodDef>>>)");
                var m1 = map.GetMethod(new MethodKey(method1));
                Assert.True(m1.Status == ObfuscationStatus.Skipped, "Instance method should have been skipped.");
                Assert.Equal(m1.StatusText, "external base class or interface");
            }
        }
示例#15
0
        public void CheckGeneric()
        {
            string xml = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath){2}SigningKey.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Var name='AnalyzeXaml' value='true' />" +
                @"<Module file='$(InPath){2}System.Windows.Controls.DataVisualization.Toolkit.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "System.Windows.Controls.DataVisualization.Toolkit.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(
                    Path.Combine(TestHelper.InputPath, @"..", "System.Windows.Controls.DataVisualization.Toolkit.dll"),
                    destFileName, true);
            }

            string destFileName1 = Path.Combine(TestHelper.InputPath, "WPFToolkit.dll");

            if (!File.Exists(destFileName1))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "WPFToolkit.dll"),
                          destFileName1, true);
            }

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "System.Windows.Controls.DataVisualization.Toolkit.dll"));

            TypeDefinition classAType =
                inAssmDef.MainModule.GetType("System.Windows.Controls.DataVisualization.Charting.NullableConverter`1");
            var type = map.GetClass(new TypeKey(classAType));

            Assert.True(type.Status == ObfuscationStatus.Renamed, "Type should have been renamed.");

            TypeDefinition classBType = inAssmDef.MainModule.GetType("System.Windows.Controls.DataVisualization.Charting.AreaDataPoint");
            var            type2      = map.GetClass(new TypeKey(classBType));

            Assert.True(type2.Status == ObfuscationStatus.Skipped, "chart type should have been skipped");
            Assert.Equal("filtered by BAML", type2.StatusText);
        }
示例#16
0
        // [Fact] no longer valid due to Cecil changes
        public void CheckCanObfuscateDelaySigned()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Module file='$(InPath){2}AssemblyForSigning.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the delaysign option (embeds the public key, reserves space for the signature, but does not sign)
            TestHelper.BuildAssembly("AssemblyForSigning", String.Empty, "/delaysign /keyfile:" + Path.Combine(TestHelper.InputPath, @"SigningKey.snk"));

            // this should not throw
            TestHelper.Obfuscate(xml);
        }
示例#17
0
        public void CheckCannotObfuscateSigned( )
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Module file='$(InPath)\AssemblyForSigning.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath);

            TestHelper.CleanInput( );

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            TestHelper.BuildAssembly("AssemblyForSigning", String.Empty, "/keyfile:" + TestHelper.InputPath + @"\SigningKey.snk");

            TestUtils.AssertThrows(delegate { TestHelper.Obfuscate(xml); }, typeof(ApplicationException),
                                   "signed assembly", "invalid", "AssemblyForSigning");
        }
示例#18
0
        public void CheckCannotObfuscateSigned()
        {
            string xml = String.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Module file='$(InPath){2}AssemblyForSigning.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, TestHelper.OutputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            TestHelper.BuildAssembly("AssemblyForSigning", String.Empty, "/keyfile:" + Path.Combine(TestHelper.InputPath, @"SigningKey.snk"));
            var exception = Assert.Throws <ObfuscarException>(() => { TestHelper.Obfuscate(xml); });

            Assert.Equal("Obfuscating a signed assembly would result in an invalid assembly:  AssemblyForSigning; use the KeyFile property to set a key to use", exception.Message);
        }
示例#19
0
        public void CheckGeneric()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeyFile' value='$(InPath){2}..{2}dockpanelsuite.snk' />" +
                @"<Var name='HidePrivateApi' value='true' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Module file='$(InPath){2}WindowsFormsApplication1.exe' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "WindowsFormsApplication1.exe");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "WindowsFormsApplication1.exe"),
                          destFileName, true);
            }

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(outputPath, "WindowsFormsApplication1.exe"));

            Assert.DoesNotContain(outAssmDef.MainModule.Resources, item =>
                                  item.Name == "WindowsFormsApplication1.Properties.Resources.resources");
            Assert.DoesNotContain(outAssmDef.MainModule.Resources, item =>
                                  item.Name == "WindowsFormsApplication1.CustomForm.resources");
            Assert.DoesNotContain(outAssmDef.MainModule.Resources, item =>
                                  item.Name == "WindowsFormsApplication1.CustomForm1.resources");
            Assert.DoesNotContain(outAssmDef.MainModule.Resources, item =>
                                  item.Name == "WindowsFormsApplication1.Form1.resources");
            Assert.DoesNotContain(outAssmDef.MainModule.Resources, item =>
                                  item.Name == "WindowsFormsApplication1.UserControl1.resources");
        }
示例#20
0
        //TODO: debug into Cecil. [Fact]
        public void CheckNetStandard20()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='SuppressIldasm' value='false' />" +
                @"<Var name='HideStrings' value='false' />" +
                @"<AssemblySearchPath path='C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\' />" +
                @"<Module file='$(InPath){2}NetStandard20.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "NetStandard20.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "NetStandard20.dll"),
                          destFileName, true);
            }

            var map = TestHelper.Obfuscate(xml, true).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "NetStandard20.dll"));

            Assert.Single(inAssmDef.MainModule.AssemblyReferences);
            Assert.Equal("netstandard", inAssmDef.MainModule.AssemblyReferences[0].Name);

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(outputPath, "NetStandard20.dll"));

            Assert.Single(outAssmDef.MainModule.AssemblyReferences);
            Assert.Equal("netstandard", outAssmDef.MainModule.AssemblyReferences[0].Name);
        }
示例#21
0
        public void CheckPortable()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='HideStrings' value='false' />" +
                @"<Var name='SuppressIldasm' value='false' />" +
                @"<Var name='KeyFile' value='$(InPath){2}SigningKey.snk' />" +
                @"<Module file='$(InPath){2}SharpSnmpLib.Portable.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "SharpSnmpLib.Portable.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "SharpSnmpLib.Portable.dll"),
                          destFileName, true);
            }

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "SharpSnmpLib.Portable.dll"));

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(outputPath, "SharpSnmpLib.Portable.dll"));

            var corlibs = outAssmDef.MainModule.AssemblyReferences.Where(reference => reference.Name == "mscorlib");

            Assert.Single(corlibs);
            Assert.Equal("2.0.5.0", corlibs.First().Version.ToString());
        }
示例#22
0
        public void CheckCannotObfuscateSigned()
        {
            string outputPath = TestHelper.OutputPath;
            string xml        = string.Format(
                @"<?xml version='1.0'?>" +
                @"<Obfuscator>" +
                @"<Var name='InPath' value='{0}' />" +
                @"<Var name='OutPath' value='{1}' />" +
                @"<Var name='KeepPublicApi' value='false' />" +
                @"<Var name='AnalyzeXaml' value='true' />" +
                @"<Module file='$(InPath){2}WpfApplication1.dll' />" +
                @"</Obfuscator>", TestHelper.InputPath, outputPath, Path.DirectorySeparatorChar);

            TestHelper.CleanInput();

            // build it with the keyfile option (embeds the public key, and signs the assembly)
            string destFileName = Path.Combine(TestHelper.InputPath, "WpfApplication1.dll");

            if (!File.Exists(destFileName))
            {
                File.Copy(Path.Combine(TestHelper.InputPath, @"..", "WpfApplication1.dll"),
                          destFileName, true);
            }

            var map = TestHelper.Obfuscate(xml).Mapping;

            AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(TestHelper.InputPath, "WpfApplication1.dll"));

            AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly(
                Path.Combine(outputPath, "WpfApplication1.dll"));

            TypeDefinition classAType = inAssmDef.MainModule.GetType("WpfApplication1.MainWindow");
            var            obfuscated = map.GetClass(new TypeKey(classAType));

            Assert.True(ObfuscationStatus.Skipped == obfuscated.Status, "WpfApplication1.MainWindow should have been skipped");
            Assert.Equal("filtered by BAML", obfuscated.StatusText);
        }