From 3809ead19b244b03256fd0ddd1f00dc2a0830c1e Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Wed, 10 Jun 2026 16:33:42 +1200 Subject: [PATCH 1/5] Fix TeeList.Remove return value --- Confuser.Core/ConfuserAssemblyResolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Confuser.Core/ConfuserAssemblyResolver.cs b/Confuser.Core/ConfuserAssemblyResolver.cs index 05ef4731f..2fced6a6b 100644 --- a/Confuser.Core/ConfuserAssemblyResolver.cs +++ b/Confuser.Core/ConfuserAssemblyResolver.cs @@ -81,7 +81,7 @@ public void Clear() { /// public bool Remove(string item) => - _lists.Aggregate(true, (current, list) => current | list.Remove(item)); + _lists.Aggregate(false, (current, list) => current | list.Remove(item)); /// public int Count => _lists[0].Count; From ac08097cfded3dd3cb72170d233cc3d3de4f1616 Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Wed, 10 Jun 2026 16:34:34 +1200 Subject: [PATCH 2/5] Fix argument exceptions --- Confuser.Core/ConfuserEngine.cs | 4 +++- Confuser.Core/Utils.cs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs index 03c616d46..f87094066 100644 --- a/Confuser.Core/ConfuserEngine.cs +++ b/Confuser.Core/ConfuserEngine.cs @@ -62,8 +62,10 @@ static ConfuserEngine() { /// .Project is null. /// public static Task Run(ConfuserParameters parameters, CancellationToken? token = null) { + if (parameters == null) + throw new ArgumentNullException(nameof(parameters)); if (parameters.Project == null) - throw new ArgumentNullException("parameters"); + throw new ArgumentNullException(nameof(parameters)); if (token == null) token = new CancellationTokenSource().Token; return Task.Factory.StartNew(() => RunInternal(parameters, token.Value), token.Value); diff --git a/Confuser.Core/Utils.cs b/Confuser.Core/Utils.cs index 323b2833c..b3e97b94b 100644 --- a/Confuser.Core/Utils.cs +++ b/Confuser.Core/Utils.cs @@ -76,14 +76,14 @@ public static void AddListEntry(this IDictionaryThe path of relative to . public static string GetRelativePath(string fileSpec, string baseDirectory) { if (fileSpec is null) throw new ArgumentNullException(nameof(fileSpec)); - if (baseDirectory is null) throw new ArgumentNullException(nameof(fileSpec)); + if (baseDirectory is null) throw new ArgumentNullException(nameof(baseDirectory)); return GetRelativePath(new FileInfo(fileSpec), new DirectoryInfo(baseDirectory)); } public static string GetRelativePath(FileInfo fileSpec, DirectoryInfo baseDirectory) { if (fileSpec is null) throw new ArgumentNullException(nameof(fileSpec)); - if (baseDirectory is null) throw new ArgumentNullException(nameof(fileSpec)); + if (baseDirectory is null) throw new ArgumentNullException(nameof(baseDirectory)); if (baseDirectory.FullName.EndsWith(Path.DirectorySeparatorChar.ToString())) { baseDirectory = new DirectoryInfo(baseDirectory.FullName.TrimEnd(Path.DirectorySeparatorChar)); From e72600654bce838023c250a7eecf8d4021ff38ec Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Wed, 10 Jun 2026 16:35:28 +1200 Subject: [PATCH 3/5] Fix typos --- Confuser.Core/ConfuserEngine.cs | 4 ++-- Confuser.Core/Marker.cs | 4 ++-- Confuser.Core/ProtectionPipeline.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs index f87094066..ebe370e16 100644 --- a/Confuser.Core/ConfuserEngine.cs +++ b/Confuser.Core/ConfuserEngine.cs @@ -138,7 +138,7 @@ static void RunInternal(ConfuserParameters parameters, CancellationToken token) // 4. Load modules context.Logger.Info("Loading input modules..."); - marker.Initalize(prots, packers); + marker.Initialize(prots, packers); MarkerResult markings = marker.MarkProject(context.Project, context); context.Modules = new ModuleSorter(markings.Modules).Sort().ToList().AsReadOnly(); foreach (var module in context.Modules) @@ -158,7 +158,7 @@ static void RunInternal(ConfuserParameters parameters, CancellationToken token) comp.Initialize(context); } catch (Exception ex) { - context.Logger.ErrorException("Error occured during initialization of '" + comp.Name + "'.", ex); + context.Logger.ErrorException("Error occurred during initialization of '" + comp.Name + "'.", ex); throw new ConfuserException(ex); } context.CheckCancellation(); diff --git a/Confuser.Core/Marker.cs b/Confuser.Core/Marker.cs index 70e8a8529..f77c218c3 100644 --- a/Confuser.Core/Marker.cs +++ b/Confuser.Core/Marker.cs @@ -56,11 +56,11 @@ public class Marker { protected Dictionary protections; /// - /// Initalizes the Marker with specified protections and packers. + /// Initializes the Marker with specified protections and packers. /// /// The protections. /// The packers. - public virtual void Initalize(IList protections, IList packers) { + public virtual void Initialize(IList protections, IList packers) { this.protections = protections.ToDictionary(prot => prot.Id, prot => prot, StringComparer.OrdinalIgnoreCase); this.packers = packers.ToDictionary(packer => packer.Id, packer => packer, StringComparer.OrdinalIgnoreCase); } diff --git a/Confuser.Core/ProtectionPipeline.cs b/Confuser.Core/ProtectionPipeline.cs index 406ed3ebc..4146c0a10 100644 --- a/Confuser.Core/ProtectionPipeline.cs +++ b/Confuser.Core/ProtectionPipeline.cs @@ -28,7 +28,7 @@ public enum PipelineStage { ProcessModule, /// - /// Confuser engine optimizes opcodes of the method bodys. + /// Confuser engine optimizes opcodes of the method bodies. /// This stage occurs once per module. /// OptimizeMethods, From 287cf29b509c7edd1596fd7207d150cda3e033bf Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Wed, 10 Jun 2026 16:37:22 +1200 Subject: [PATCH 4/5] Fix deterministic disposal --- Confuser.Core/ConfuserEngine.cs | 43 ++++++++++++++++++--------------- Confuser.Core/Utils.cs | 8 +++--- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs index ebe370e16..741efbf79 100644 --- a/Confuser.Core/ConfuserEngine.cs +++ b/Confuser.Core/ConfuserEngine.cs @@ -480,31 +480,36 @@ static IEnumerable GetFrameworkVersions() { using (RegistryKey ndpKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ""). OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\")) { + if (ndpKey == null) yield break; foreach (string versionKeyName in ndpKey.GetSubKeyNames()) { if (!versionKeyName.StartsWith("v")) continue; - RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName); - var name = (string)versionKey.GetValue("Version", ""); - string sp = versionKey.GetValue("SP", "").ToString(); - string install = versionKey.GetValue("Install", "").ToString(); - if (install == "" || sp != "" && install == "1") - yield return versionKeyName + " " + name; - - if (name != "") - continue; + using (RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName)) { + if (versionKey == null) continue; + var name = (string)versionKey.GetValue("Version", ""); + string sp = versionKey.GetValue("SP", "").ToString(); + string install = versionKey.GetValue("Install", "").ToString(); + if (install == "" || sp != "" && install == "1") + yield return versionKeyName + " " + name; - foreach (string subKeyName in versionKey.GetSubKeyNames()) { - RegistryKey subKey = versionKey.OpenSubKey(subKeyName); - name = (string)subKey.GetValue("Version", ""); if (name != "") - sp = subKey.GetValue("SP", "").ToString(); - install = subKey.GetValue("Install", "").ToString(); - - if (install == "") - yield return versionKeyName + " " + name; - else if (install == "1") - yield return " " + subKeyName + " " + name; + continue; + + foreach (string subKeyName in versionKey.GetSubKeyNames()) { + using (RegistryKey subKey = versionKey.OpenSubKey(subKeyName)) { + if (subKey == null) continue; + name = (string)subKey.GetValue("Version", ""); + if (name != "") + sp = subKey.GetValue("SP", "").ToString(); + install = subKey.GetValue("Install", "").ToString(); + + if (install == "") + yield return versionKeyName + " " + name; + else if (install == "1") + yield return " " + subKeyName + " " + name; + } + } } } } diff --git a/Confuser.Core/Utils.cs b/Confuser.Core/Utils.cs index b3e97b94b..e941cc1e6 100644 --- a/Confuser.Core/Utils.cs +++ b/Confuser.Core/Utils.cs @@ -117,8 +117,8 @@ public static string NullIfEmpty(this string val) { /// The input buffer. /// The SHA1 hash of the input buffer. public static byte[] SHA1(byte[] buffer) { - var sha = new SHA1Managed(); - return sha.ComputeHash(buffer); + using (var sha = new SHA1Managed()) + return sha.ComputeHash(buffer); } /// @@ -143,8 +143,8 @@ public static byte[] Xor(byte[] buffer1, byte[] buffer2) { /// The input buffer. /// The SHA256 hash of the input buffer. public static byte[] SHA256(byte[] buffer) { - var sha = new SHA256Managed(); - return sha.ComputeHash(buffer); + using (var sha = new SHA256Managed()) + return sha.ComputeHash(buffer); } /// From 4dfdafb6b152f63be57e5dcbb0eab33c5e4fe347 Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Wed, 10 Jun 2026 16:37:53 +1200 Subject: [PATCH 5/5] Fix RandomService seed --- Confuser.Core/Services/RandomService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Confuser.Core/Services/RandomService.cs b/Confuser.Core/Services/RandomService.cs index 9016df741..56f18310b 100644 --- a/Confuser.Core/Services/RandomService.cs +++ b/Confuser.Core/Services/RandomService.cs @@ -235,7 +235,7 @@ public RandomService(string seed) { public RandomGenerator GetRandomGenerator(string id) { if (string.IsNullOrEmpty(id)) throw new ArgumentNullException("id"); - byte[] newSeed = seed; + byte[] newSeed = (byte[])seed.Clone(); byte[] idHash = Utils.SHA256(Encoding.UTF8.GetBytes(id)); for (int i = 0; i < 32; i++) newSeed[i] ^= idHash[i];