Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Friends,

DLL is build with the help of .NET code.
As per the information, I am having we can use
IL DIssemble
IL SPY
.NET reflector

to see the objects, classess, properties present inside the DLL.

But is there any way to get the source code from DLL ?
This question is looking very strange to me :( as a .NET developer.

But JAVA folks are proudly saying that their executable EAR can decompile to the source code from it is build...

so, .NET friends, Please help me by commenting more about the way to get the source code from dll...
Whether any way is present ?
If yes, What is that ?
If no, Why it is not available ???

thanks in advance for your help !!!!
Posted
Comments
Thanks7872 19-Jun-15 7:52am    
Very first question, why? If you have developed something,then you should be having access to the code. If not developed by you, you should not try this.That will be considered malpractice. Further, it's possible but very difficult.
Sergey Alexandrovich Kryukov 19-Jun-15 10:57am    
Your statement about malpractice is highly exaggerated. There are many cases when you need to reverse-engineer code; and the law allows that. Want some typical example? You purchase some "industrial-grade" specialized hardware, and nearly all the "programmers" of that products write lousy drivers and lousy API. Usually, you can do little too low level but can fix, say, .NET API to make the hardware at list minimally usable. The law says that reverse-engineering is allowed for some purposes, one of them is the purpose of making the product you purchase more usable (there are different legislation regions and other subtleties, I don't want to discuss them here).

I would not care about pure software products which you could just ignore, but when you buy hardware, the software is bundled to it and can make software unusable. It's not that a customer steals the code, its that those lousy "programmers" rob the customers by blocking their ways of using the hardware. This problem has too high scale...

—SA
Thanks7872 19-Jun-15 13:39pm    
And he is trying to get the code from the website :-)
Sergey Alexandrovich Kryukov 19-Jun-15 14:05pm    
Really? Than it's just not possible. DLL is something which works only on the server side. There is no any access to it from client side.
—SA
F-ES Sitecore 19-Jun-15 8:04am    
I don't understand your question, the tools you've already listed (ilspy etc) are capable of getting the source from the dll, so what is the question?

While I completely agree with @Rohan Leuva, you can try an excellent product from Telerik named "Just Decompile". It's very easy to use.
You can download it from here http://www.telerik.com/download/justdecompile[^]

My suggestion is to follow the documentation/tutorial for the first time use.

Hope, it helps :)

Note: You cann't get the 100% same code decopmiled but it should generate equivalent working code.
 
Share this answer
 
The tools you listed are great tools for viewing the contents of .NET DLLs. ILSpy and .NET Reflector allow you export the code from the DLL into C# or VB.NET, but there are limitations to this.

I personally use ILSpy, which is as easy as opening the DLL, finding the class in question, then go to File->Save Code.

I haven't used .NET Reflector since Red Gate made it closed source and charged for it. When I did use it, it had a very nice feature that would export the entire assembly's contents into C# or VB.NET project as opposed to individual code files like ILSpy does.

There are also other tools out there that will achieve this. I know Telerik has one, but I believe it is a commercial product. JetBrains also has one called dotPeek that is free to use.

In order to understand your second question, the why, you need to understand how .NET works. Your .NET application is not compiled and linked into executable file like a C/C++ application is. Your application is compiled into an intermediate language (IL) or Microsoft Intermediate Language (MSIL) which is similar to Java's bytecode. Take a look at this article to understand IL a bit more in depth:
Understanding Common Intermediate Language (CIL)[^]

In Windows, when you run a .NET application, the local computer takes the IL and performs a Just In Time compile (JIT) to produce native code that can run on the local computer. Take a look at this MSDN article to understand more about JIT:
Compiling MSIL to Native Code[^]

The short answer to the why is simply your code hasn't been fully compiled until you run your application so the reverse engineering is fairly straight forward. There are limitations to this (linq queries, lamda expressions, obfuscator) where the tool may have an extremely hard time creating the exact code, but it will be able to give something functional.

I hope this helps.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jun-15 10:20am    
I think this is a good answer and voted 5, but I would like to hear about the limitations you mentioned. Could you list and explain them?
—SA
Nibin22 19-Jun-15 11:17am    
Thanks for the detailed explaination.
I tried IL SPY and able to generate/SAVE Code for a WINDOWS application(EXE).

Next, I am willing to try to generate the code for an ASP.NET application which deployed in IIS.
Eager to check, How would be the results....

Any suggestion, Whether i can get the source code of a WEBSITE?
WebSite, I mean is the site which is deployed in ISS.
Normally, We can get all the ASPX, CSS, JS from the folder itself....
What i want to check is from the compiled(DLL) Whether i am able to extract all the information or not ?
And trying to setup the development environment :) !!!!
virusstorm 19-Jun-15 11:23am    
Look in the bin folder of your ASP.NET application. There will be a DLL with the name of the web application. This has all of the complied code for your web application and ILSpy will have no issues reading it. I just did this two months ago for a rogue production application we didn't have source code to. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900