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;
diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs
index 03c616d46..741efbf79 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);
@@ -136,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)
@@ -156,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();
@@ -478,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/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,
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];
diff --git a/Confuser.Core/Utils.cs b/Confuser.Core/Utils.cs
index 323b2833c..e941cc1e6 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));
@@ -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);
}
///