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

Commit

Permalink
Fix Windows 8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yck1509 committed Jul 5, 2014
1 parent f1df614 commit bacf24b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 8 additions & 5 deletions Confuser.Protections/AntiTamper/NormalMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public void HandleInject(AntiTamperProtection parent, ConfuserContext context, P
deriver.Init(context, random);

var rt = context.Registry.GetService<IRuntimeService>();
MethodDef initMethod = rt.GetRuntimeType("Confuser.Runtime.AntiTamperNormal").FindMethod("Initialize");
initMethod = InjectHelper.Inject(initMethod, context.CurrentModule);
context.CurrentModule.GlobalType.Methods.Add(initMethod);
TypeDef initType = rt.GetRuntimeType("Confuser.Runtime.AntiTamperNormal");
IEnumerable<IDnlibDef> members = InjectHelper.Inject(initType, context.CurrentModule.GlobalType, context.CurrentModule);
var initMethod = (MethodDef)members.Single(m => m.Name == "Initialize");

initMethod.Body.SimplifyMacros(initMethod.Parameters);
List<Instruction> instrs = initMethod.Body.Instructions.ToList();
Expand Down Expand Up @@ -81,13 +81,16 @@ public void HandleInject(AntiTamperProtection parent, ConfuserContext context, P

var name = context.Registry.GetService<INameService>();
var marker = context.Registry.GetService<IMarkerService>();
name.MarkHelper(initMethod, marker);
foreach (IDnlibDef def in members) {
name.MarkHelper(def, marker);
if (def is MethodDef)
parent.ExcludeMethod(context, (MethodDef)def);
}

MethodDef cctor = context.CurrentModule.GlobalType.FindStaticConstructor();
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, initMethod));

parent.ExcludeMethod(context, cctor);
parent.ExcludeMethod(context, initMethod);
}

public void HandleMD(AntiTamperProtection parent, ConfuserContext context, ProtectionParameters parameters) {
Expand Down
10 changes: 8 additions & 2 deletions Confuser.Runtime/AntiTamper.Normal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
using System.Runtime.InteropServices;

namespace Confuser.Runtime {
internal class AntiTamperNormal {
internal static class AntiTamperNormal {
[DllImport("kernel32.dll")]
private static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);

private static unsafe void Initialize() {
Module m = typeof (AntiTamperNormal).Module;
Module m = typeof(AntiTamperNormal).Module;
string n = m.FullyQualifiedName;
bool f = n.Length > 0 && n[0] == '<';
var b = (byte*)Marshal.GetHINSTANCE(m);
Expand Down Expand Up @@ -47,6 +50,9 @@ private static unsafe void Initialize() {
}
Mutation.Crypt(y, d);

uint w = 0x40;
VirtualProtect((IntPtr)e, l << 2, w, out w);

uint h = 0;
for (uint i = 0; i < l; i++) {
*e ^= y[h & 0xf];
Expand Down

0 comments on commit bacf24b

Please sign in to comment.