Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decompile ASP.NET / C# Web Application

I've just inherited a web application whose source has long been lost (originally written in 2010 and shelved). The application has a few .dll assemblies that related to the application itself e.g. "applicationCORE.dll", "applicationBI.dll", "applicationDATA.dll" and "application.dll"

I've seen this question and the suggested tool (Just Decompile) is brilliant and created a .sln and .csproj file for the first assembly that I decompiled. My question is how do I merge the various projects that would be created through decompiling with the compiled web application files (.aspx) also, how do I resolve the references in the .aspx files i.e. referencing the codebehind file that no longer exists e.g. "default.aspx" references "default.aspx.cs" while the decompiler creates a "default.cs" file. Is it safer to rename the .cs file or should I update the reference?

Finally, will each dll appear as a separate project within the solution?

I realise this may be perceived as a duplicate question however there doesn't appear to be a resource online that walks a developer through the process.

like image 424
Daniel Avatar asked Aug 17 '17 14:08

Daniel


People also ask

Can you decompile C#?

You can now use Visual Studio to decompile managed code even if you don't have the symbols, allowing you to look at code, inspect variables and set breakpoints.

Can .net be decompiled?

NET assemblies to C# dotPeek is a free-of-charge standalone tool based on ReSharper's bundled decompiler. It can reliably decompile any .

How do I decompile DLL in Visual Studio?

To do this, go to the Modules window and from the context menu of a . NET assembly, and then select the Decompile source code command. Visual Studio generates a symbol file for the assembly and then embeds the source into the symbol file. In a later step, you can extract the embedded source code.

Can DLL be decompiled?

Such a DLL is compiled to machine language and can only be directly decompiled to assembly language. So, again, it depends on the language used. And the answer might be that it's just not possible to get anything resembling the original source code. Then, as stated, if it's Visual Basic, research p-code decompilers.


1 Answers

Following David's advice, I managed to get the application running from decompiled assemblies. Here's the process I followed to get it working

  1. I had already decompiled the various assemblies into projects using a Reflector (on a trial).
  2. I created a blank Web forms application in Visual Studio
  3. I added the .aspx pages from the website to the project through visual studio
  4. Then added the .cs files from the decompiled 'application.dll' project (since this is the website project within the solution. Some files had to be renamed to match the codebehind references in the `.aspx. files
  5. Each additional project e.g. applicationCore.dll was then added to the solution
  6. Each project's references needed to be updated and references to the newly added projects must be added to the startup project
  7. Since the website was built so long ago, there were 1,000's of syntax errors. The easiest way to resolve them was to use Notepad++ and the Find and Replace. To be safe, I did this file-by-file by following the errors from Visual Studio rather than a batch find and replace
  8. When trying to build I noticed errors where required assemblies were missing so I changed the build output directory of the sub-projects to the bin folder of the web project
  9. I added the connection strings and settings from the original website's web.config. I did this line by line to make sure I didn't break anything and so that I could trace the result of each addition
  10. Finally I had a successful build!

Additional Steps There were also syntax errors which I assumed were due to the decompiling process. Some external references needed to be added and there were slight changes due to the age of the project e.g. asp:AjaxScriptControl changed to asp:ScriptControl (after adding the package using Nuget). I also had to install Crystal Reports for this application and will have to purchase a Telerik licence as there are UI components being used (although I'll see if I can use an open / native alternative as I work through the app).

I've logged in using credentials (I did have to set the correct start page) and tried a few basic CRUD operations. There are silly issues that have to be resolved e.g. the authentication doesn't work properly and there's no redirect if you access a protected page but these things are relatively minor compared to the issues I faced initially.

What I must say is each error was resolved using questions and answers from this site! This was all completed in just under 6 hours.

like image 104
Daniel Avatar answered Oct 10 '22 20:10

Daniel