Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Merge branch 'guiwpf'
Browse files Browse the repository at this point in the history
Conflicts:
	Confuser.Core/ConfuserEngine.cs
	Confuser.Core/Marker.cs
	Confuser.Renamer/AnalyzePhase.cs
  • Loading branch information
yck1509 committed Jun 22, 2014
2 parents 4be2740 + 5969669 commit 479b7e3
Show file tree
Hide file tree
Showing 93 changed files with 4,214 additions and 116 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ obj/
_ReSharper*/
[Tt]est[Rr]esult*

/docs
!packages/*/build/
packages/
/Confuser.Test
Expand Down
6 changes: 3 additions & 3 deletions Confuser.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public void ErrorException(string msg, Exception ex) {
WriteLineWithColor(ConsoleColor.Red, "Exception: " + ex);
}

public void Progress(int overall, int progress) {
WriteLineWithColor(ConsoleColor.Gray, string.Format("{0}/{1}", progress, overall));
}
public void Progress(int progress, int overall) { }

public void EndProgress() { }

public void Finish(bool successful) {
DateTime now = DateTime.Now;
Expand Down
67 changes: 33 additions & 34 deletions Confuser.Core/ConfuserEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,21 @@ private static void RunInternal(ConfuserParameters parameters, CancellationToken
context.PackerInitiated = parameters.PackerInitiated;
context.token = token;


var asmResolver = new AssemblyResolver();
asmResolver.EnableTypeDefCache = true;
asmResolver.DefaultModuleContext = new ModuleContext(asmResolver);
context.Resolver = asmResolver;
context.BaseDirectory = Path.Combine(Environment.CurrentDirectory, parameters.Project.BaseDirectory + "\\");
context.OutputDirectory = Path.Combine(parameters.Project.BaseDirectory, parameters.Project.OutputDirectory + "\\");
foreach (string probePath in parameters.Project.ProbePaths)
asmResolver.PostSearchPaths.Add(Path.Combine(context.BaseDirectory, probePath));

PrintInfo(context);

bool ok = false;
try {
var asmResolver = new AssemblyResolver();
asmResolver.EnableTypeDefCache = true;
asmResolver.DefaultModuleContext = new ModuleContext(asmResolver);
context.Resolver = asmResolver;
context.BaseDirectory = Path.Combine(Environment.CurrentDirectory, parameters.Project.BaseDirectory + "\\");
context.OutputDirectory = Path.Combine(parameters.Project.BaseDirectory, parameters.Project.OutputDirectory + "\\");
foreach (string probePath in parameters.Project.ProbePaths)
asmResolver.PostSearchPaths.Add(Path.Combine(context.BaseDirectory, probePath));

context.CheckCancellation();

Marker marker = parameters.GetMarker();

// 2. Discover plugins
Expand All @@ -93,13 +94,14 @@ private static void RunInternal(ConfuserParameters parameters, CancellationToken

context.Logger.InfoFormat("Discovered {0} protections, {1} packers.", prots.Count, packers.Count);

context.CheckCancellation();

// 3. Resolve dependency
context.Logger.Debug("Resolving component dependency...");
try {
var resolver = new DependencyResolver(prots);
prots = resolver.SortDependency();
}
catch (CircularDependencyException ex) {
} catch (CircularDependencyException ex) {
context.Logger.ErrorException("", ex);
throw new ConfuserException(ex);
}
Expand All @@ -110,6 +112,8 @@ private static void RunInternal(ConfuserParameters parameters, CancellationToken
foreach (Packer packer in packers)
components.Add(packer);

context.CheckCancellation();

// 4. Load modules
context.Logger.Info("Loading input modules...");
marker.Initalize(prots, packers);
Expand All @@ -122,55 +126,51 @@ private static void RunInternal(ConfuserParameters parameters, CancellationToken
asmResolver.AddToCache(module);
context.Packer = markings.Packer;

context.CheckCancellation();

// 5. Initialize components
context.Logger.Info("Initializing...");
foreach (ConfuserComponent comp in components) {
try {
comp.Initialize(context);
}
catch (Exception ex) {
} catch (Exception ex) {
context.Logger.ErrorException("Error occured during initialization of '" + comp.Name + "'.", ex);
throw new ConfuserException(ex);
}
context.CheckCancellation();
}

context.CheckCancellation();

// 6. Build pipeline
context.Logger.Debug("Building pipeline...");
var pipeline = new ProtectionPipeline();
context.Pipeline = pipeline;
foreach (ConfuserComponent comp in components) {
comp.PopulatePipeline(pipeline);
}

context.CheckCancellation();

//7. Run pipeline
RunPipeline(pipeline, context);

ok = true;
}
catch (AssemblyResolveException ex) {
} catch (AssemblyResolveException ex) {
context.Logger.ErrorException("Failed to resolve a assembly, check if all dependencies are of correct version.", ex);
}
catch (TypeResolveException ex) {
} catch (TypeResolveException ex) {
context.Logger.ErrorException("Failed to resolve a type, check if all dependencies are of correct version.", ex);
}
catch (MemberRefResolveException ex) {
} catch (MemberRefResolveException ex) {
context.Logger.ErrorException("Failed to resolve a member, check if all dependencies are of correct version.", ex);
}
catch (IOException ex) {
} catch (IOException ex) {
context.Logger.ErrorException("An IO error occured, check if all input/output locations are read/writable.", ex);
}
catch (OperationCanceledException) {
} catch (OperationCanceledException) {
context.Logger.Error("Operation is canceled.");
}
catch (ConfuserException) {
} catch (ConfuserException) {
// Exception is already handled/logged, so just ignore and report failure
}
catch (Exception ex) {
} catch (Exception ex) {
context.Logger.ErrorException("Unknown error occured.", ex);
}
finally {
} finally {
context.Logger.Finish(ok);
}
}
Expand Down Expand Up @@ -234,8 +234,7 @@ private static void Inspection(ConfuserContext context) {
.SelectMany(module => module.GetAssemblyRefs().Select(asmRef => Tuple.Create(asmRef, module)))) {
try {
AssemblyDef assembly = context.Resolver.ResolveThrow(dependency.Item1, dependency.Item2);
}
catch (AssemblyResolveException ex) {
} catch (AssemblyResolveException ex) {
context.Logger.ErrorException("Failed to resolve dependency of '" + dependency.Item2.Name + "'.", ex);
throw new ConfuserException(ex);
}
Expand Down Expand Up @@ -300,6 +299,7 @@ private static void BeginModule(ConfuserContext context) {
context.Logger.InfoFormat("Processing module '{0}'...", context.CurrentModule.Name);

context.CurrentModuleWriterListener = new ModuleWriterListener();
context.CurrentModuleWriterListener.OnWriterEvent += (sender, e) => context.CheckCancellation();
context.CurrentModuleWriterOptions = new ModuleWriterOptions(context.CurrentModule, context.CurrentModuleWriterListener);
var snKey = context.Annotations.Get<StrongNameKey>(context.CurrentModule, Marker.SNKey);
context.CurrentModuleWriterOptions.InitializeStrongNameSigning(context.CurrentModule, snKey);
Expand Down Expand Up @@ -388,8 +388,7 @@ private static void SaveModules(ConfuserContext context) {
private static void PrintInfo(ConfuserContext context) {
if (context.PackerInitiated) {
context.Logger.Info("Protecting packer stub...");
}
else {
} else {
context.Logger.InfoFormat("{0} {1}", Version, Copyright);

Type mono = Type.GetType("Mono.Runtime");
Expand Down
19 changes: 18 additions & 1 deletion Confuser.Core/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,26 @@ public interface ILogger {
/// <summary>
/// Logs the progress of protection.
/// </summary>
/// <remarks>
/// This method is intended to be used with <see cref="EndProgress" />.
/// </remarks>
/// <example>
/// <code>
/// for (int i = 0; i &lt; defs.Length; i++) {
/// logger.Progress(i + 1, defs.Length);
/// }
/// logger.EndProgress();
/// </code>
/// </example>
/// <param name="overall">The total work amount .</param>
/// <param name="progress">The amount of work done.</param>
void Progress(int overall, int progress);
void Progress(int progress, int overall);

/// <summary>
/// End the progress of protection.
/// </summary>
/// <seealso cref="Progress" />
void EndProgress();

/// <summary>
/// Logs the finish of protection.
Expand Down
6 changes: 5 additions & 1 deletion Confuser.Core/Marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ protected internal virtual MarkerResult MarkProject(ConfuserProject proj, Confus
context.Logger.InfoFormat("Loading '{0}'...", module.Path);

ModuleDefMD modDef = module.Resolve(proj.BaseDirectory, context.Resolver.DefaultModuleContext);
context.CheckCancellation();

if (proj.Debug)
modDef.LoadPdb();

Expand All @@ -118,8 +120,10 @@ protected internal virtual MarkerResult MarkProject(ConfuserProject proj, Confus
context.Annotations.Set(modDef, SNKey, LoadSNKey(context, module.SNKeyPath == null ? null : Path.Combine(proj.BaseDirectory, module.SNKeyPath), module.SNKeyPassword));
context.Annotations.Set(modDef, RulesKey, rules);

foreach (IDnlibDef def in modDef.FindDefinitions())
foreach (IDnlibDef def in modDef.FindDefinitions()) {
ApplyRules(context, def, rules);
context.CheckCancellation();
}

// Packer parameters are stored in modules
if (packerParams != null)
Expand Down
3 changes: 3 additions & 0 deletions Confuser.Core/NullLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void ErrorException(string msg, Exception ex) { }
/// <inheritdoc />
public void Progress(int overall, int progress) { }

/// <inheritdoc />
public void EndProgress() { }

/// <inheritdoc />
public void Finish(bool successful) { }

Expand Down
8 changes: 6 additions & 2 deletions Confuser.Core/Packer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ public void ErrorException(string msg, Exception ex) {
baseLogger.ErrorException(msg, ex);
}

public void Progress(int overall, int progress) {
baseLogger.Progress(overall, progress);
public void Progress(int progress, int overall) {
baseLogger.Progress(progress, overall);
}

public void EndProgress() {
baseLogger.EndProgress();
}

public void Finish(bool successful) {
Expand Down
7 changes: 6 additions & 1 deletion Confuser.Core/PluginDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public void GetPlugins(ConfuserContext context, out IList<Protection> protection
GetPluginsInternal(context, protections, packers, components);
}

private static bool HasAccessibleDefConstructor(Type type) {
/// <summary>
/// Determines whether the specified type has an accessible default constructor.
/// </summary>
/// <param name="type">The type.</param>
/// <returns><c>true</c> if the specified type has an accessible default constructor; otherwise, <c>false</c>.</returns>
public static bool HasAccessibleDefConstructor(Type type) {
ConstructorInfo ctor = type.GetConstructor(Type.EmptyTypes);
if (ctor == null) return false;
return ctor.IsPublic;
Expand Down
2 changes: 1 addition & 1 deletion Confuser.Core/Project/ConfuserPrj.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<xs:sequence>
<xs:element name="rule" type="rule" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="packer" type="objSettings" minOccurs="0" maxOccurs="1" />
<xs:element name="module" type="module" minOccurs="1" maxOccurs="unbounded" />
<xs:element name="module" type="module" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="probePath" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="plugin" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
Expand Down
6 changes: 6 additions & 0 deletions Confuser.Core/ProtectionPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public ProtectionPhase(ConfuserComponent parent) {
/// <value>The protection targets.</value>
public abstract ProtectionTargets Targets { get; }

/// <summary>
/// Gets the name of the phase.
/// </summary>
/// <value>The name of phase.</value>
public abstract string Name { get; }

/// <summary>
/// Gets a value indicating whether this phase process all targets, not just the targets that requires the component.
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion Confuser.Core/ProtectionPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ public T FindPhase<T>() where T : ProtectionPhase {
/// <param name="context">The working context.</param>
internal void ExecuteStage(PipelineStage stage, Action<ConfuserContext> func, Func<IList<IDnlibDef>> targets, ConfuserContext context) {
foreach (ProtectionPhase pre in preStage[stage]) {
pre.Execute(context, new ProtectionParameters(pre.Parent, Filter(context, targets(), pre)));
context.CheckCancellation();
context.Logger.DebugFormat("Executing '{0}' phase...", pre.Name);
pre.Execute(context, new ProtectionParameters(pre.Parent, Filter(context, targets(), pre)));
}
context.CheckCancellation();
func(context);
context.CheckCancellation();
foreach (ProtectionPhase post in postStage[stage]) {
context.Logger.DebugFormat("Executing '{0}' phase...", post.Name);
post.Execute(context, new ProtectionParameters(post.Parent, Filter(context, targets(), post)));
context.CheckCancellation();
}
Expand Down
Loading

0 comments on commit 479b7e3

Please sign in to comment.