public void Test013_NameOnly() { TestDeobfOptions options = new TestDeobfOptions(); options.Rows = new string[] { "Assembly013.dll" }; options.ApplyFrom("Name Only"); TestUtils.Deobfuscate(options); string outputFile = options.OutputFiles[0]; TestPEVerifyOptions vo = new TestPEVerifyOptions(); vo.Rows = new string[] { outputFile }; //After upgrade to 4.0, peverify find 1 error //TestUtils.PEVerify(vo); vo.TextInfoBox = new System.Windows.Forms.TextBox(); TestPEVerifier verifier = new TestPEVerifier(vo); verifier.Go(); string outputText = vo.TextInfoBox.Text; if ( outputText.Contains("1 Error(s) Verifying") && outputText.Contains("NS014.c000148[T]::m0003db][mdToken=0x6000f71][offset 0x00000021] The 'this' parameter to the call must be the calling method's 'this' parameter.(Error: 0x801318E1)") ) { Utils.DeleteFile(outputFile); } else { Assert.Fail(String.Format("Failed to verify {0}", options.Rows[0])); } }
public static void PEVerify(TestPEVerifyOptions options) { if (options == null || options.Rows == null || options.Rows.Length == 0) { return; } TestPEVerifier verifier = new TestPEVerifier(options); options.TextInfoBox = new TextBox(); verifier.Go(); ///All Classes and Methods in E:\....\Assembly007.exe Verified. //11 Error(s) Verifying E:\....\Assembly007.exe string outputText = options.TextInfoBox.Text; bool verified = !outputText.Contains(" Error(s) Verifying ") && outputText.Contains("All Classes and Methods in ") && outputText.Contains(" Verified."); if (!verified) { Utils.ConsoleOutput(outputText); } Assert.IsTrue(verified, String.Format("Failed to verify {0}", options.Rows[0])); }
public void Test007_NameOnly() { TestDeobfOptions options = new TestDeobfOptions(); options.Rows = new string[] { "Assembly007.exe" }; options.ApplyFrom("Name Only"); TestUtils.Deobfuscate(options); string outputFile = options.OutputFiles[0]; AssemblyDefinition ad = AssemblyDefinition.ReadAssembly(outputFile); string errorMsg = "Failed to find Dispose method in {0}"; string methodName = "Dispose"; string[] parameterTypes = new string[] { "System.Boolean" }; string returnType = "System.Void"; TypeDefinition td; MethodDefinition md; string typeName; typeName = "c0000a0"; td = ad.MainModule.GetType(typeName); md = TestUtils.FindMethod(td, methodName, parameterTypes, returnType); Assert.IsNotNull(md, String.Format(errorMsg, typeName)); typeName = "c00009d"; td = ad.MainModule.GetType(typeName); md = TestUtils.FindMethod(td, methodName, parameterTypes, returnType); Assert.IsNotNull(md, String.Format(errorMsg, typeName)); typeName = "c00005b"; td = ad.MainModule.GetType(typeName); md = TestUtils.FindMethod(td, methodName, parameterTypes, returnType); Assert.IsNotNull(md, String.Format(errorMsg, typeName)); Assert.IsTrue(md.HasOverrides, "Failed to find Overrides for method " + md.ToString()); Assert.AreEqual(methodName, md.Overrides[0].Name, "Failed to find Override Dispose for method " + md.ToString()); typeName = "c00002b"; td = ad.MainModule.GetType(typeName); md = TestUtils.FindMethod(td, "CompareTo", new string[] { "System.Object" }, "System.Int32"); Assert.IsNotNull(md, String.Format("Failed to find CompareTo method in {0}", typeName)); TestPEVerifyOptions vo = new TestPEVerifyOptions(); vo.Rows = new string[] { outputFile }; TestUtils.PEVerify(vo); Utils.DeleteFile(outputFile); }
public void Test015_NameOnly() { TestDeobfOptions options = new TestDeobfOptions(); options.Rows = new string[] { "Assembly015.dll" }; options.ApplyFrom("Name Only"); TestUtils.Deobfuscate(options); string outputFile = options.OutputFiles[0]; TestPEVerifyOptions vo = new TestPEVerifyOptions(); vo.Rows = new string[] { outputFile }; TestUtils.PEVerify(vo); Utils.DeleteFile(outputFile); }
public void RenameMeTest() { string sourceFile = deobf.Options.Rows[0]; string outputFile = deobf.Options.OutputFiles[0]; TestPEVerifyOptions vo = new TestPEVerifyOptions(); vo.Rows = new string[] { outputFile }; TestUtils.PEVerify(vo); List <string> errors = new List <string>(); ModuleDefinition sourceMd = AssemblyDefinition.ReadAssembly(sourceFile).MainModule; ModuleDefinition targetMd = AssemblyDefinition.ReadAssembly(outputFile).MainModule; foreach (TypeDefinition sourceTd in sourceMd.AllTypes) { if (!IsRenameMe(sourceTd.Name)) { continue; } string targetTypeName = GetTargetTypeName(deobf, sourceTd); if (targetMd.AllTypesDictionary.ContainsKey(targetTypeName)) { TypeDefinition targetTd = targetMd.AllTypesDictionary[targetTypeName]; CheckMembers(errors, sourceTd.Properties, targetTd.Properties, "p00", targetTypeName, "Property"); CheckMembers(errors, sourceTd.Fields, targetTd.Fields, "f00", targetTypeName, "Fields"); CheckMembers(errors, sourceTd.Methods, targetTd.Methods, "m00", targetTypeName, "Methods"); CheckMembers(errors, sourceTd.Events, targetTd.Events, "e00", targetTypeName, "Events"); CheckCustomAttributes(errors, sourceTd, targetTd, deobf); //TODO: generic parameters ... } else { AddError(errors, sourceTd.FullName, targetTypeName); } } Utils.ConsoleOutput(errors); Assert.AreEqual(0, errors.Count, "Failed to rename something!"); }
public void Test012_NameOnly() { TestDeobfOptions options = new TestDeobfOptions(); options.Rows = new string[] { "Assembly012.dll" }; options.ApplyFrom("Name Only"); options.chkAddMissingPropertyAndEventChecked = true; TestUtils.Deobfuscate(options); string outputFile = options.OutputFiles[0]; TestPEVerifyOptions vo = new TestPEVerifyOptions(); vo.Rows = new string[] { outputFile }; TestUtils.PEVerify(vo); //TODO: add some checking for added properties Utils.DeleteFile(outputFile); }
public static void PEVerify(TestPEVerifyOptions options) { if (options == null || options.Rows == null || options.Rows.Length == 0) return; TestPEVerifier verifier = new TestPEVerifier(options); options.TextInfoBox = new TextBox(); verifier.Go(); ///All Classes and Methods in E:\....\Assembly007.exe Verified. //11 Error(s) Verifying E:\....\Assembly007.exe string outputText = options.TextInfoBox.Text; bool verified = !outputText.Contains(" Error(s) Verifying ") && outputText.Contains("All Classes and Methods in ") && outputText.Contains(" Verified."); if (!verified) { Utils.ConsoleOutput(outputText); } Assert.IsTrue(verified, String.Format("Failed to verify {0}", options.Rows[0])); }
public TestPEVerifier(TestPEVerifyOptions options) : base(options) { }
public void RenameMeTest() { string sourceFile = deobf.Options.Rows[0]; string outputFile = deobf.Options.OutputFiles[0]; TestPEVerifyOptions vo = new TestPEVerifyOptions(); vo.Rows = new string[] { outputFile }; TestUtils.PEVerify(vo); List<string> errors = new List<string>(); ModuleDefinition sourceMd = AssemblyDefinition.ReadAssembly(sourceFile).MainModule; ModuleDefinition targetMd = AssemblyDefinition.ReadAssembly(outputFile).MainModule; foreach (TypeDefinition sourceTd in sourceMd.AllTypes) { if (!IsRenameMe(sourceTd.Name)) continue; string targetTypeName = GetTargetTypeName(deobf, sourceTd); if (targetMd.AllTypesDictionary.ContainsKey(targetTypeName)) { TypeDefinition targetTd = targetMd.AllTypesDictionary[targetTypeName]; CheckMembers(errors, sourceTd.Properties, targetTd.Properties, "p00", targetTypeName, "Property"); CheckMembers(errors, sourceTd.Fields, targetTd.Fields, "f00", targetTypeName, "Fields"); CheckMembers(errors, sourceTd.Methods, targetTd.Methods, "m00", targetTypeName, "Methods"); CheckMembers(errors, sourceTd.Events, targetTd.Events, "e00", targetTypeName, "Events"); CheckCustomAttributes(errors, sourceTd, targetTd, deobf); //TODO: generic parameters ... } else { AddError(errors, sourceTd.FullName, targetTypeName); } } Utils.ConsoleOutput(errors); Assert.AreEqual(0, errors.Count, "Failed to rename something!"); }