Stopping a memory dump from recovering your assembly
Renaming and string encryption are undone if an attacker just dumps your running process back to disk. How Nebula.NET anti-dump relocates and scrubs the in-memory PE and metadata headers so a carved image is unusable — with the real offsets, C#, an SVG of the carve path, and the honest limits.
Rename every type, encrypt every string, flatten every branch — and an attacker can skip all of it with one move: let your program start, then copy the assembly straight out of its own memory and open that in a decompiler. The runtime has already done the hard part. Strings are decrypted on first use, metadata is resolved, the JIT has the real tokens. A process dump captures a module that is, in some ways, cleaner than the file you shipped.
This is the attack obfuscation alone does nothing about, and the countermeasure — anti-dump — is one of the more misunderstood protections in the box. Here’s exactly what a dumper relies on, how Nebula.NET takes it away, and where the technique stops.
What a dumper actually does
A managed assembly is a PE file. When the CLR loads it, the loader maps that PE into the process’s address space as an image: each section lands at its virtual address, so an in-memory pointer is just base + RVA. A dump tool exploits that regular layout. The steps are mechanical:
- Enumerate loaded modules (or scan committed memory for an
MZDOS header followed by aPE\0\0signature). - Walk the headers to the CLI header (the
IMAGE_COR20_HEADER, data directory entry 14), and from it read theMetaDatadirectory — the RVA and size of the metadata root that begins with the ASCII signatureBSJB. - Carve the mapped image out of memory, “unmap” it (rewrite section RVAs back to raw file offsets so the bytes form a valid on-disk PE again), and write a
.dll. - Open it in dnSpy/ILSpy. Every name you renamed is still renamed — but every string your code already touched is sitting there in cleartext, and the module runs.
The whole attack rests on one assumption: that the PE headers and the metadata root are still in memory, in canonical form, where a scanner can find them. Anti-dump breaks that assumption.
The idea: move the metadata, scrub the original
You cannot simply zero the metadata after load — the CLR needs it for reflection, generic instantiation, and exception type resolution for the life of the process. So Nebula does something more surgical, in a startup stub that runs before any of your code:
- Find this module’s own base address.
- Allocate a fresh private region, copy the metadata there, and rewrite the in-memory CLI header’s
MetaDataRVA so the runtime follows the copy. The CLR keeps working — it reads the patched pointer. - Scrub the original: overwrite the
BSJBsignature and the header fields in the mapped image that a scanner keys on.
Now a dumper that carves the mapped image copies a scrubbed region. The CLI header points at metadata that has been overwritten; the BSJB signature is gone. The carved file is not a loadable assembly, and a tool that follows the directory lands on garbage — while your process, following the relocated pointer, runs normally.
To do any of this, the stub has to read the header chain by hand. The offsets are fixed and worth knowing, because they are exactly what the attacker’s tool reads too:
// Illustrative: how the startup stub locates its own CLI header and metadata.
// Real injection is native-first, obfuscated, and runs before your Main.
static unsafe (IntPtr metaRoot, int metaSize) FindMetadata(Module module)
{
byte* base_ = (byte*)Marshal.GetHINSTANCE(module); // mapped image base
int e_lfanew = *(int*)(base_ + 0x3C); // -> PE signature
byte* nt = base_ + e_lfanew; // "PE\0\0"
short magic = *(short*)(nt + 0x18); // optional header magic
// data directories start at 0x60 (PE32) or 0x70 (PE32+)
int ddOffset = (magic == 0x20B) ? 0x70 : 0x60;
byte* dataDirs = nt + 0x18 + ddOffset;
// entry 14 = IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR (CLI header)
int cor20Rva = *(int*)(dataDirs + 14 * 8);
byte* cor20 = base_ + cor20Rva; // IMAGE_COR20_HEADER
int metaRva = *(int*)(cor20 + 8); // MetaData.VirtualAddress
int metaSize = *(int*)(cor20 + 12); // MetaData.Size
return ((IntPtr)(base_ + metaRva), metaSize); // begins with 'BSJB'
}
Every number there is a real PE/CLI offset: e_lfanew at 0x3C, the optional-header magic at 0x18 into the NT headers, the CLI header at data directory index 14, and the MetaData directory at offset 8 inside the 72-byte IMAGE_COR20_HEADER. The relocation step then VirtualProtects the header page writable, rewrites *(int*)(cor20 + 8) to the new RVA, and overwrites the first four bytes at the old metadata root (the BSJB magic) so no scanner can re-find it.
base + RVA straight out of the mapped image. Anti-dump relocates the metadata and scrubs the BSJB root in place, so the carved copy has no readable metadata while the live process follows the patched CLI header.Why it has to run first
The entire value of anti-dump is timing. If an attacker snapshots the process before your stub executes, the headers are still pristine and you have protected nothing. That is why Nebula does not emit this as ordinary C# that happens to run early — it wires the scrub 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 anyone’s breakpoint, is reachable, the headers are already moved and scrubbed.
It also means the stub cannot be a tidy, findable method. A single AntiDump() an attacker can locate and NOP in a debugger defeats the whole thing, so the relocation logic is obfuscated, inlined into the load path, and its constants are derived rather than stored — the same discipline that makes anti-tamper worth shipping.
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 },
"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 here — anti-dump is module-wide by nature, because it operates on the module’s own headers. The cost is a few microseconds at startup and one private allocation the size of your metadata stream, paid once per process. 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 scrubbed. Those tools are slower and clumsier, and they often produce a broken module, but anti-dump does not stop them by itself. Pair it with anti-debug so attaching the kind of process that drives a DAC dumper is itself detected.
- It does not re-encrypt what the runtime decrypted. Once your code has run, decrypted strings and JIT-compiled method 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 are decrypted late and not held, and lean on code virtualization for the handful of methods whose logic — not just their names — 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 is the same one that runs through every protection in the suite. Anti-dump does not make your assembly impossible to extract — nothing running on a machine you don’t control does. It removes the cheapest extraction: the one-click “run it, dump it, open it” that turns a decrypted live process into a clean file in under a minute. That path is how most casual lifting of managed IP happens, and closing it forces an attacker onto the slow, fragile tools — which, combined with anti-tamper and anti-debug, is the difference between a minute’s work and a project they have 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.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.