How to compile the dll back after decompile C# dll? - c#

I use reflector to decompile a asp.net dll, after that I find the bug and fixed it, now I want to compile it back to a dll, then I can deploy, but it seems that I can't how can I do this ?

You have two choices, either you use Reflector's addin Filedisassembler, which is free, or commercial ( and pricy) .net dissemblers such as spices.net or salamander decompiler.
I used Filedisassembler; the quality of the decompiled code is very bad. The decompiler code cannot be recompiled.
I'm sure about the quality of commercial decompilers but I suspect that it would be much better.
Edit: To use Filedisassembler, go to Reflector, View->Addins, click Add and select the Filedisassembler.dll.

If the fix is simple enough and you know IL, you are better of round tripping it using IL instead of a high-level language such as C# or VB.Net.
See search: http://www.google.com/#hl=en&q=ildasm+IL+round-tripping

Related

how to get source code from dll in C#

I have an assembly which is not strong-named. I have no source code for it.
I now need to recover the source code . Is there a way to do this?
Use decompiler such as dotPeek or ILSpy.
Be aware of the fact that code is decompiled using IL code that resides in .NET assembly it may be different from the original code used when compiling the assembly.
I can recommend RedGate .NET Reflector. You can try 14 days trial version.
At work we used to use Reflector, until we learned that dotPeek is free. It serves us well.

Decompiler and repacker for .NET

Is there a tool which allows me to decompile a .net dll, edit it and repack it back to dll again?
I use dotPeek a lot. It can't repack or edit.
While Reflector is cool - but it's not free.
There is Mono.Cecil - which is a lower level tool that can modify assemblies. The two I now use most often are:
JustDecompile and DotPeek
Reflector is one of a kind. I have successfully created c# projects from binaries and recompiled them.
Bear in mind that protected assemblies are difficult to decompile, also they may be obfuscated or protected against ILDASM.

Are we looking at the original code in a Disassembler or reverse engineered CIL?

Take ILSPy. When I view my assembly am I looking at my original C#? Or, is this code reconstructed from CIL using some type of reverse engineering process?
My understanding is that release assemblies do not include any original code, just CIL. So, does it make a difference if I build my assembly in release mode?
Neither release nor debug assemblies contain original source code.
ILSpy & friends analyze the compiled CIL to extract a reasonable C# equivalent.
Release vs Debug still makes a huge difference. The compiler does optimize. See Scott Hanselman's post about Release vs Debug.
In terms of what ILSpy does, yes it displays CIL and then reverse engineers it to a reasonable C#/VB representation. I'll admit ILSpy does a very good job with it! I've reversed others' assemblies with it and can make perfect sense of their code. The only time I've had it break down was with WPF and GUI stuff, but I'm sure there are ways to work that as well.
In terms of preventing reversal of your assembly and protecting your intellectual property, use Dotfuscator or other obfuscation tool.
You are seeing code reconstructed from the IL. This reconstruction process can be performed on any .NET assembly regardless of whether it is built in debug or release mode.
You can't prevent your source code from being reconstructed from your assembly in this way, but if you want to make the code less useful/understandable you can use various .NET obfuscation tools.
Actually, you could use ILMerge or .net FuZe to wrap your exe and dlls into an exe or dll container, making it more difficult to disassemble.

.Net Assemblies Decompiler that Convert Assemblies into C# Source Code

I am well aware that one can use reflector to browse the content inside an assembly, and one can use FileDisassembler to convert the content into the c# source code with cs projects. But the source code outputted by FileDisassembler may not be able to compile if it has interface with property.
Is the other similar applications that do what FileDisassembler does?
I would not trust Reflector's decompiler.
Many times I have seen it just ignore instruction it did not understand, or just optimized certain sequences away, and changing the meaning the process.
The only trusty way is to use IL.
Regarding more tools, look at the CCI. IIRC, they had a C# source emitter at some stage, but it was removed for some reason.
dotPeek from jetBrains is a good decompiler for c#. http://confluence.jetbrains.net/display/NETPEEK/dotPeek+Early+Access+Program

(.net) Intermediate language exe editor?

I know we have ILdasm, but is there any tool out there that will let me edit .exe or .dll files without having to go through all the rigmarole of having to convert it to IL code, with resources includeded, etc etc, manually edit, then recompile again?
You could always use Reflector to disassemble whole namespaces to source code (not IL), but then you're still stuck without a direct editor, you have to copy/paste to a code file and recompile.
On the other hand, it seems like I was wrong, Reflector has an add-in Reflexil that looks like it'll do what you want.
check out this SourceForge project I guess it's what you're looking for:
http://sourceforge.net/projects/dile/
Perhaps you should check out Mono.Cecil. It's a managed library for manipulating IL. You can add, remove and modify methods as you please.
Granted it's not an IDE or anything but it should be a starting point.

Categories