≈ the.bay.news

Obfuscating enums: why the names survive renaming, and how ToString() and switch leak them

DEV Community
Obfuscating enums: why the names survive renaming, and how ToString() and switch leak them
Rename an enum and its members and a decompiler still prints LicenseTier.Pro, not a.b — because an enum is a sealed class whose members are public const literal fields, and the moment your code calls ToString() or Enum.Parse the runtime reads those field names straight out of the metadata at runtime. Renaming them to a, b, c is legal and costs you nothing except the one thing you wanted: a round-trip through the name breaks, because "Pro" no longer matches a field called a. This post reads the IL an enum compiles to, shows where the names live (the Field table and #Strings heap, not the values), walks exactly what breaks when you rename — ToString, Enum.Parse, [Flags] formatting, JSON string serialization, Enum.GetNames — and how Nebula scopes enum handling so the values that gate your logic are protected while the names your protocol depends on stay intact.

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.