0

What's a simple method for extracting the finally x86/x64 assembly code of a C# method?

Preferably without debugging the method within Visual Studio and stepping with the assembly.

tgiphil
  • 1,242
  • 10
  • 22
  • 3
    The x86/x64 code is generated at run-time, see https://stackoverflow.com/questions/5589409/c-sharp-jit-compiling-and-net It's possible for different executions of the method to use different machine code. Are you sure this is what you're after, and not the CIL that's part of the generated .exe/.dll? –  May 28 '18 at 16:12
  • 2
    I think [ILSPY](https://github.com/icsharpcode/ILSpy) is what you're looking for. – Vulpex May 28 '18 at 16:16
  • @Vulpex That's not going to show any x86/x64 assembly code. –  May 28 '18 at 16:18
  • @hvd that's the closest to what he is looking for I can think of, otherwise there are the usual disassemblers left, IDA for example. – Vulpex May 28 '18 at 16:22
  • 1
    For simple code I think [sharplab](https://sharplab.io/) should be able to show it. For more complex code, perhaps you could ngen it? – xanatos May 28 '18 at 17:13
  • Thanks for the sharplab reference. My goal is to study the IL compiler and specifically compiler optimizations. I'd love to ngen and then dump the binary to assembly. – tgiphil May 28 '18 at 19:56
  • IDK if you're specifically interested in (a specific implementation of) C#, but if not then C or C++ compilers are easier to play with. See Matt Godbolt's CppCon2017 talk [“What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid”](https://youtu.be/bSkpMdDe4g4) for an intro to looking at / making sense of compiler asm output. (His http://godbolt.org/ compiler-explorer has MSVC installed, as well as gcc/clang/ICC, and gcc for various non-x86 ISAs). See also [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116). – Peter Cordes May 29 '18 at 00:40

0 Answers0