Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix bugs in .NET program without access to source

I have a program i frequently use that is made with .NET. This program has a small bug that is very annoying and the developer to the app is nowhere to be found.

I have found the location of the problem in reflector and just want to add a single if-statement here and then recompile the program.

What is the easiest way to do this?

I have tried using the export-function in reflector but it doesn't seem to work perfectly. For example alot of using-directives are missing and enums that are cast back and forth to ints are also not exported properly. I believe i can fix this with some work but i'm wondering if there are any easier way to do this.

Update: Solved it by doing this:

The program is a single file executable

  1. Find the bug in reflector with C#-view. Then switch to IL-view to see what you should look for in step 5.
  2. Open the program you want to change with ildasm
  3. Press dump and select an empty folder, default settings worked for me.
  4. Find the .il file in this folder and open with any texteditor
  5. Find the code from step 1.
  6. Replace it with new code, in my case i just had to replace all the contents of a function with a simple return (IL_0000: ret). I don't think all fixes will be this easy.
  7. Open a commandwindow in the folder from step 3
  8. Run ilasm, i also had to include some resources from the original exe. These are automatically output with ildasm. I used this ilasm like this "C:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm.exe" test.il /resource=test.res /output=FixedProgram.exe

Done! I've only used the fixed program some minutes right now but it seems to work just like before except for the bug :)

I also ran into some problems with the application settings. In %appdata%\ProgramName there was a folder called something like ProgramName.exe_Url_qa5i3p42aomuvoxpuxuficvbmngksgjs where all settings are stored. My new executable created a new folder like this with different random letters at the end and with the default settings. To copy the settings you used before just copy all the contents of the old folder to the new one.

like image 278
Erik Avatar asked Oct 05 '09 08:10

Erik


People also ask

How do you fix coding errors is called?

Definition: Debugging is the process of detecting and removing of existing and potential errors (also called as 'bugs') in a software code that can cause it to behave unexpectedly or crash. To prevent incorrect operation of a software or system, debugging is used to find and resolve bugs or defects.


3 Answers

I suggest you use the Reflexil plugin for Reflector. It allows you to easily modify assemblies, and even replace the body of a method by your own C# code.

like image 83
Jb Evain Avatar answered Oct 01 '22 20:10

Jb Evain


I don't think there is an easier way to do this than what you already mentioned. I actually decompiled a program with ILDASM for something similar and it took quite a lot of tinkering.

If there is an easier method I'd like to know it too.

like image 26
rslite Avatar answered Oct 01 '22 19:10

rslite


You can use ILDASM and ILASM to make a roundtrip. While this is impractical for large changes, I think that it should do the trick in your case.

like image 39
Lucero Avatar answered Oct 01 '22 20:10

Lucero