Skip to content

Commit 110b096

Browse files
author
RandomCrocodile
committed
feature: randomize anti-tamper feedback constant per run (#69)
Phase 2 of #69 (Level 2 identity). The anti-tamper method-body cipher used a hardcoded feedback constant 0x3dbb2819 in both the obfuscator (encrypt) and the injected runtime (decrypt) — a value de4dot signature-matches to identify ConfuserEx. Normal and Anti modes now generate a random per-run feedback value, use it in the encryption loop, and inject it into the runtime via a new Mutation key (KeyI5), exactly like the existing z/x/c/v hash constants (KeyI1-4). Obfuscator and runtime stay in sync automatically because the same generated value is both used and injected. JIT mode is intentionally left unchanged — its runtime component is already broken and its test is skipped, so a crypto change there cannot be validated. Validated by AntiTamper.Test: the obfuscated app decrypts its own method bodies at runtime and produces correct output (exit 42) for both Normal and Anti modes.
1 parent 495ee4c commit 110b096

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Visual Studio Cache files (starting with VS 2015)
22
.vs/
3+
.temp
34

45
# Launch Settings
56
launchSettings.json

Confuser.Protections/AntiTamper/AntiMode.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Confuser.Protections.AntiTamper {
1717
internal class AntiMode : IModeHandler {
1818
uint c;
19+
uint feedback;
1920
IKeyDeriver deriver;
2021

2122
List<MethodDef> methods;
@@ -31,6 +32,7 @@ public void HandleInject(AntiTamperProtection parent, ConfuserContext context, P
3132
x = random.NextUInt32();
3233
c = random.NextUInt32();
3334
v = random.NextUInt32();
35+
feedback = random.NextUInt32();
3436
name1 = random.NextUInt32() & 0x7f7f7f7f;
3537
name2 = random.NextUInt32() & 0x7f7f7f7f;
3638

@@ -77,8 +79,8 @@ public void HandleInject(AntiTamperProtection parent, ConfuserContext context, P
7779
initMethod.Body.Instructions.Add(instr);
7880

7981
MutationHelper.InjectKeys(initMethod,
80-
new[] { 0, 1, 2, 3, 4 },
81-
new[] { (int)(name1 * name2), (int)z, (int)x, (int)c, (int)v });
82+
new[] { 0, 1, 2, 3, 4, 5 },
83+
new[] { (int)(name1 * name2), (int)z, (int)x, (int)c, (int)v, (int)feedback });
8284

8385
var name = context.Registry.GetService<INameService>();
8486
var marker = context.Registry.GetService<IMarkerService>();
@@ -219,7 +221,7 @@ void EncryptSection(ModuleWriterBase writer) {
219221
for (uint i = 0; i < encSize; i++) {
220222
uint data = reader.ReadUInt32();
221223
result[i] = data ^ key[i & 0xf];
222-
key[i & 0xf] = (key[i & 0xf] ^ data) + 0x3dbb2819;
224+
key[i & 0xf] = (key[i & 0xf] ^ data) + feedback;
223225
}
224226
var byteResult = new byte[encSize << 2];
225227
Buffer.BlockCopy(result, 0, byteResult, 0, byteResult.Length);

Confuser.Protections/AntiTamper/NormalMode.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Confuser.Protections.AntiTamper {
1717
internal class NormalMode : IModeHandler {
1818
uint c;
19+
uint feedback;
1920
IKeyDeriver deriver;
2021

2122
List<MethodDef> methods;
@@ -31,6 +32,7 @@ public void HandleInject(AntiTamperProtection parent, ConfuserContext context, P
3132
x = random.NextUInt32();
3233
c = random.NextUInt32();
3334
v = random.NextUInt32();
35+
feedback = random.NextUInt32();
3436
name1 = random.NextUInt32() & 0x7f7f7f7f;
3537
name2 = random.NextUInt32() & 0x7f7f7f7f;
3638

@@ -77,8 +79,8 @@ public void HandleInject(AntiTamperProtection parent, ConfuserContext context, P
7779
initMethod.Body.Instructions.Add(instr);
7880

7981
MutationHelper.InjectKeys(initMethod,
80-
new[] { 0, 1, 2, 3, 4 },
81-
new[] { (int)(name1 * name2), (int)z, (int)x, (int)c, (int)v });
82+
new[] { 0, 1, 2, 3, 4, 5 },
83+
new[] { (int)(name1 * name2), (int)z, (int)x, (int)c, (int)v, (int)feedback });
8284

8385
var name = context.Registry.GetService<INameService>();
8486
var marker = context.Registry.GetService<IMarkerService>();
@@ -220,7 +222,7 @@ void EncryptSection(ModuleWriterBase writer) {
220222
for (uint i = 0; i < encSize; i++) {
221223
uint data = reader.ReadUInt32();
222224
result[i] = data ^ key[i & 0xf];
223-
key[i & 0xf] = (key[i & 0xf] ^ data) + 0x3dbb2819;
225+
key[i & 0xf] = (key[i & 0xf] ^ data) + feedback;
224226
}
225227
var byteResult = new byte[encSize << 2];
226228
Buffer.BlockCopy(result, 0, byteResult, 0, byteResult.Length);

Confuser.Runtime/AntiTamper.Anti.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static unsafe void Initialize() {
2727
uint l = 0;
2828
var r = (uint*)(p + 0x18 + o);
2929
uint z = (uint)Mutation.KeyI1, x = (uint)Mutation.KeyI2, c = (uint)Mutation.KeyI3, v = (uint)Mutation.KeyI4;
30+
uint fb = (uint)Mutation.KeyI5;
3031

3132
CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);
3233
if (isDebuggerPresent) Environment.FailFast(null);
@@ -80,7 +81,7 @@ static unsafe void Initialize() {
8081
uint h = 0;
8182
for (uint i = 0; i < l; i++) {
8283
*e ^= y[h & 0xf];
83-
y[h & 0xf] = (y[h & 0xf] ^ (*e++)) + 0x3dbb2819;
84+
y[h & 0xf] = (y[h & 0xf] ^ (*e++)) + fb;
8485

8586
CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);
8687
if (isDebuggerPresent) Environment.FailFast(null);

Confuser.Runtime/AntiTamper.Normal.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static unsafe void Initialize() {
2020
uint l = 0;
2121
var r = (uint*)(p + 0x18 + o);
2222
uint z = (uint)Mutation.KeyI1, x = (uint)Mutation.KeyI2, c = (uint)Mutation.KeyI3, v = (uint)Mutation.KeyI4;
23+
uint fb = (uint)Mutation.KeyI5;
2324
for (int i = 0; i < s; i++) {
2425
uint g = (*r++) * (*r++);
2526
if (g == (uint)Mutation.KeyI0) {
@@ -60,7 +61,7 @@ static unsafe void Initialize() {
6061
uint h = 0;
6162
for (uint i = 0; i < l; i++) {
6263
*e ^= y[h & 0xf];
63-
y[h & 0xf] = (y[h & 0xf] ^ (*e++)) + 0x3dbb2819;
64+
y[h & 0xf] = (y[h & 0xf] ^ (*e++)) + fb;
6465
h++;
6566
}
6667
}

0 commit comments

Comments
 (0)