From 37d9a91ed98e0db5c90abdd19847d640d56ba9e1 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 21 May 2024 10:40:10 +0800 Subject: [PATCH 1/2] fix WPF relative resource renaming https://github.com/mkaring/ConfuserEx/issues/550 --- Confuser.Renamer/Analyzers/WPFAnalyzer.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Confuser.Renamer/Analyzers/WPFAnalyzer.cs b/Confuser.Renamer/Analyzers/WPFAnalyzer.cs index 9cc9993f9..f441558cd 100644 --- a/Confuser.Renamer/Analyzers/WPFAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/WPFAnalyzer.cs @@ -60,8 +60,15 @@ public void PreRename(ConfuserContext context, INameService service, ProtectionP var decodedName = HttpUtility.UrlDecode(doc.DocumentName); var encodedName = doc.DocumentName; if (bamlRefs.TryGetValue(decodedName, out var references)) { - var decodedDirectory = decodedName.Substring(0, decodedName.LastIndexOf('/') + 1); - var encodedDirectory = encodedName.Substring(0, encodedName.LastIndexOf('/') + 1); + var decodedLastSlash = decodedName.LastIndexOf('/') + 1; + var encodedLastSlash = encodedName.LastIndexOf("/") + 1; + + var decodedDirectory = decodedName.Substring(0, decodedLastSlash); + var encodedDirectory = encodedName.Substring(0, encodedLastSlash); + + var decodedFileName = decodedName.Substring(decodedLastSlash); + var encodedFileName = encodedName.Substring(encodedLastSlash); + var fileName = service.RandomName(renameMode).ToLowerInvariant(); if (decodedName.EndsWith(".BAML", StringComparison.OrdinalIgnoreCase)) @@ -78,8 +85,8 @@ public void PreRename(ConfuserContext context, INameService service, ProtectionP if (renameOk) { foreach (var bamlRef in references) { - bamlRef.Rename(module, decodedName, decodedNewName); - bamlRef.Rename(module, encodedName, encodedNewName); + bamlRef.Rename(module, decodedFileName, fileName); + bamlRef.Rename(module, encodedFileName, fileName); } doc.DocumentName = encodedNewName; } From 0c2ef94515ce34f678514d655f67a427e2f615b2 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 30 Aug 2024 09:32:17 +0800 Subject: [PATCH 2/2] Update WPFAnalyzer.cs remove empty line as code factor suggests --- Confuser.Renamer/Analyzers/WPFAnalyzer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Confuser.Renamer/Analyzers/WPFAnalyzer.cs b/Confuser.Renamer/Analyzers/WPFAnalyzer.cs index f441558cd..d9ba3624d 100644 --- a/Confuser.Renamer/Analyzers/WPFAnalyzer.cs +++ b/Confuser.Renamer/Analyzers/WPFAnalyzer.cs @@ -69,7 +69,6 @@ public void PreRename(ConfuserContext context, INameService service, ProtectionP var decodedFileName = decodedName.Substring(decodedLastSlash); var encodedFileName = encodedName.Substring(encodedLastSlash); - var fileName = service.RandomName(renameMode).ToLowerInvariant(); if (decodedName.EndsWith(".BAML", StringComparison.OrdinalIgnoreCase)) fileName += ".baml";