public void CheckClassHasAttribute() { Obfuscator item = BuildAndObfuscateAssemblies(); ObfuscationMap map = item.Mapping; string assmName = "AssemblyWithSpecializedGenerics.dll"; AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly( Path.Combine(TestHelper.InputPath, assmName)); AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly( Path.Combine(item.Project.Settings.OutPath, assmName)); { TypeDefinition classAType = inAssmDef.MainModule.GetType("TestClasses.ClassA`1"); MethodDefinition classAmethod2 = FindByName(classAType, "Method2"); TypeDefinition classBType = inAssmDef.MainModule.GetType("TestClasses.ClassB"); MethodDefinition classBmethod2 = FindByName(classBType, "Method2"); ObfuscatedThing classAEntry = map.GetMethod(new MethodKey(classAmethod2)); ObfuscatedThing classBEntry = map.GetMethod(new MethodKey(classBmethod2)); Assert.True( classAEntry.Status == ObfuscationStatus.Renamed && classBEntry.Status == ObfuscationStatus.Renamed, "Both methods should have been renamed."); Assert.True( classAEntry.StatusText == classBEntry.StatusText, "Both methods should have been renamed to the same thing."); } { TypeDefinition classAType = inAssmDef.MainModule.GetType("TestClasses.ClassA`1"); MethodDefinition classAmethod2 = FindByName(classAType, "Method3"); TypeDefinition classBType = inAssmDef.MainModule.GetType("TestClasses.ClassB"); MethodDefinition classBmethod2 = FindByName(classBType, "Method3"); ObfuscatedThing classAEntry = map.GetMethod(new MethodKey(classAmethod2)); ObfuscatedThing classBEntry = map.GetMethod(new MethodKey(classBmethod2)); Assert.True( classAEntry.Status == ObfuscationStatus.Renamed && classBEntry.Status == ObfuscationStatus.Renamed, "Both methods should have been renamed."); Assert.True( classAEntry.StatusText == classBEntry.StatusText, "Both methods should have been renamed to the same thing."); } }
public void CheckInterfaces() { Obfuscator item = BuildAndObfuscateAssemblies("AssemblyWithInterfaces"); ObfuscationMap map = item.Mapping; string assmName = "AssemblyWithInterfaces.dll"; AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly( Path.Combine(TestHelper.InputPath, assmName)); AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly( Path.Combine(item.Project.Settings.OutPath, assmName)); { TypeDefinition classCType = inAssmDef.MainModule.GetType("TestClasses.C"); MethodDefinition method = FindMethodByName(classCType, "Method"); PropertyDefinition property = FindPropertyByName(classCType, "Property"); ObfuscatedThing methodEntry = map.GetMethod(new MethodKey(method)); ObfuscatedThing propertyEntry = map.GetProperty(new PropertyKey(new TypeKey(classCType), property)); Assert.True(methodEntry.Status == ObfuscationStatus.Skipped, "public interface method should not be obfuscated."); Assert.True(propertyEntry.Status == ObfuscationStatus.Skipped, "public interface property should not be obfuscated."); } }
public void CheckClassHasAttribute() { Obfuscator item = BuildAndObfuscateAssemblies(); ObfuscationMap map = item.Mapping; string assmName = "AssemblyWithOverrides.dll"; AssemblyDefinition inAssmDef = AssemblyDefinition.ReadAssembly( Path.Combine(TestHelper.InputPath, assmName)); AssemblyDefinition outAssmDef = AssemblyDefinition.ReadAssembly( Path.Combine(item.Project.Settings.OutPath, assmName)); { TypeDefinition classAType = inAssmDef.MainModule.GetType("TestClasses.ClassA"); MethodDefinition classAmethod2 = FindByName(classAType, "Method2"); MethodDefinition classAcompare = FindByName(classAType, "CompareTo"); TypeDefinition classBType = inAssmDef.MainModule.GetType("TestClasses.ClassB"); MethodDefinition classBmethod2 = FindByName(classBType, "Method2"); MethodDefinition classBcompare = FindByName(classBType, "CompareTo"); TypeDefinition classCType = inAssmDef.MainModule.GetType("TestClasses.ClassC"); MethodDefinition classCmethod1 = FindByName(classCType, "Method1"); TypeDefinition classDType = inAssmDef.MainModule.GetType("TestClasses.ClassD"); MethodDefinition classDmethod1 = FindByName(classDType, "Method1"); ObfuscatedThing classAEntry = map.GetMethod(new MethodKey(classAmethod2)); ObfuscatedThing classACompareEntry = map.GetMethod(new MethodKey(classAcompare)); ObfuscatedThing classBEntry = map.GetMethod(new MethodKey(classBmethod2)); ObfuscatedThing classBCompareEntry = map.GetMethod(new MethodKey(classBcompare)); ObfuscatedThing classCEntry = map.GetMethod(new MethodKey(classCmethod1)); ObfuscatedThing classDEntry = map.GetMethod(new MethodKey(classDmethod1)); var classFType = inAssmDef.MainModule.GetType("TestClasses.ClassF"); var classFmethod = FindByName(classFType, "Test"); var classGType = inAssmDef.MainModule.GetType("TestClasses.ClassG"); var classGmethod = FindByName(classGType, "Test"); var classFEntry = map.GetMethod(new MethodKey(classFmethod)); var classGEntry = map.GetMethod(new MethodKey(classGmethod)); Assert.True( classAEntry.Status == ObfuscationStatus.Renamed && classBEntry.Status == ObfuscationStatus.Renamed, "Both methods should have been renamed."); Assert.True( classAEntry.StatusText == classBEntry.StatusText, "Both methods should have been renamed to the same thing."); Assert.True(classACompareEntry.Status == ObfuscationStatus.Skipped); Assert.True(classBCompareEntry.Status == ObfuscationStatus.Skipped); Assert.True(classCEntry.Status == ObfuscationStatus.Renamed); Assert.True(classDEntry.Status == ObfuscationStatus.Renamed); Assert.True( classFEntry.Status == ObfuscationStatus.Renamed && classGEntry.Status == ObfuscationStatus.Renamed, "Both methods should have been renamed."); Assert.True(classFEntry.StatusText == classGEntry.StatusText, "Both methods should have been renamed to the same thing."); } { TypeDefinition classAType = inAssmDef.MainModule.GetType("TestClasses.CA"); MethodDefinition classAmethod2 = FindByName(classAType, "get_PropA"); TypeDefinition classBType = inAssmDef.MainModule.GetType("TestClasses.CB"); MethodDefinition classBmethod2 = FindByName(classBType, "get_PropB"); TypeDefinition classCType = inAssmDef.MainModule.GetType("TestClasses.IA"); MethodDefinition classCmethod1 = FindByName(classCType, "get_PropA"); TypeDefinition classDType = inAssmDef.MainModule.GetType("TestClasses.IB"); MethodDefinition classDmethod1 = FindByName(classDType, "get_PropB"); ObfuscatedThing classAEntry = map.GetMethod(new MethodKey(classAmethod2)); ObfuscatedThing classBEntry = map.GetMethod(new MethodKey(classBmethod2)); ObfuscatedThing classCEntry = map.GetMethod(new MethodKey(classCmethod1)); ObfuscatedThing classDEntry = map.GetMethod(new MethodKey(classDmethod1)); Assert.True( classAEntry.Status == ObfuscationStatus.Renamed && classCEntry.Status == ObfuscationStatus.Renamed, "Both methods should have been renamed."); Assert.True( classAEntry.StatusText == classCEntry.StatusText, "Both methods should have been renamed to the same thing."); Assert.True( classBEntry.Status == ObfuscationStatus.Renamed && classDEntry.Status == ObfuscationStatus.Renamed, "Both methods should have been renamed."); Assert.True(classBEntry.StatusText == classDEntry.StatusText, "Both methods should have been renamed to the same thing."); Assert.True(classAEntry.StatusText != classBEntry.StatusText, "Both methods shouldn't have been renamed to the same thing."); } }