Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support modifying .dlls via CLI #318

Open
lerarosalene opened this issue Apr 26, 2024 · 1 comment
Open

Support modifying .dlls via CLI #318

lerarosalene opened this issue Apr 26, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@lerarosalene
Copy link

Problem Description

I am currently able to modify .dlls via editing C# sources in GUI. But there seems to be no documented way to patch .dll via dnSpy.Console.exe.

I suspect that it should be possible to decompile .dll fully to source code, introduce changes and compile it back, but I am not sure how (and if contents of decompiled files are guaranteed to be the same to reliable apply diff patches). But if it's the intended solution, then I'm dumb, sorry.

Proposal

Add CLI flags to introduce changes to .dlls based on modified source code of methods.

Alternatives

No response

Additional Context

No response

@lerarosalene lerarosalene added the enhancement New feature or request label Apr 26, 2024
@ElektroKill
Copy link
Member

The CLI app is very primitive and is currently written in a way that allows only decompilation of a given file. It lacks all the necessary infrastructure to run the other components of dnSpy like assembly editing, debugging, etc. Extending the CLI app to add more functionality is something I want to do especially for debugging.

However, I'm not sure how text-based C# level assembly editing would be implemented in a CLI. If you want to apply C# level patches it is probably best to fully decompile the file using dnSpy or ILSpy to produce a C# project file/solution file, apply text-based patches onto the source code, and then recompile. It is not the ideal way of applying patches to files though. The C# editing is only meant to be a quick way of applying patches to files manually. Automated patching should always do what is described below.

Ideally, you'd want to use a lower-level library like dnlib and edit assemblies on the metadata and CIL code level. This is a lower level than C# and makes it so you do not have to recompile the code. Libraries like dnlib can open a .exe and traverse the type structure similar to dnSpy and edit methods and method bodies in a way similar to Edit Method dialog and Edit IL instructions option. This ensures that parts of code you are not patching do not undergo changes as a result of decompilation errors.

Hope this answers your questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants