Open a .NET assembly in a decompiler and the methods are not the only thing on display. Click into the resources node and there they are: every embedded .resources stream, every bundled image, every configuration blob you compiled in — sitting in the PE as plaintext manifest resources. A right-click saves any of them to disk. One line of code does the same from outside your process:
using var s = assembly.GetManifestResourceStream("MyApp.Policy.resources");
For resources that are just UI strings, who cares. But teams embed more than that — a licensing policy table, a proprietary lookup set, a pricing matrix, an ML model, a template that encodes real know-how. Renaming the resource helps nobody: GetManifestResourceNames still lists it, and the bytes are still verbatim. The value is the content, and the content is in the clear.
So here is the real question: can you ship an embedded resource whose bytes a decompiler cannot read off the disk, without loading every resource into memory at startup or rewriting how your code asks for them? Nebula Pro's answer is to encrypt selected resource streams at protect time, replace the real stream with ciphertext, and inject a hook that decrypts the bytes into a MemoryStream only when the application actually resolves that resource. This post is how that works, which loader path you have to hook for it to survive contact with WPF and satellite assemblies, and where it still leaks.
What the decompiler sees today
A resource compiled into your assembly is a named entry in the manifest with its bytes stored contiguously in the resource section. GetManifestResourceNames enumerates the entries; GetManifestResourceStream hands back the bytes:
MyApp.Strings.resources (ResX-compiled, plaintext)
MyApp.Policy.bin (your licensing policy, plaintext)
MyApp.Assets.logo.png (plaintext)
Nothing there is secret from the tooling. The name is readable, the bytes are readable, and the format — a .resources stream has a documented header and a predictable layout — tells the attacker exactly how to parse what they just extracted. That is the surface to remove.
Encrypting the stream at protect time
At protect time, Nebula does two things to a selected resource. First it reads the original resource bytes, encrypts them, and stores the ciphertext as the resource's new content. Second it renames the manifest entry to something opaque so the original name is not a signpost. The real stream the loader will ask for no longer exists as plaintext anywhere in the file; what sits in the resource section is an encrypted blob under a renamed key.
Before: MyApp.Policy.bin -> [ plaintext policy bytes ]
After: _r3f9c2.bin -> [ ciphertext ]
Open the shipped assembly now and the resources node shows a blob you cannot parse under a name that tells you nothing. GetManifestResourceStream("MyApp.Policy.bin") from outside returns null — that name is gone. Static extraction has nothing to save.
The decrypt-on-resolve hook
The bytes have to come back before the resource can be used, and the honest, portable way to do that is to intercept the lookup at the moment the application asks. Which interception point depends on how the resource is loaded, and getting that right is the whole game.
For resources loaded through a ResourceManager or looked up as resource-assembly / satellite resolution, AppDomain.CurrentDomain.ResourceResolve fires when the runtime fails to find a named resource and lets you supply it. For direct GetManifestResourceStream calls, the cleanest shim is a small accessor your transformed call sites route through. Either way the handler locates the ciphertext under its renamed key, decrypts it into a MemoryStream, and returns that stream to the caller as if it had been there all along:
static class ProtectedResources
{
// real name -> renamed ciphertext entry
static readonly Dictionary<string, string> _map = BuildMap();
public static Stream? Resolve(string requestedName)
{
if (!_map.TryGetValue(requestedName, out var blobName))
return null; // not ours; let the loader continue
var asm = typeof(ProtectedResources).Assembly;
using var enc = asm.GetManifestResourceStream(blobName)
?? throw new MissingManifestResourceException(requestedName);
byte[] cipher = ReadAll(enc);
byte[] clear = Decrypt(cipher, DeriveKey()); // key derived, not stored
return new MemoryStream(clear, writable: false);
}
}
Wiring it to ResourceResolve is the install step that must run before the first resource load:
// Module initializer / earliest startup — before any resource is touched.
AppDomain.CurrentDomain.ResourceResolve += (_, e) =>
{
var stream = ProtectedResources.Resolve(e.ResourceName);
return stream is null ? null : BuildResourceAssembly(e, stream);
};
For the common ResX case you can instead ship a thin ResourceManager subclass that overrides stream acquisition, or a custom IResourceReader, so the decrypted MemoryStream is fed straight into the normal .resources parsing path. The principle is identical: the consumer still calls the resource the way it always did; the decryption happens underneath, once, on demand.
The key has to be reachable — so hide it well
There is the same unavoidable tension resource encryption shares with every runtime-decrypt technique: to decrypt at runtime, the key must be derivable at runtime, which means it is present, in some form, inside the very assembly the attacker is studying. Store it as a plain byte[] constant and you have handed it over — a decompiler reads static arrays as easily as it lists resources.
So resource encryption is only as strong as what hides its decryptor. Nebula Pro pairs it with string encryption so the key material, the renamed blob names, and the real resource names in your map are not literals sitting in the user-string heap. The key is derived — assembled from scattered computation rather than stored — so recovering it means understanding string-encrypted, obfuscated code, not reading a constant. Encrypting the bytes raises the cost of static extraction to infinity; obfuscating the decryptor is what stops that cost collapsing back to "find the key, decrypt the blob offline."
Where it leaks, and how to scope it
Three honest limits decide where this technique belongs.
The plaintext exists in memory when used. The consumer needs real bytes, so once the resource is resolved the decrypted content is materialised in the process. An attacker who runs the app and dumps memory after the resource is read can capture it. This is cost, not a wall: you convert a trivial static save-to-disk into a dynamic attack that requires running the target, reaching the code path that loads the resource, and timing the dump — far more work, far more detectable, but not impossible.
The loader path has to be hooked correctly or the app breaks. WPF resolves packed pack:// URIs and BAML through its own resource machinery; ResX goes through ResourceManager and IResourceReader; localized satellite assemblies are probed early. Encrypt a resource but hook the wrong path and the framework gets a null or malformed stream and the feature dies at runtime, not at build. Test the real resource-load path for each resource — run the app and exercise the screen or code that uses it — and leave framework-critical resources that you cannot verify unencrypted. If your UI resources are packed BAML, read how that loader resolves URIs first in obfuscating WPF BAML and resource URIs.
Install before first use, and scope for size. Some frameworks read resources very early — satellite-assembly probing can happen before a casual startup hook runs — so the resolve handler must be installed in a module initializer or the earliest entry point, before anything asks for a protected resource. And decryption is not free: a large resource adds latency and a full-size MemoryStream every time it is resolved. Scope encryption to sensitive resources, not to every image and string table, and cache the decrypted stream if the resource is read repeatedly rather than decrypting on each resolve.
Takeaway
Renaming a resource keeps its name off the list; encrypting it keeps its bytes off the disk, and restores them only at the instant the application resolves it. The mechanism is an encrypted blob under a renamed manifest entry at protect time, and a ResourceResolve handler — or a ResourceManager/IResourceReader shim — that decrypts into a MemoryStream on demand at runtime, installed before first use and paired with string encryption so the key is derived rather than stored. Used on the embedded data that is genuinely your product, scoped to resources whose load path you have tested and away from the hot or the huge, it turns a one-click resource extract into a dynamic attack most adversaries will not pay for.
See Nebula.NET for the full transform set, or the docs for the nebula.config.json resource-encryption reference and per-resource scoping.
Top comments (0)