DEV Community

Zero Heartbeat
Zero Heartbeat

Posted on Originally published at delta1labs.com

Hiding sensitive calls behind proxy methods

Rename every symbol, encrypt every string, and a decompiler still prints one line that hands an attacker a map: call bool Licensing.LicenseCheck::Verify(string). The method name may be mangled, but the edge is right there — this method calls that method — and so is the fully-qualified target when the callee is a BCL type like System.Security.Cryptography.Aes or RSA.VerifyData. Reading a protected assembly often starts with "find every call into Cryptography" and working outward. Those call sites are a search index into your logic.

Proxy-call obfuscation — sometimes called reference obfuscation — takes that index away. It replaces the direct call/callvirt with a jump through an injected intermediary, so the decompiled caller no longer shows a clear edge to the sensitive method, and the method's name is no longer sitting in the call site's token.

This is a deep look at how that works at the IL level: three real forms of indirection, the before/after IL for each, what they actually hide, and the honest cost.

What a direct call gives away

Start with an ordinary guard:

public bool Activate(string key)
{
    return LicenseCheck.Verify(key);
}
Enter fullscreen mode Exit fullscreen mode

The IL is exactly what you'd expect — load the argument, call the target by its full metadata token, return:

.method public instance bool Activate(string key)
{
  IL_0000: ldarg.1
  IL_0001: call      bool Licensing.LicenseCheck::Verify(string)
  IL_0006: ret
}
Enter fullscreen mode Exit fullscreen mode

Two facts leak from IL_0001. First, the name and signature of the target are encoded in the MemberRef/MethodDef token the call points at — a decompiler resolves it and prints LicenseCheck::Verify. Second, the call-graph edge Activate → Verify is explicit: any tool that walks call instructions draws that arrow for free. Chain those arrows and you have the control structure of the program before you've read a single algorithm.

The idea: put something in the middle

Every proxy form shares one move — insert an intermediary the caller invokes instead, and have that reach the real target by a route the static call-instruction scan does not follow.


A direct call edge is replaced by a proxy that reaches the target without a static call instruction


The caller's direct edge to the target is cut; it now calls a proxy, which reaches the target through a delegate, a metadata token, or a function pointer rather than a plain call.

Form 1 — a cached delegate

The caller invokes a Func<> delegate instead of the method. The delegate is built once, with ldftn + the delegate constructor, and cached in a static field:

// injected by Nebula
static Func<string, bool> __p0;

static bool Proxy0(string key)
{
    Func<string, bool> d = __p0 ?? (__p0 = BuildP0());
    return d(key);
}

static Func<string, bool> BuildP0()
{
    // ldftn target + Func`2::.ctor
    return new Func<string, bool>(LicenseCheck.Verify);
}

public bool Activate(string key) => Proxy0(key);   // was: LicenseCheck.Verify(key)
Enter fullscreen mode Exit fullscreen mode

In Activate, the call LicenseCheck::Verify is gone. The only call instruction left at the site is a callvirt into the delegate's Invoke:

IL_0000: ldarg.1
IL_0001: call      bool App.Stubs::Proxy0(string)
IL_0006: ret
// inside Proxy0, the actual invocation:
IL_000a: callvirt  instance bool class [System.Runtime]System.Func`2<string,bool>::Invoke(string)
Enter fullscreen mode Exit fullscreen mode

A tool that indexes call targets now records a call to Func.Invoke — which every delegate in the program shares — not to Verify. The call-graph edge Activate → Verify is broken. The target name still appears once, in the ldftn inside BuildP0, but it's no longer at the use site and no longer tied to Activate; fan a hundred proxies through one builder table and the edges all collapse into a single anonymous hub.

Form 2 — reflection by token

Delegate construction still leaves an ldftn <name> in the IL. To remove the name entirely, resolve the target from its numeric metadata token at runtime:

static MethodInfo __m0;

static bool Proxy0(string key)
{
    MethodInfo m = __m0 ?? (__m0 =
        (MethodInfo)typeof(Proxy0Host).Module.ResolveMethod(0x06000012));
    return (bool)m.Invoke(null, new object[] { key });
}
Enter fullscreen mode Exit fullscreen mode

Now the IL contains no reference to Verify at all — only the integer 0x06000012 handed to Module.ResolveMethod:

IL_0007: ldc.i4    0x06000012
IL_000c: callvirt  instance class [System.Runtime]System.Reflection.MethodBase
                    [System.Runtime]System.Reflection.Module::ResolveMethod(int32)
IL_0018: callvirt  instance object
                    [System.Runtime]System.Reflection.MethodInfo::Invoke(object, object[])
Enter fullscreen mode Exit fullscreen mode

A casual decompile shows a reflection call against an opaque number. The name is recoverable — the token resolves against the same module's #~ tables — but that is a deliberate step an analyst must take, not a label the decompiler hands them. Mask the constant with an opaque arithmetic expression and even the token isn't a plain literal.

Form 3 — calli through a function pointer

The lowest-level form uses the calli instruction, which calls through a function pointer on the stack against an explicit signature. If the pointer is loaded from a table (or computed) rather than via a literal ldftn <name>, the call site names neither a method nor a delegate type:

// fnptr pushed from a runtime-built table, not ldftn <name>
IL_0005: ldarg.1
IL_0006: ldsfld    native int App.Stubs::_ptr0
IL_000b: calli     bool(string)
Enter fullscreen mode Exit fullscreen mode

calli is the most efficient of the three — no delegate allocation, no reflection — but it is also the most fragile: the signature is hand-encoded as a standalone signature token, and a wrong pointer is an immediate crash rather than an exception.

Turning it on

Proxy calls live under their own block in nebula.config.json, scoped to the namespaces whose call sites you most want to hide:

{
  "renaming": { "mode": "dictionary" },
  "encryptStrings": true,
  "proxyCalls": {
    "enabled": true,
    "mode": "delegate",
    "scope": ["MyApp.Licensing", "MyApp.Crypto"],
    "cacheDelegates": true
  }
}
Enter fullscreen mode Exit fullscreen mode

Then run the obfuscator over your built assembly:

nebula protect ./bin/Release/net8.0/App.dll \
  --config nebula.config.json \
  --out ./protected/
Enter fullscreen mode Exit fullscreen mode

mode picks the indirection: delegate (fast, keeps a static ldftn reference — safe for trimming), reflection (hides the name via token, costly and linker-hostile), or calli (fastest indirection, no name, most fragile). scope is the dial that matters: proxying every call bloats the assembly and taxes startup, so point it at the methods that actually reach your IP — licence verification, key derivation, crypto, sensitive P/Invoke — and leave hot inner loops alone.

The cost, honestly

Indirection is never free, and the three forms are not equally cheap.

  • Performance. A cached-delegate call is a virtual dispatch plus the delegate's own indirection — nanoseconds, fine outside a tight loop. calli is similar. Reflection is in a different universe: MethodInfo.Invoke is on the order of hundreds of times slower than a direct call and boxes every argument and the return value into object, allocating on each invocation. Never put a reflection proxy on a hot path.
  • Trimming and AOT. This is the sharp edge. A trimmer and the NativeAOT compiler decide what to keep by following static calls. A reflection proxy's target is reachable only through a token inside Invoke, which they cannot see — so the target may be trimmed away or fail to resolve under AOT, turning a hidden call into a runtime MissingMethodException. Delegate and calli proxies keep a static ldftn reference, so the linker still roots the target. If you publish trimmed or AOT, prefer delegate and verify with a published build.
  • Debuggability. A proxied stack trace shows Proxy0 → Func.Invoke instead of your real method, and reflection frames are noisy. Keep your renaming/symbol artifacts so you can retrace production traces back to source.

Where it breaks

Be clear-eyed about what this does and does not buy. Proxy calls defeat the cheap attack — the call-instruction scan and the auto-generated call graph that a decompiler or a tool like de4dot produces in one click. They do not defeat a determined analyst. The delegate target, the resolved token, and the function pointer all point somewhere real at runtime, and dataflow analysis or a single breakpoint on Invoke recovers it. What changes is the cost: "list every call into Cryptography" stops being a menu item and becomes a per-site investigation. Combined with renaming, string encryption and control-flow obfuscation, that is often the difference between a one-afternoon decompile and a project an attacker has to decide is worth their week.

Which tier

Delegate and token-based proxy calls are a Pro feature, alongside code virtualization and method encryption. The most aggressive variant — reflection with runtime-computed tokens, correlated with the aggressive control-flow tier so the proxy dispatch is itself buried in bogus branches — is Enterprise. As always, it is legitimate protection for your own IP: raise the floor across the whole assembly with renaming and strings, then spend proxy indirection where the sensitive edges actually are. See Nebula.NET and the documentation.

Top comments (0)