I want to investigate IL code of most .net framework library classes. Is it possible? I am trying to decompiling some dll (e.g.: System.Treading), and I only see signature of the functions. Then I go to mscorlib.dll and see only manifest. There is a way to see the real code?
You can use .NET Reflector (commercial but very good):
https://www.red-gate.com/products/dotnet-development/reflector/
You can open a .net assembly with it (.exe or .dll).
So you can also directly browse .NET Framework assemblies by selecting the framework version.
Select view IL or other language such as C# or VB code and it is done.
There is also for example this free tool (slow, very slow):
https://www.jetbrains.com/decompiler/
If you want to study the implementation of .Net classes. I suggest you use the reference code provided by Microsoft.
The main advantage of using the reference code, is that you can see the comments and other elements that will not be added to IL (like #define).
Reference Source
To study the effect of certain C# constructs on the generated IL, I would suggest using SharpLib.
SharpLib
Personnaly to decompile IL code i use ILspy , it's lightweight tool and easy to use .
you can found it in the link below :
https://sourceforge.net/projects/ilspyportable/
Best Regards .
In NetBeans using Java I can open java.lang.String class and I see that class source code. If I try to open System.String class in VisualStudio I see methods signatures only.
Is it possible to install VisualStudio plug-in or something like that to open mscorlib classes source code pressing F12?
Thanks for your answers.
I've found the best solution for me: http://visualstudiogallery.msdn.microsoft.com/95789cdb-08f9-4dae-9b2f-fc45a452ad77
What you want is at "Microsoft Reference Source Code Center", with the .NET Library sources at http://referencesource.microsoft.com/.
What you are asking for can be achieved by using dot peek from Jetbrains.
Jetbrains offer some other cool software too, like Resharper which can have dot peek included and you can navigate to the decompiled sources.
You can get the actual source code, not decompiled, from the symbol files which is the option beneath the one I have highlighted, you would need to do what the other answer says by setting up your symbol server.
UPDATE: See Bruno Brants answer.
While the previous answers are good, you have a better option now: Microsoft has open-sourced .NET, and not only that, all of it is available at GitHub.
Also, it's now possible to configure Visual Studio to check referencesource.microsoft.com while debugging.
I have a dll file is written on C #, I opened the file via the Reflector, the file is the code
if (a! = 5)
{
}
How can I change the code on
if (a == 5)
{
}
I still have the plugin Reflexil
You can do that using MSIL Disassembler
Decompile using that tool, apply changes in IL and compile back again using MSIL Assembler
This will work smoothly if compiled app is not protected.
Whilst the answer about modifying the IL is correct, you can also use Denis Bauers plugin for reflector to disassemble the code and create a new project from it. You can then recompile that project to produce a new dll.
This allows you to make the change in a more familiar environment, rather than having to deal with the IL. you can also choose the language you want to make the changes in.
If the assembly needs to be signed then you might have problems getting it to load again.
Other Alternatives are ILSpy or the Resharper 6.0 which also contains a disassembler.
Quick question.
Can I recover a lost .cs file using RedGate Reflector ?
My assembly is a debug version
If you open .NET assembly in Reflector, you should be able to switch which language Reflector uses to display the code e.g. IL, VB.NET, C#. There is a dropdown list on the UI menu bar with this selection of languages.
As long as you have all the required external libraries and references, you should be able to copy the C# code form Reflector and try to rebuild it.
To make it a little more simple to get the IL code back into a file you should check out this Reflector Add-in.
More add-ins for Reflector can be found here.
I'm new to .NET C# programming. I'm following few books. It is said that instead of compiling C# code directly to machine code, it is converted into an intermediate language (called MSIL aka CIL). But when I compile, I get an exe/dll file.
Is this MSIL/CIL contained in these exe/dll files?
I want to see that intermediate language code, just to get feel for its existence. How do I view it?
They are calling this exe/dll file an assembly. Are they using this "fancy word" just to differentiate these from the exe/dll files that contain native/machine code?
Yes it is, more exactly in the .text section of the PE file (portable executable = *.exe or *.dll). More information can be found here.
The best choice is to use ILSpy (Reflector is no longer free). It's a free disassembler that can dissassemble your assembly into MSIL but also C#, VB (to some extent). The .NET Framework SDK contains ILDasm, which is the official MSIL dissasembler.
Basically yes. An assembly is a file that contains MSIL code and corresponding metadata. This is not restricted to PE files per se, but all current CLR implementations use them.
If I may recommend a good book on that matter too, it's Expert .NET 2.0 IL Assembler by Serge Lidin. He's the guy who designed MSIL.
One of my favorite ways to see IL for a snippet of C# is to use the free LINQPad tool. After entering some code and choosing "C# statements" at the top (or "C# Program", whichever suits), click the "IL" button under the code entry area, and you will see the generated IL.
Using LINQPad for this is much more convenient than loading up Visual Studio or running the compiler from the command line, then loading up ILDASM and opening the .il file with a text editor.
If you want it online, .NET Fiddle is excellent. Just paste your code and click View IL option at the top right.
Another option: Use ReSharper
Source / IL synced view: left blue background line corresponds with right IL Block
In Visual Studio:
Choose ReSharper | Windows | IL Viewer
or Context Menu: Navigate | IL Code
Supports synced view of Source Code and IL - when you click on a statement in source, the corresponding block in IL is highlighted (and vice versa). Displays descriptions for IL from Microsoft Developer Network and "Common Intermediate Language (CIL) instruction set" from ECMA standard specification.
see Viewing Intermediate Language (IL) in Resharper Help. Picture above is from Resharper Help.
Free option is to use Jetbrains dotPeek
see also: "Exploring Intermediate Language (IL) with ReSharper and dotPeek", by Maarten Balliauw, January 19, 2017 - Jetbrains Blog
sharplab is an online tool, great for simple use cases. Type your code on the left, IL shows up on the right.
I believe that they are called "assemblies" because an assembly is a set of modules, assembled together by a manifest.
(source: microsoft.com)
See Assembly Contents for details.
Yes it is in assembly.
You need .NET Reflector or ILDasm.
More details on assembly check HERE.
P.S As you are following some books I will highly recommend you CLR via C#.
In many respects, .NET assemblies are similar to Java bytecode packages.
Yes. They also contain manifests and other data, but the CIL is part of the exe/dll.
Use ILDasm or Reflector - most people would say Reflector, as it is much more powerful. Both will show you what CIL was produced. Wikipedia has a list of all CIL instructions, for a better feel (it is assembly like).
I guess it is meant as an assembly of code. A good way to differentiate it from native.
I know this is an old question, and I'd prefer any of the tools above. However, in a pinch, there has been an MSIL viewer in the box with Visual Studio since at least Version 2005.
The tool is named ildasm.exe, and is located in the following folders after default Visual Studio installations:
Visual Studio 2005
"C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\ildasm.exe"
Visual Studio 2008
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe"
Visual Studio 2010
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\ildasm.exe"
For more information, see: "How to: View Assembly Contents" in the MSDN Library.
I have just spent a couple of hours searching for the best tool that could let me view the IL code directly inside Visual Studio.
The only solution I found so far is Msiler https://visualstudiogallery.msdn.microsoft.com/60fc53d4-e414-461b-a27c-3d5d2a53f637
it works quite well!
Otherwise the second best solution, but without visual studio integration, is JetBrains dotPeek, which is quite awesome to be honest.
From my experience the best source of IL-related knowledge is Andrew Troelsen “Pro C# and .NET Platform”. Starting from 3rd edition he has really, really outstanding chapter (approx 50 pages) on how to understand IL and even write your own code and use ILAsm. I’ve employed that information to investigate whether multiple inheritance exists in .NET world. Also you could try to employ some very interesting features in IL (e.g. filtering of exceptions which only exists in VB but not in C#).
I highly recommend to read that chapter.
Eventually, .NET Reflector is an enterprise standard for investigating IL code of assemblies and Richter's book is definitely "must read" stuff. But from other books like mentioned above you could reveal really useful things :)
Yes, each assembly in .NET world holds some IL code (alongsite with manifest) which could be viewed thru Reflector or ILDasm. Even more, Reflector could show you C# and VB optimized code. This means that any person could view the source code of an assembly and that's why in commercial products obfuscators are used.
I you want to view the intermediate language, Try downloading JustDecompile from Telerik (Which is currently free, requires a sign up though).
Drag in your DLL and choose IL from the drop down box at the top!
There is now another option. You can do this in VS Code with this extension built with Roslyn. This is currently limited to .NET Core.