diff --git a/Confuser.Renamer/MessageDeobfuscator.cs b/Confuser.Renamer/MessageDeobfuscator.cs index aaf19f922..c86ed4f7c 100644 --- a/Confuser.Renamer/MessageDeobfuscator.cs +++ b/Confuser.Renamer/MessageDeobfuscator.cs @@ -45,14 +45,14 @@ public string Deobfuscate(string obfuscatedMessage) { string DecodeSymbolMap(Match match) { var symbol = match.Value; if (_symbolMap.TryGetValue(symbol, out string result)) - return NameService.ExtractShortName(result); - return NameService.ExtractShortName(symbol); + return NameService.ExtractShortName(result, false); + return NameService.ExtractShortName(symbol, false); } string DecodeSymbolPassword(Match match) { var sym = match.Value; try { - return NameService.ExtractShortName(_renamer.Decrypt(sym)); + return NameService.ExtractShortName(_renamer.Decrypt(sym), false); } catch { return sym; diff --git a/Confuser.Renamer/NameService.cs b/Confuser.Renamer/NameService.cs index dcebd73eb..9f9639569 100644 --- a/Confuser.Renamer/NameService.cs +++ b/Confuser.Renamer/NameService.cs @@ -360,13 +360,13 @@ string GetSimplifiedFullName(IDnlibDef dnlibDef) { } if (GetParam(dnlibDef, "shortNames")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true) { - result = ExtractShortName(result); + result = ExtractShortName(result, true); } return result; } - public static string ExtractShortName(string fullName) { + public static string ExtractShortName(string fullName, bool trimNamespace) { const string doubleParen = "::"; int doubleParenIndex = fullName.IndexOf(doubleParen); if (doubleParenIndex != -1) { @@ -381,6 +381,11 @@ public static string ExtractShortName(string fullName) { return fullName.Substring(slashIndex + 1); } + if (trimNamespace) { + int dotIndex = fullName.IndexOf('.'); + return dotIndex != -1 ? fullName.Substring(dotIndex + 1) : fullName; + } + return fullName; } } diff --git a/Tests/MethodOverloading.Test/MethodOverloadingTest.cs b/Tests/MethodOverloading.Test/MethodOverloadingTest.cs index 52557d6df..4e35b3d66 100644 --- a/Tests/MethodOverloading.Test/MethodOverloadingTest.cs +++ b/Tests/MethodOverloading.Test/MethodOverloadingTest.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading.Tasks; using Confuser.Core; using Confuser.Core.Project; @@ -31,7 +33,29 @@ await Run( "class5" }, new SettingItem("rename") { ["mode"] = "decodable", ["shortNames"] = shortNames.ToString().ToLowerInvariant() }, - shortNames ? "_shortnames" : "_fullnames" + shortNames ? "_shortnames" : "_fullnames", + seed: "seed", + postProcessAction: outputPath => { + var symbolsPath = Path.Combine(outputPath, "symbols.map"); + var symbols = File.ReadAllLines(symbolsPath).Select(line => { + var parts = line.Split('\t'); + return new KeyValuePair(parts[0], parts[1]); + }).ToDictionary(keyValue => keyValue.Key, keyValue => keyValue.Value); + + if (shortNames) { + Assert.Equal("Class", symbols["_OatkF4GhWlgOakbgdlaLpqEglhm"]); + Assert.Equal("NestedClass", symbols["_GYHfKMUMLLO9oVLM117IvfCdmUC"]); + Assert.Equal("OverloadedMethod", symbols["_phF8iy7Y79cwt3EaAFmJzW2bGch"]); + } + else { + Assert.Equal("MethodOverloading.Class", symbols["_iyWU2GdYVZxajP8BQlt8KKTy6qQ"]); + Assert.Equal("MethodOverloading.Program/NestedClass", symbols["_CZIbNVHU7wPJyGhgOcTnIUsFtC0"]); + Assert.Equal("MethodOverloading.Program::OverloadedMethod(System.Object[])", symbols["_LzCBuBOSn49xbtKNsjuJxQZPIEW"]); + Assert.Equal("MethodOverloading.Program::OverloadedMethod(System.String)", symbols["_ywSbkiShk8k3qj7bBrEWEUfs9Km"]); + } + + return Task.Delay(0); + } ); public static IEnumerable MethodOverloadingData => new[] { new object[] {false}, new object[] {true}}; diff --git a/Tests/MethodOverloading/Program.cs b/Tests/MethodOverloading/Program.cs index 1ebe33a63..f95d1f239 100644 --- a/Tests/MethodOverloading/Program.cs +++ b/Tests/MethodOverloading/Program.cs @@ -43,7 +43,7 @@ public class Class5 : BaseClass5, Interface5 { } public class Program { - public class Test { + public class NestedClass { public override string ToString() => "test"; } @@ -55,7 +55,7 @@ public class Test { public static object OverloadedMethod(bool cond, float param1, double param2) => cond ? param1 : param2; - public static Test OverloadedMethod(Test test) => test; + public static NestedClass OverloadedMethod(NestedClass nestedClass) => nestedClass; static int Main(string[] args) { Console.WriteLine("START"); @@ -63,7 +63,7 @@ static int Main(string[] args) { Console.WriteLine(OverloadedMethod("Hello world")); Console.WriteLine(OverloadedMethod(new object[] { "object" })); Console.WriteLine(OverloadedMethod(false, 1.0f, 2.0)); - Console.WriteLine(OverloadedMethod(new Test())); + Console.WriteLine(OverloadedMethod(new NestedClass())); Console.WriteLine(new Class().Method("class")); Console.WriteLine(new Class2().Method2("class2")); Console.WriteLine(new Class3().Method3("class3"));