Menu

Obfuscating source-generated code safely
πŸ“°

Obfuscating source-generated code safely

DEV Community: dotnetΒ·Zero HeartbeatΒ·2 days ago
#QgqzpWE5
#devtodotnet#devto#dev#name#generated
Reading 0:00
15s threshold

A source generator is a compiler plugin that reads your code and emits more code into the same compilation. By the time the C# compiler finishes, the generated files are just part of your assembly β€” same metadata tables, same IL, no marker in the output that distinguishes a method you wrote from one the generator wrote. Which raises the obvious question for an obfuscator: when Nebula renames your types and members, what happens to code that was generated around them ?

The answer is better than you'd expect, with one twist. Generators resolve names at compile time , which is exactly the property that makes code rename-safe. But the way they do it is by writing your names down as string literals , and those literals survive renaming verbatim β€” occasionally telling an attacker what a method used to be called.

Runtime lookup versus compile-time capture

The whole reason obfuscation breaks things is runtime name lookup.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.