Back to articles

Tag archive

#glass

D
Nov 14, 2026

Decompiling a WinForms app: reconstructing the Designer''s InitializeComponent and resources

A compiled WinForms app has no .Designer.cs and no .resx — the designer code was merged into one type as InitializeComponent(), and the UI strings and images live in an embedded .resources stream. Here is how Glass.NET reconstructs a faithful InitializeComponent() from the binary, surfaces the ComponentResourceManager values, and lets you export the embedded resources — all static, all free.

Nov 14, 20268 min read0 reactions0 comments
R
Nov 14, 2026

Recovering Real Variable Names, Source Files and Line Numbers from PDBs and Source Link

A decompiler reconstructs C# from IL and metadata — but names like V_0 and V_1 are gone. Here is how Glass reads Portable PDBs (embedded, side-by-side or fetched via Source Link) to restore real local and parameter names, annotate decompiled code with original source file and line, and fetch the actual source — and how it degrades when no symbols exist.

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

Decompiling generic constraints and variance: reconstructing where-clauses and out/in from metadata

Generic type-parameter constraints and variance are, like struct layout, features a decompiler cannot recover from code shapes — they live entirely in metadata. Each generic parameter carries a variance direction and special-constraint flags in the GenericParam table, and the GenericParamConstraint table lists the base type and interfaces a parameter is bound to. Covariance (out) and contravariance (in) are flag bits; the class / struct / new() constraints are flag bits too; but notnull and unmanaged are encoded indirectly, through a modreq and an attribute rather than a raw flag. Drop the variance and an interface stops being assignable the way it was; re-emit the constraints in the wrong order and the output does not compile at all. This post shows where the data lives, how Glass.NET reads the GenericParam and GenericParamConstraint tables, how it sorts the constraints into the exact order C# requires, and a worked covariant-interface plus multi-constraint-method example.

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

How Glass follows type forwarding and the ExportedType table

When a type moves from mscorlib to System.Runtime, the old assembly keeps a forwarder — an ExportedType row with the forwarder flag pointing at a new AssemblyRef. A forwarder has no members, so a decompiler must not render it as a type: it has to follow the forward to the real definition. This walks through where the forward lives in metadata, how Glass.NET resolves a forwarding chain, how it degrades gracefully when the target assembly is missing, and how it re-emits [assembly: TypeForwardedTo(...)] when you decompile the facade itself.

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

Decompiling explicit struct layout and C-style unions: reconstructing [StructLayout] and [FieldOffset] from metadata

Explicit struct layout is one of the few C# features a decompiler cannot recover from code shapes, because it leaves no code — it lives entirely in metadata. The LayoutKind (Sequential/Explicit/Auto) is a flag on the type definition, Pack and Size sit in the ClassLayout table, and every field''s byte offset sits in the FieldLayout table. When two fields share an offset you have a C-style union: aliased bytes, one int viewing the same four bytes as a float. Get a single offset wrong and the decompiled struct silently corrupts every interop and marshalling call that touches it. This post shows where the layout data lives, how Glass.NET reads the ClassLayout and FieldLayout tables and re-emits [StructLayout(LayoutKind.Explicit, Pack = ..., Size = ...)] on the type and [FieldOffset(n)] on each field, how it recognizes a union from overlapping offsets, and why preserving exact offsets is non-negotiable.

Nov 13, 20269 min read0 reactions0 comments
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 C# range and index operators: folding Slice and GetSubArray back into a[^1] and a[1..^1]

The ^ and .. operators are pure compiler sugar. a[^1] lowers to arithmetic against the collection length, a[1..^1] builds a System.Range from two System.Index values and calls RuntimeHelpers.GetSubArray, a span range becomes Span<T>.Slice, and a string range becomes String.Substring. A naive decompiler shows the raw constructor calls and the Length minus n arithmetic; Glass.NET pattern-matches these shapes and folds them back into ^ and .. — including the subtle case where span.Slice(1, 2) and span[1..3] emit byte-identical IL, so Glass has to pick the reading that round-trips.

Nov 13, 20268 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