34

Is there any software to do this? I didn't find any useful information on the internet so I am asking here.

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
ILoveMusic
  • 501
  • 1
  • 5
  • 10
  • The original source code that was compiled? Simply not possible. Something functionally equivalent? Yes. –  Jan 16 '11 at 16:01
  • @delnan - What do you mean by functionally equivalent? Sorry new to all this. I didn't get it. I want to extract the classes' (written in c#.net) code from a dll file. the dll file's got like way too many classes. Any way to get that code out of that dll? – ILoveMusic Jan 16 '11 at 16:05
  • @ILoveMusic You can extract something like the original code, but not the exact one. Use the .NET reflector. – Petar Minchev Jan 16 '11 at 16:06
  • Tools like the ones in the answers can give you source code that, when compiled again, gives a DLL that does the same thing. But it can only try to infer what the original source code looked like from the bytecode (which is, of course, much more low-level), it can't magically restore the exact code the DLL was created from - much, like formatting, certain identifiers, etc. are lost during compilation. –  Jan 16 '11 at 16:10
  • okk..so there's no way I can extract the EXACT code, right? – ILoveMusic Jan 16 '11 at 16:12
  • @ILoveMusic: Correct. The decompiled code is a code representation of the compiled IL, not the code that was used to create it. Write some simple code, compile it and then decompile it. You may get something that looks the same, but you might not. – adrianbanks Jan 16 '11 at 16:15
  • hmm ok. Thanks all for answering :) – ILoveMusic Jan 16 '11 at 16:28

10 Answers10

31

You cannot get the exact code, but you can get a decompiled version of it.

The most popular (and best) tool is Reflector, but there are also other .Net decompilers (such as Dis#). You can also decompile the IL using ILDASM, which comes bundled with the .Net Framework SDK Tools.

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
  • 11
    These days you should probably use ILSpy or dotPeek. Both are **free** and doing an excellent job. I find dotPeek better because of navigation, and also it takes a long time for ILSpy to start. Also, I once decompiled an assembly that was I obfuscated (for testing tools) and Redgate's .NET reflector crashes immediately from the simplest obfuscation. ILSpy and dotPeek had no problem and have loaded it instantly. They also highlight selection so you can somehow manage the obfuscation. – MasterMastic Feb 04 '13 at 09:42
  • Im just going to say, you should probably edit this and include DnSpy instead of ilspy, ildasm, or reflector. In my honest opinion, nowadays reflector is the Worst of all of them. DnSpy seems to be the easiest to setup, is minimal, and has all the features of all the other programs. @adrianbanks – Mister SirCode Aug 21 '19 at 11:55
21

Only managed Languages like c# and Java can be decompiled completely.You can view complete source code. For Win32 dll you cannot get source code.

For CSharp dll Use DotPeek becoz it free and works same as ReDgate .Net Compiler

Have fun.

RickL
  • 3,318
  • 10
  • 38
  • 39
Vikas Kumar
  • 519
  • 5
  • 16
10

Use dotPeek

enter image description here

Select the .dll to decompile

enter image description here

That's it

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
6

Use .NET reflector.

Petar Minchev
  • 46,889
  • 11
  • 103
  • 119
4

Use Refractor. Download from here.

  1. Open the software after installing.
  2. Press Ctrl + O and select your DLL File.
  3. Dll will be shown in left pane.
  4. Right click on Dll and select Export Source Code.
  5. Select the folder in which you want to export your files
  6. Wait for a while it may take 2-3 minutes

enter image description here

Singh T
  • 161
  • 1
  • 5
2

You can use Reflector and also use Add-In FileGenerator to extract source code into a project.

ShahidAzim
  • 1,446
  • 1
  • 10
  • 15
2

You can use dotPeek The only thing I have to say is that when using it, right-click on the class to select Decompiled Source instead of double-clicking, otherwise dotpeek will only display the contents of the local cs file, not the decompiled content.

Option instance

我零0七
  • 315
  • 3
  • 6
0

If you want to know only some basics inside the dll assembly e.g. Classes, method etc.,to load them dyanamically

you can make use of IL Disassembler tool provided by Microsoft.

Generally located at: "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin"

riaz
  • 11
0

I used Refractor to recover my script/code from dll file.

-1
 public async void Decompile(string DllName)
 {
     string destinationfilename = "";

     if (System.IO.File.Exists(DllName))
     {
         destinationfilename = (@helperRoot + System.IO.Path.GetFileName(medRuleBook.Schemapath)).ToLower();
         if (System.IO.File.Exists(destinationfilename))
         { 
             System.IO.File.Delete(destinationfilename);
         }

         System.IO.File.Copy(DllName, @destinationfilename);
     }
        // use dll-> XSD
     var returnVal = await DoProcess(
            @helperRoot + "xsd.exe", "\"" + @destinationfilename + "\"");

     destinationfilename = destinationfilename.Replace(".dll", ".xsd");

     if (System.IO.File.Exists(@destinationfilename))
     {
          // now use XSD
          returnVal =
            await DoProcess(
              @helperRoot + "xsd.exe", "/c /namespace:RuleBook /language:CS " + "\"" + @destinationfilename + "\"");

            if (System.IO.File.Exists(@destinationfilename.Replace(".xsd", ".cs")))
            {
                string getXSD = System.IO.File.ReadAllText(@destinationfilename.Replace(".xsd", ".cs"));
           
            }
        }
}
Muaath
  • 579
  • 3
  • 19
BobSpring
  • 69
  • 1
  • 1
  • there is some problems, what is `DoProcess` method, and what is `@helperRoot` and add explan for code. – Muaath Aug 11 '20 at 10:57