Why can programs written in C# be reverse-compiled essentially to their original form with variables names (such as dnSpy) while C++ decompilers (such as Ghidra) are unable to decode the variable names?
Debug Symbol information is often "stripped off" from
C++ binaries. Symbol information stores all user-created names, symbols, and types, bounds, fouction boundary and other function related metadata information (it is generally stored according to a popular and standardized "dwarf" format which is widely used and employed in modern compilers). If you want to keep this information then compile your binary with - say
-g flag in gcc or clang. For e.g.
gcc -g myprog.c. You will find all user-defined symbols rendered by Ghidra.
On the other hand, in
C# .NET removal of name symbol metadata is not possible (as reflection requires retrieval of symbol for types at runtime). Thus to work around this,
C# symbols are generally obfuscated.
References: https://www.appsealing.com/code-obfuscation-comprehensive-guide/ http://www.semdesigns.com/Products/Obfuscators/CSharpObfuscationExample.html https://help.gapotchenko.com/eazfuscator.net/53/advanced-features/symbol-names-encryption