Back to articles

Tag archive

#decompilation

H
Nov 13, 2026

How Glass reconstructs a C# switch statement from an IL jump table

A C# switch over a dense integer range does not compile to a chain of comparisons — it compiles to a single switch IL opcode carrying a table of branch targets, indexed by the switch value. This walks through what that jump table looks like, how the compiler normalizes the value by subtracting the minimum case, why sparse switches become binary-search if/else chains instead, and how Glass.NET turns the resulting tangle of gotos back into a clean switch (x) { case 10: ... }.

Nov 13, 20269 min read0 reactions0 comments
D
Nov 13, 2026

Decompiling [CallerArgumentExpression]: the source text the compiler bakes into your call sites, and how Glass restores the clean call

When you call ArgumentNullException.ThrowIfNull(x) or a custom Guard.Against(x), you pass one argument. The compiled IL pushes two: your value, and a string literal holding the exact source text of your first argument — because the parameter carries [CallerArgumentExpression]. The attribute lives in metadata on the parameter; the captured text lives as a plain ldstr at every call site. A naive decompiler prints the redundant second argument back at you. This post reads the IL and the attribute blob, shows why the literal is there, and walks how Glass.NET detects the attribute, matches the literal to the reconstructed expression, suppresses the synthesized argument, and rebuilds the method declaration with the attribute intact.

Nov 13, 20268 min read0 reactions0 comments
D
Nov 13, 2026

Decompiling [Flags] enums: how Glass.NET turns ldc.i4.3 back into Read | Write

A bitwise flag combination like Read | Write is folded to a single integer literal before it ever reaches IL, so the | you wrote vanishes. This deep dive reads the real IL for enum flag code, explains the FlagsAttribute and named-constant metadata signals that let a decompiler decompose a raw integer back into a sum of named members, and walks through how Glass.NET reconstructs | & ~ and HasFlag patterns instead of leaving you (Permissions)3.

Nov 13, 20267 min read0 reactions0 comments
D
Nov 13, 2026

Decompiling module initializers: the <Module> static constructor and ModuleInitializerAttribute

A method marked [ModuleInitializer] runs before anything else in the assembly, but the attribute is not what the runtime calls. The C# compiler emits a static constructor on the special <Module> pseudo-type that calls each initializer in turn. Here is the exact IL the compiler generates, the metadata signals that mark the <Module> cctor and distinguish it from an ordinary type initializer, and how Glass.NET reads the whole thing back to the [ModuleInitializer] methods you wrote.

Nov 13, 20267 min read0 reactions0 comments
D
Nov 12, 2026

Decompiling boxing, unboxing and the constrained. prefix in C#

An implicit conversion from int to object is invisible in C# but allocates on the heap — and the IL says so with a box opcode. This walks through where box, unbox.any and the constrained. prefix come from, why generic code uses constrained. to dodge a boxing allocation, and how Glass.NET reconstructs readable C# while the IL reveals the allocation that the source hides.

Nov 12, 20267 min read0 reactions0 comments
R
Nov 12, 2026

Reading top-level statements in decompiled C#: the synthesized Program class and the Main entry point

A file of top-level statements has no visible class and no visible Main, but the assembly does. The C# compiler wraps your statements in an internal class named Program and an entry-point method with the unspeakable name <Main>$, marked with the .entrypoint directive. Here is exactly what the compiler emits for the sync and async cases, why the entry point is the method you can never write by hand, where your global usings went, and how Glass.NET reads it back as the top-level program you wrote.

Nov 12, 20266 min read0 reactions0 comments