Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Confuser.Core/ConfuserAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Clear() {

/// <inheritdoc />
public bool Remove(string item) =>
_lists.Aggregate(true, (current, list) => current | list.Remove(item));
_lists.Aggregate(false, (current, list) => current | list.Remove(item));

/// <inheritdoc />
public int Count => _lists[0].Count;
Expand Down
51 changes: 29 additions & 22 deletions Confuser.Core/ConfuserEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ static ConfuserEngine() {
/// <paramref name="parameters" />.Project is <c>null</c>.
/// </exception>
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);
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -478,31 +480,36 @@ static IEnumerable<string> 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;
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Confuser.Core/Marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public class Marker {
protected Dictionary<string, Protection> protections;

/// <summary>
/// Initalizes the Marker with specified protections and packers.
/// Initializes the Marker with specified protections and packers.
/// </summary>
/// <param name="protections">The protections.</param>
/// <param name="packers">The packers.</param>
public virtual void Initalize(IList<Protection> protections, IList<Packer> packers) {
public virtual void Initialize(IList<Protection> protections, IList<Packer> packers) {
this.protections = protections.ToDictionary(prot => prot.Id, prot => prot, StringComparer.OrdinalIgnoreCase);
this.packers = packers.ToDictionary(packer => packer.Id, packer => packer, StringComparer.OrdinalIgnoreCase);
}
Expand Down
2 changes: 1 addition & 1 deletion Confuser.Core/ProtectionPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum PipelineStage {
ProcessModule,

/// <summary>
/// Confuser engine optimizes opcodes of the method bodys.
/// Confuser engine optimizes opcodes of the method bodies.
/// This stage occurs once per module.
/// </summary>
OptimizeMethods,
Expand Down
2 changes: 1 addition & 1 deletion Confuser.Core/Services/RandomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
12 changes: 6 additions & 6 deletions Confuser.Core/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public static void AddListEntry<TKey, TValue>(this IDictionary<TKey, List<TValue
/// <returns>The path of <paramref name="filespec" /> relative to <paramref name="folder" />.</returns>
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));
Expand Down Expand Up @@ -117,8 +117,8 @@ public static string NullIfEmpty(this string val) {
/// <param name="buffer">The input buffer.</param>
/// <returns>The SHA1 hash of the input buffer.</returns>
public static byte[] SHA1(byte[] buffer) {
var sha = new SHA1Managed();
return sha.ComputeHash(buffer);
using (var sha = new SHA1Managed())
return sha.ComputeHash(buffer);
}

/// <summary>
Expand All @@ -143,8 +143,8 @@ public static byte[] Xor(byte[] buffer1, byte[] buffer2) {
/// <param name="buffer">The input buffer.</param>
/// <returns>The SHA256 hash of the input buffer.</returns>
public static byte[] SHA256(byte[] buffer) {
var sha = new SHA256Managed();
return sha.ComputeHash(buffer);
using (var sha = new SHA256Managed())
return sha.ComputeHash(buffer);
}

/// <summary>
Expand Down
Loading