Constants Encryption Enterprise
Integer constants in .NET IL (ldc.i4, ldc.i8) reveal magic numbers, buffer sizes, protocol constants, and algorithm parameters. Demeanor replaces each constant with an equivalent inline arithmetic expression that evaluates to the same value at runtime — with zero method-call overhead.
Usage
| CLI | MSBuild | Default |
|---|---|---|
| (enabled by default at Enterprise) | <ObfuscateEncryptConstants>true</ObfuscateEncryptConstants> | On |
--no-constants | <ObfuscateEncryptConstants>false</ObfuscateEncryptConstants> | Disable |
Before & After
private const int MaxTrialDays = 30;
private const int GracePeriodDays = 7;
if (key.Length != 25 || key[5] != '-')
return false;
foreach (char c in key.Where(char.IsLetterOrDigit))
checksum = (checksum * 31 + c) & 0x7FFFFFFF;
return checksum % 97 == 0;// 30 → arithmetic expression
if (days > -505527931 - -505527968)
// 25 → multiplication + addition
if (a.Length != -12946822 * -879980427 + 556600919)
// 31 → multiplication + addition
num = (num * (1327598100 * 806479407 + 1802874483) + item)
// 97 → bitwise arithmetic
return num % (0x2452FFEB ^ 0x2452FF8A) == 0;Real ILSpy output. Every integer constant — 30, 7, 25, 31, 97, even 100 for the decimal division — is replaced with an arithmetic expression. Multiple encoding modes are randomly selected per constant.
How It Works
Each ldc.i4 / ldc.i4.s / ldc.i4.0–ldc.i4.8 / ldc.i4.m1 / ldc.i8 instruction is replaced with 2-3 IL instructions that compute the same value. The JIT compiler folds these at compile time in Release builds — there is literally zero runtime overhead. The expressions use large random operands so the original value cannot be guessed from the arithmetic.
When to Disable
- IL size constraints — each constant expands from 1-5 bytes to 9-13 bytes. For assemblies near the 4 GB .text section limit this matters (extremely rare).
- In practice, there is no reason to disable this feature. It has zero runtime cost and significantly increases the effort required to understand your code.
Ready to protect your .NET code?