0

I have a DLL written in C# for which I don't have the sources. I have tried different C# decompiler to modify the DLL, but they all give me errors in my attempts to recompile with the modifications, I suppose due to IL decompilation limitations. Is it possible to add a .cs file to the root of the DLL in order or inject a method to add a functionality ? PS: This is not intended to hack a software but to create a mod of a game which requires DLL modification.

cgcmake
  • 103
  • 3
  • Have you tried compiling without modifications? If that works, the error probably lies in your additions. And have you checked all references? – derpirscher Jul 22 '16 at 16:58
  • Compiling without modifications also give me errors. The references are too numerous to know if the errors come from them. – cgcmake Jul 22 '16 at 20:59
  • To be able to compile you'll have to setup a valid build configuartion, which also includes setting the correct references. If you don't do that, you won't be able to compile. What errors are you getting? – derpirscher Jul 22 '16 at 21:07

3 Answers3

2

Your best approach may be to just create a wrapper project around the dll to add the functionality that you want. Your code could them reference the project instead of the dll. As long as the classes aren't sealed you should be able to inherit from them.

Modifying code you don't have access to probably isn't a good idea to begin with. Especially if the dll could be updated in the future.

1

You can also create a new DLL with the same namespace. This might make things look as if they're in the same location, but it's not the best practice and it could be confusing since namespaces are expected to match the project/dll name.

Benjamin's solution with the wrapper seems reasonable.

Ahmad Farid
  • 14,398
  • 45
  • 96
  • 136
0

The Reflexil plugin for .NET Reflector could inject a method or a class in a DLL as illustrate in a video by its creator. It prevents decompilation-compilation errors as it just injects IL code in the assembly.

To install this plugin follow these steps.

Community
  • 1
  • 1
cgcmake
  • 103
  • 3