Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit a hardcoded string in compiled DLL?

I have a single compiled dll which i need to change a little. It was written by me half a year ago, but I've lost the source code. There's one single hardcoded string in it (it's a filename)

I need to change it from TestPage.html to TestPage1.html (it's not much longer)

How to do that? The string is anonymous, the corresponding piece of code is:

... + folder + "TestPage.html"

There's no variable it's assigned to.

Thanks in advance.

EDIT: I do not want to recompile c# code after extracting it with Reflector-like tools!

like image 337
Ilya Smagin Avatar asked Sep 27 '11 09:09

Ilya Smagin


People also ask

How can I change DLL file without source code?

You can use reflector. However, I didn't mention it as it may be illegal to modify the source code, depending on the licensing terms. Also, if the original creator obfuscated the assembly, that's going to create problems with what the final source code looks like.

How do I open a DLL file and edit it?

You can easily open a DLL file in Visual Studio the same way you would any other file. To do so, click File in the menu bar at the top, followed by Open. Then click File and select the DLL file you want to open and click Open. This will open the DLL file in a new Resource Editor window.


3 Answers

You could use CFF Explorer, which provides a very raw view on .NET assemblies. It also provides the possibility to view and even modify the UserString-stream (find it under .NET Directory > MetaData Streams > #US).

The UserString-stream stores string literals as the one you described. You should be able to find your particular string with the find-function and modify it. However, there is a limitation: You cannot use a string with a different length (shorter or longer). This would mess up the indices of all strings that would follow later on in the UserString-stream and all the offsets of the other sections. So, unfortunately I think changing it to TestPage1.html will not work, as it is one character longer.

like image 157
chrisn Avatar answered Oct 21 '22 05:10

chrisn


Use Reflector (or other similar tool) to decompile IL into C# (or another CLR language), and then - edit and compile it again.

like image 25
abatishchev Avatar answered Oct 21 '22 03:10

abatishchev


You can use the free tool ILSpy to decompile the code and ressources from a .NET-dll file.

like image 44
Alexander Avatar answered Oct 21 '22 03:10

Alexander