A one-shot header scrub has a gap, and the gap is timing. The common anti-dump move is to let the CLR load your module and then overwrite the PE headers the runtime no longer needs. It stops the laziest tools. But it leaves two openings. Anything the CLR does still read — the metadata stream directory above all — stays in memory in canonical form for the life of the process. And any dumper that snapshots before your scrub runs gets a pristine image anyway. Nebula.NET's anti-dump closes both by inverting the model: scramble more than a one-shot scrub dares to, including structures the runtime will need again, and keep the real bytes valid only for the moments the CLR is reading them.

This is a protection for software vendors hardening their own assemblies. The point is to raise the cost of the one-click "run it, dump it, open it" path that turns a decrypted live process into a clean file in under a minute — not to make extraction impossible, which nothing running on a machine you do not control can do.

The real question

A memory dumper does not break your on-disk file. It lets your own process decrypt its strings and JIT its methods, then carves the mapped image and writes a .dll. To do that it needs a chain of structures still standing: the DOS header's e_lfanew, the NT headers, the section table, the IMAGE_COR20_HEADER, and — the part that is easy to forget — the metadata stream directory that says where the #~, #Strings, #US, #GUID and #Blob heaps live inside the metadata blob.

A one-shot scrub can safely erase the first few, because the loader read them once and is done. It cannot safely erase the stream directory, because the CLR re-reads it lazily: the first time you reflect over a type, instantiate a generic, or resolve an exception type, the runtime walks those streams again. So the stream directory survives — and that is exactly the structure a dumper most wants. The real question is whether you can scramble a structure the runtime still needs and still run.

Walking the chain the attacker walks

The scrub reads the same offsets the dumper reads. They are fixed, and worth stating exactly, because every one is a target:

// Illustrative: locating the module's own metadata root from its mapped image. // Nebula's real pass is native-first and obfuscated; this is the offset map. static unsafe byte* FindMetadataRoot(Module module, out int size) { byte* b = (byte*)Marshal.GetHINSTANCE(module); // mapped image base int e_lfanew = *(int*)(b + 0x3C); // DOS -> "PE\0\0" byte* nt = b + e_lfanew; short magic = *(short*)(nt + 0x18); // 0x10B PE32 / 0x20B PE32+ int ddOffset = (magic == 0x20B) ? 0x70 : 0x60; // data directories byte* dd = nt + 0x18 + ddOffset; int cor20Rva = *(int*)(dd + 14 * 8); // dir 14 = CLI header byte* cor20 = b + cor20Rva; // IMAGE_COR20_HEADER int metaRva = *(int*)(cor20 + 8); // MetaData.VirtualAddress size = *(int*)(cor20 + 12); // MetaData.Size return b + metaRva; // begins with 'BSJB' } 

The metadata root is the richer target. Its layout is fixed by ECMA-335:

// At the metadata root (offsets relative to the root pointer): // 0x00 Signature uint = 0x424A5342 ('B','S','J','B') // 0x04 MajorVersion ushort // 0x06 MinorVersion ushort // 0x08 Reserved uint = 0 // 0x0C Length uint = version-string length, rounded up to 4 // 0x10 Version byte[Length] e.g. "v4.0.30319" // then Flags ushort // Streams ushort = number of stream headers that follow // then StreamHeader[Streams]: // Offset uint (relative to the metadata root) // Size uint // Name null-terminated ASCII, padded to a 4-byte boundary 

Those stream headers are the map. #~ (or #- when uncompressed) is the table stream; #Strings, #US, #GUID and #Blob are the heaps. Erase the Streams count and the per-stream Offset/Size/Name records and a carved image still holds every metadata table — but nothing that says where any of them begins. A decompiler opening it reports a corrupt metadata root and stops. That is the structure Nebula wants scrambled, and the one a one-shot scrub must leave alone.

Scramble, then restore on demand

Because the CLR reads the stream directory again, Nebula cannot simply destroy it. Instead the startup pass keeps an encrypted copy of every byte range it is about to corrupt, scrambles the originals in place, and watches for the runtime to come asking. When the CLR needs the stream directory, Nebula restores the real bytes from the encrypted copy, lets the runtime take its reading, and re-scrambles behind it. The structure is canonical only while the CLR is actively consuming it — a short, runtime-driven window — and scrambled the rest of the time, which is all of the time a dumper is likely scanning.

// Conceptual shape of the lazy-restore bookkeeping (native-first in the real pass). sealed class CloakedRegion { readonly byte[] _cipher; // encrypted copy of the real header bytes readonly IntPtr _addr; // where they live in the mapped image readonly int _len; public CloakedRegion(IntPtr addr, int len) { _addr = addr; _len = len; _cipher = Encrypt(ReadBytes(addr, len)); // stash before scrambling Scramble(addr, len); // corrupt the in-memory copy } // Called when the CLR is about to read this region, and only then. public void WithRealBytes(Action read) { WriteBytes(_addr, Decrypt(_cipher)); // canonical for this read try { read(); } finally { Scramble(_addr, _len); } // and gone again } } 

The scramble itself is not a blunt zero-fill. Zeroed fields are themselves a signature — a region of nulls where a BSJB root should sit tells a reconstructor exactly what to rebuild and where. Nebula overwrites with values shaped like plausible-but-wrong headers: a non-zero but invalid signature, stream Offsets that point outside the blob, a Streams count that disagrees with the records that follow. A tool that trusts the headers follows them into garbage; a tool that distrusts them has to rebuild the map from scratch.

A dumper reads base + RVA straight out of the mapped image and gets scrambled headers with an invalid metadata root. The CLR gets the real bytes restored from an encrypted stash only for each read, then they are scrambled again.

Why it has to run first

The value of anti-dump is timing. If an attacker snapshots the process before the stub executes, the headers are still pristine and you have protected nothing. So Nebula does not emit this as ordinary C# that happens to run early; it wires the scramble into the module's load path — a native-first entry that executes ahead of managed Main — so by the time any of your code, or any breakpoint, is reachable, the headers are already cloaked.

That also means the stub cannot be a tidy, findable method. A single AntiDump() an attacker can locate and NOP defeats the whole thing, so the logic is obfuscated, inlined into the load path, and its constants derived rather than stored — the same discipline behind self-integrity checks.

Turning it on

Anti-dump is a toggle in the protection config, applied as a startup pass:

{ "renaming": { "mode": "dictionary" }, "encryptStrings": true, "antiDump": { "enabled": true, "lazyRestore": true }, "antiTamper": { "enabled": true }, "antiDebug": { "enabled": true } } 
nebula protect ./bin/Release/net8.0/Billing.dll \ --config nebula.config.json \ --out ./protected/ 

There is no per-method scoping — anti-dump is module-wide by nature, because it operates on the module's own headers. The cost is a small, bounded allocation for the encrypted stash and a little work on each restore; the overhead is paid against metadata reads, not your hot path. Install the CLI with dotnet tool install --global Delta1Labs.Nebula.Tool.

Where it stops — honestly

Anti-dump has a specific job and a specific blind spot, and selling past either is how you end up with false confidence in production.

  • It defeats scanners, not reconstructors. A dumper that carves the raw mapped image is blocked. A tool that rebuilds a module from the CLR's own runtime structures — walking type and method tables through the debugging/DAC surface rather than reading your PE headers — never looks at the bytes you scrambled. Those tools are slower and often produce a broken module, but header cloaking does not stop them by itself. Pair it with anti-debug so that attaching the kind of process that drives a DAC dumper is itself detected.
  • The restore window is real. The headers are canonical for the instant the CLR reads them. An attacker who can reliably stall the process inside that window, or who can read the encrypted stash and the restore logic, can defeat the cloak. Lazy restore shrinks the window from the whole process lifetime to a sliver; it does not remove it.
  • It does not re-encrypt what the runtime decrypted. Once your code has run, decrypted strings and JIT-compiled bodies live in memory in cleartext. Anti-dump makes the module hard to carve as a valid assembly; it does not scrub every secret from the heap. Scope sensitive strings so they decrypt late and are not held, and lean on encrypted method bodies and code virtualization for the handful of methods whose logic must never be recovered.
  • Layout-dependent. Single-file bundles, ReadyToRun images and NativeAOT change the PE/CLI layout the stub walks. Nebula adapts the pass to the output kind, but verify your protected build actually starts in the target deployment shape before you rely on it.

The mental model runs through every protection in the suite. Anti-dump does not make your assembly impossible to extract; it removes the cheapest extraction and forces an attacker onto the slow, fragile tools. Combined with anti-tamper and anti-debug, that is the difference between a minute's work and a project someone has to decide is worth their week.

See the Nebula.NET docs to add anti-dump to your protection profile, then dump your own protected build and watch the carved file refuse to open.