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

Commit

Permalink
Minor fixes/modification
Browse files Browse the repository at this point in the history
yck1509 committed Dec 23, 2014
1 parent 5f37fe4 commit e0d6051
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Confuser.Core/ProtectionPipeline.cs
Original file line number Diff line number Diff line change
@@ -173,7 +173,7 @@ private static IList<IDnlibDef> Filter(ConfuserContext context, IList<IDnlibDef>
ProtectionSettings parameters = ProtectionParameters.GetParameters(context, def);
Debug.Assert(parameters != null);
if (parameters == null) {
context.Logger.ErrorFormat("'{0}' not marked for obfuscation, possibly a bug.");
context.Logger.ErrorFormat("'{0}' not marked for obfuscation, possibly a bug.", def);
throw new ConfuserException(null);
}
return parameters.ContainsKey(phase.Parent);
10 changes: 8 additions & 2 deletions Confuser.Protections/AntiTamper/AntiTamperProtection.cs
Original file line number Diff line number Diff line change
@@ -5,8 +5,14 @@
using dnlib.DotNet;

namespace Confuser.Protections {
public interface IAntiTamperService {

void ExcludeMethod(ConfuserContext context, MethodDef method);

}

[BeforeProtection("Ki.ControlFlow"), AfterProtection("Ki.Constants")]
internal class AntiTamperProtection : Protection {
internal class AntiTamperProtection : Protection, IAntiTamperService {

public const string _Id = "anti tamper";
public const string _FullId = "Ki.AntiTamper";
@@ -34,7 +40,7 @@ public override ProtectionPreset Preset {
}

protected override void Initialize(ConfuserContext context) {
//
context.Registry.RegisterService(_ServiceId, typeof(IAntiTamperService), this);
}

protected override void PopulatePipeline(ProtectionPipeline pipeline) {
14 changes: 7 additions & 7 deletions Confuser.Protections/AntiTamper/JITMode.cs
Original file line number Diff line number Diff line change
@@ -140,6 +140,13 @@ public void HandleInject(AntiTamperProtection parent, ConfuserContext context, P
}

public void HandleMD(AntiTamperProtection parent, ConfuserContext context, ProtectionParameters parameters) {
// move initialization away from module initializer
cctorRepl.Body = cctor.Body;
cctor.Body = new CilBody();
cctor.Body.Instructions.Add(Instruction.Create(OpCodes.Call, initMethod));
cctor.Body.Instructions.Add(Instruction.Create(OpCodes.Call, cctorRepl));
cctor.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));

methods = parameters.Targets.OfType<MethodDef>().Where(method => method.HasBody).ToList();
context.CurrentModuleWriterListener.OnWriterEvent += OnWriterEvent;
}
@@ -199,13 +206,6 @@ private void CreateSection(ModuleWriter writer) {
var bodyIndex = new JITBodyIndex(methods.Select(method => writer.MetaData.GetToken(method).Raw));
newSection.Add(bodyIndex, 0x10);

// move initialization away from module initializer
cctorRepl.Body = cctor.Body;
cctor.Body = new CilBody();
cctor.Body.Instructions.Add(Instruction.Create(OpCodes.Call, initMethod));
cctor.Body.Instructions.Add(Instruction.Create(OpCodes.Call, cctorRepl));
cctor.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));

// save methods
foreach (MethodDef method in methods.WithProgress(context.Logger)) {
if (!method.HasBody)
2 changes: 1 addition & 1 deletion Confuser.Protections/ControlFlow/ExpressionPredicate.cs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public void Init(CilBody body) {
public void EmitSwitchLoad(IList<Instruction> instrs) {
instrs.Add(Instruction.Create(OpCodes.Stloc, stateVar));
foreach (Instruction instr in invCompiled)
instrs.Add(instr);
instrs.Add(instr.Clone());
}

public int GetSwitchKey(int key) {

0 comments on commit e0d6051

Please sign in to comment.