How to decompile ASP.NET web application [duplicate] - c#

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 ?

Open the DLLs in the .NET Reflector.

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:
Get .Net Reflector from here: http://www.red-gate.com/products/dotnet-development/reflector/
You do not seem to need FileDisassembler.
Either load your bins in Reflector or double click them.
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.
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.

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.

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/

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.

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.

Related

Modify Compiled .Net Exe

I have an application written in C# (without the source of course), that needs to be changed a little bit. For example, I need to stop a few lines of code that create an unnecessary menu. So I think I should comment them out.
The source code is not obfuscated. I know I can completely decompile, change, and compile again, using tools like Reflector/Reflexil. But everyone knows that by doing this, many parts of code won't compile again! Is there a way in Reflector (or any other product) that a part of could be disabled/changed without this process?
Thanks.
You might want to try dnSpy. It is a .NET assembly editor, decompiler, and debugger forked from ILSpy.
https://github.com/0xd4d/dnSpy
If you really needed to do this, you could decompile it with Reflector (or a similar product) and then use that to try to recreate a solution in .Net that will produce the same executable.
You may run into issues around:
Obfuscated code
Sections where the decompile shows you accurate code for specific sections, but for some reason it just doesn't work in your new solution (and then what do you do?)
This is not to mention the potential legal issues related to doing this. If the executable was released under a license that would permit you to do this, then you would most likely have access to the source code. So the fact that you do not have access to the source code implies that doing what you are suggesting might not be legal.
Eventually I managed to "disable" a few lines of code in the compiled exe.
I used Reflector with Reflexil plugin installed. Reflexil allowed me to edit an MSIL instruction, and then save the result back to an exe file. So, it involved learning a few MSIL instructions, especially the "no operation" command (making a line of code do nothing). To see the list of instructions and a tutorial, see here and here.
Hope it helps someone else.
for the sake of completeness:
Another possible solution is to use the ildasm http://msdn.microsoft.com/en-US/library/f7dy01k1%28v=vs.80%29.aspx
MSIL Disassembler, edit the MSIL and feed it back to ilasm.
How practical this solution is, depends on you of course
This thread may help: dotnet dll decompile and change the code
Last time When I tried with decompile the source using reflection, I got too many compilation issues with regarding to resources and other subs though the dll isn't obfuscated. So there could be things beyond just extracting the source and modifying in order to make your new dll work as the old one.
SO I would suggest to go with direct dll manipulation using any of the options mentioned in the other thread.
If you have source code on the same machine on which you are testing your exe file, and if you are making changes in your sourcecode in visual studio, then while compiling it will automatically get reflected in your exe file.
You need not do any special thing for it. And if it is not, then just make the changes in code and paste your debugg folder's new exe (with debugg folder) on another machine having all recent changes.

Including 3rd party code as source vs dll

There is a Github project for a C# library that I'd like to use. Is it more conventional to include the source as a separate project in my Visual Studio solution and build the dll as part of the regular compilation process, or to build a dll separately and include just that in my project reference?
Unless you need to modify the source, use a DLL. Don't forget to mention the license and the source repository location (home of the Github project)
Both the options are equally valid and depends upon how often you require the change the source code.
If you really need to change the source code then you should add the
source code to your project otherwise just adding the reference of the dll will save your
compilation time.
I have seen both approaches.
Mostly I've included 3rd party code into the solution if I intended to modify it a little, or at least I assumed I would.
All other cases, Dll works fine.

Orchard: Full Source or Not?

We're going to be using Orchard as a base for a particular client. We're a C# shop running VS2K10. We'll throw it in our version control system as per the norm for our projects.
That said, we'll be creating custom modules based on the needs of our clients. What approach does everyone here recommend?
Get full source from CodePlex and check that in
Download just the Orchard web code (similar to Web Platform Installer)
Problem with #1 is that the code base is rather large, but it will allow us to debug the site locally when developing.
What are the caveats with #2? Lack of debugging?
I'm curious what everyone's approach would be for this. I'm inclined to go with #1, get the full source, throw it in SVN, and build off of that.
Thoughts?
If you are going to develop modules using Visual Studio, just use the full source code. Disk space is cheap.
Caveats with #2 are that it's immensely less comfortable. Why bother?
I use the full source version, but I only check the modules and themes that I'm working on into source control.
I did originally use just the web code, but found myself running into lots of little problems that were much easier to track down when using the full source.
I found that only source controlling the stuff I was working on made updating to later versions of Orchard much easier.
I'm no software engineer, but here is what I would do :
Get the source code.
Add it in your VS solution and source control.
Do NOT reference the project(s).
Add a post-build event on that project to copy the dll and the symbols (for debug) in the folders of the project that would otherwise refer this one.
If it crashed in a class from that project's assembly, you'll be able to specify the source code files since you got the symbols, and since you won't be modifying that project on a regular basis, your VS won't rebuild it every time. You could even unload the project if you want to save some memory, however trivial it might be.

recover lost C# pages

I had a problem I lost all my source(CS) of web site pages but I had only published pages on server ,so please if there is any way to recover theses published pages to orignal pages with code,bin folder
You need to decompile the C#. It is an advanced user scenario, but it can be done... sort of.
How do I decompile a .NET EXE into readable C# source code?
try to use reflector. it help you to restore all your code
Use your latest backup copy, or roll back to the previous version of SVN you are working on.
http://www.red-gate.com/products/dotnet-development/reflector/ is a good piece of software for recovering source from a compiled program.
If your project was a website, you should be able to ftp each file from the server 1 for 1. If your file was a web application project, you're hosed. The code files are compiled into a binary, and if you lost the source code it's gone.
http://www.red-gate.com/products/dotnet-development/reflector/ Can decompile .NET assemblies into source code - however it won't be the code you wrote as alot of it will have been changed by the compiler (IE your comments will have gone bye bye)
You can then rebuild your Project in your IDE of choice and you are done.
If the assemblies haven't been obfuscated, you can use reflector to recover your code from the assemblies.

Using Reflector To Create VisualStudio Project

I have a .exe app which I want to understand better - I can see it in reflector
Is there any way to get reflector to create a VS project with the code so I can view it properly in Visual Studio?
Nothing special is needed, it is built into Reflector, albeit not very discoverable. Right-click the assembly in the left pane and choose Export. You'll get a chance to change the output directory. Click OK and Reflector starts decompiling the code, creating a source file for each individual class. And creates a .csproj file which you can open in Visual Studio.
Check out Jason Bock's FileGenerator, it might be what you are looking for.
I've used Denis Bauer's Reflector.FileDisassembler http://www.denisbauer.com/NETTools/FileDisassembler.aspx. It works well enough to compile and step through the code.
Yea there is, but it doesn't come cheap
http://www.remotesoft.com/salamander/
I have used it to decompile assembly, but I've never used the feature to decompile it into a project so can't give you a review on that. The quality of the decompiler will match the one in reflector.
They also be some legal issues associated with decompiling exe into project - and source for recompilation, so use it with care.

Categories