Decompile Precompiled Source Code ASP.NET
Asked Answered
K

6

17

we have an application in production and the code is in Pre-Compiled form. The developer who developed that application left the company and we don't have any backup of source code. the only access we have is Pre Compiled code in the server. We need to fix the issues in the application now.

Is there any way to Decompile (extract to actual source code) the PreCompiled code ?

Klemperer answered 5/1, 2011 at 19:56 Comment(0)
L
15

Open the DLLs in the .NET Reflector.

Letter answered 5/1, 2011 at 19:58 Comment(10)
There is no DLL in the precompiled code. The only things I see are aspx pages and some other images, skins foldersKlemperer
@msbyuva: Did you check the bin folder of the application?Letter
I see some dlls, I opened then through .NET Reflector then I disassembled them but have not seen any code. And also how can I see the .aspx.cs files ?Klemperer
@msbyuva: Right-click on a class, click on Disassemble, click on Expand Methods on the right. I'm not sure if you're going to be able to fully recover .aspx.cs files, but I don't have a WebForms app in front of me to try to decompile, or the time to do so. You may want to take a look at the FileDisassembler that x0n posted. Perhaps that'll help.Letter
Thanks adam, can I just read the code or else can I Edit the code ?Klemperer
@msbyuva: You can't edit it in the Reflector application itself, but you can certainly migrate it into a new project you can create to re-house all this code. See x0n's answer for more details.Letter
Thanks...as suggested I used reflector and I am able to see all the Code in class files and code behind files. Well, I didn't understand how to use the second tool File Dissembler.. I have extracted all the dll's from .NET reflector, how can I use the 2nd tool to extract source code from those extracted dll's ??? I am sorry for bothering you.Klemperer
@msbyuva: I've never used that tool before, nor have I ever heard of it before I read x0n's answer. I can't really help you there. Sorry!Letter
@Letter Thanks for your time. I contacted the .NET Relector company, they said that using the tool we can read and debug the code but can't modify it which makes sense. Thanks again for your time.!!!Klemperer
@adamjford: Well, you can't modify a compiled DLL, obviously. You need to take the decompiled source code out of Reflector, and create a new project to house all that code and run with that.Letter
V
4

To update @xOn's answer:

Due to a recent source control disaster I had to recover my project from the DLLs. So sadly I'm knowledgable on the procedure:

  1. Get .Net Reflector from here: http://www.red-gate.com/products/dotnet-development/reflector/

  2. You do not seem to need FileDisassembler.

  3. Either load your bins in Reflector or double click them.

  4. Mind that the .Net framework might have not maintained your original project file structure. So if some of your ASPX pages shared the same basic class name in different .cs files (I.E. Inherits tag is the same, but CodeFile tag differs), you would not be able to simply "export source code". Don't go blindly exporting source files. It won't work.

  5. There will still be some work to be done before being able to just fire up the old build button. For example - DLLs can refer to property's getter/setters directly. You will have to fix that.

Good luck.

Vallombrosa answered 7/3, 2014 at 17:58 Comment(0)
H
3

Start with:

http://www.red-gate.com/products/dotnet-development/reflector/

...plus:

http://www.denisbauer.com/NETTools/FileDisassembler.aspx

You'll have to recompile the latter to link it against v6.5 of reflector (the latest, as of this post.) It is a good add-on if you want to avoid having to copy and paste ever single class into files by hand. It will dump an entirely assembly as .cs files. I think it may even generate a csproj.

Both tools are free.

Houseroom answered 5/1, 2011 at 20:3 Comment(4)
There is no DLL in the precompiled code. The only things I see are aspx pages and some other images, skins folders.. How can I get the aspx.cs pages ?Klemperer
There are no more aspx.cs "pages," which are actually not pages, but are source code files. The C# compiler - like all compilers - takes a collection of source files and turns them into one or more DLLs. You will not be able to get the original .cs files back. You have to dump out all classes as source files using the tools above, and then add them to a new Web project alongside the existing aspx pages you do have.Houseroom
Thanks...as suggested I used reflector and I am able to see all the Code in class files and code behind files. Well, I didn't understand how to use the second tool File Dissembler.. I have extracted all the dll's from .NET reflector, how can I use the 2nd tool to extract source code from those extracted dll's ??? I am sorry for bothering you...Klemperer
@Klemperer - hmm, I understand this is not easy, but I really can't help you any further. If you can't do see how to do this with the graphical tools, perhaps you can ask someone more senior with more .net experience to help?Houseroom
K
0

I found that dll can be just Read using the .NET Reflector tool but can't extract the Source Code. And also once the webforms are precompiled, we can't even get back the code behind files. All we can do is to debug and analyze the Code.

Klemperer answered 14/2, 2011 at 19:52 Comment(1)
.NET Reflector is good but it's not free tool, I found dotPeek which is free -- jetbrains.com/decompilerKlemperer
P
0

I had the similar issue and used Reflector to Decompile it. I got the source code, then changed the bit I wanted, and rebuild it. Then I copied that dll again to Production site. It started to reflect my changes. It was very easy and not at all difficult, maybe because Precompiled site had dlls for every page, and was updatable , so had only code-behind file in dll.

For reference: http://www.reflector.net/

Prog answered 22/12, 2011 at 3:12 Comment(0)
S
0

When u install .net reflecter.its import in visual studio. then you saw the .net reflector tools on menu bar.

Click on .net reflector >>Choose Asseblies (Dll file) to debug.

Savil answered 15/6, 2012 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.