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

Commit

Permalink
Minor addition to ref proxy API
Browse files Browse the repository at this point in the history
  • Loading branch information
yck1509 committed Dec 6, 2015
1 parent 87347c4 commit 5956662
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Confuser.Protections/ReferenceProxy/MildMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public override void ProcessCall(RPContext ctx, int instrIndex) {
}
else
invoke.Operand = proxy;

var targetDef = target.ResolveMethodDef();
if (targetDef != null)
ctx.Context.Annotations.Set(targetDef, ReferenceProxyProtection.Targeted, ReferenceProxyProtection.Targeted);
}

public override void Finalize(RPContext ctx) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Confuser.Protections {
public interface IReferenceProxyService {
void ExcludeMethod(ConfuserContext context, MethodDef method);
void ExcludeTarget(ConfuserContext context, MethodDef method);
bool IsTargeted(ConfuserContext context, MethodDef method);
}

[AfterProtection("Ki.AntiDebug", "Ki.AntiDump")]
Expand All @@ -17,6 +18,7 @@ internal class ReferenceProxyProtection : Protection, IReferenceProxyService {
public const string _ServiceId = "Ki.RefProxy";

internal static object TargetExcluded = new object();
internal static object Targeted = new object();

public override string Name {
get { return "Reference Proxy Protection"; }
Expand Down Expand Up @@ -46,6 +48,10 @@ public void ExcludeTarget(ConfuserContext context, MethodDef method) {
context.Annotations.Set(method, TargetExcluded, TargetExcluded);
}

public bool IsTargeted(ConfuserContext context, MethodDef method) {
return context.Annotations.Get<object>(method, Targeted) != null;
}

protected override void Initialize(ConfuserContext context) {
context.Registry.RegisterService(_ServiceId, typeof(IReferenceProxyService), this);
}
Expand Down
8 changes: 8 additions & 0 deletions Confuser.Protections/ReferenceProxy/StrongMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ void ProcessBridge(RPContext ctx, int instrIndex) {
// Replace instruction
instr.OpCode = OpCodes.Call;
instr.Operand = proxy.Item2;

var targetDef = target.ResolveMethodDef();
if (targetDef != null)
ctx.Context.Annotations.Set(targetDef, ReferenceProxyProtection.Targeted, ReferenceProxyProtection.Targeted);
}

void ProcessInvoke(RPContext ctx, int instrIndex, int argBeginIndex) {
Expand Down Expand Up @@ -161,6 +165,10 @@ void ProcessInvoke(RPContext ctx, int instrIndex, int argBeginIndex) {
instr.OpCode = OpCodes.Call;
instr.Operand = delegateType.FindMethod("Invoke");
}

var targetDef = target.ResolveMethodDef();
if (targetDef != null)
ctx.Context.Annotations.Set(targetDef, ReferenceProxyProtection.Targeted, ReferenceProxyProtection.Targeted);
}

MethodDef CreateBridge(RPContext ctx, TypeDef delegateType, FieldDef field, MethodSig sig) {
Expand Down

0 comments on commit 5956662

Please sign in to comment.