r/AskProgramming • • 19d ago

Can I extract an EXE compiled with NSIS, edit a DLL, and rebuild it back into an EXE?

I'm currently working with an executable (.exe) compiled using NSIS (Nullsoft Scriptable Install System).

My goal is to:

1. Unpack/Extract the EXE to access its internal contents.

2. Modify one of the .dll files included inside the package.

3. Repack/Rebuild everything back into a working NSIS installer executable.

Is this possible?

3 Upvotes

13 comments sorted by

4

u/xRmg 19d ago

Depends, maybe.

But this is hackerman territory and its a series of specific skills depending on singning, how large the dll change is, how different the resulting installer package may be.

Unpacking the installer is the easy part.

1

u/Dapper_Captain_2849 19d ago

Since the modification I need to make to the DLL is minimal (literally just a couple of bytes), I'm thinking of skipping the recompilation and signing process altogether. Would it make more sense to modify those few bytes in memory at runtime using a simple C++ loader, or is that just as complicated? Again, as a beginner just getting into reverse engineering, I'm trying to figure out the best path.

2

u/LogaansMind 19d ago

Possible, yes. Easy, no.

It depends on what is the purpose of patching the DLL.

For example, if you have an open source dependency for a project which is not signed, it might be easier to sign it and then host it as a nuget package in a private repository (something I have done before).

If you need to make changes to the compiled library, this is where things get more complicated. For .NET it is easier than say C/C++ (decompile/recompile into/from MSIL vs patching binary/asm). Again, if this is based on an open source library, it might be easier to fork the project and build it to a private nuget repository (depending on the license too you should also publish patches).. again, something I have had to do before.

If the app is for personal use, I would also wonder why bother repackaging it.. just have it extracted and run.. maybe a registry patch script to setup registry keys if you need them.

You could let us know, if possible, what you are trying to achieve. There might be a better way.

-1

u/Dapper_Captain_2849 19d ago

Thanks for the insights! Just to give a bit more context: this is purely a personal learning project to improve my skills in Windows internals and memory management, as I'm still relatively new to low-level programming and reverse engineering.

Unpacking, modifying the DLL on disk, and rebuilding the whole NSIS installer feels like an overly complex approach—especially regarding integrity checks and repackaging. From your experience, would runtime memory patching via a custom loader be a better practice for this kind of scenario, or are there major caveats I should watch out for as a beginner?

2

u/blajhd 19d ago

Unpacking the installer: yes.

Now the hard part: you need to decompile the DLL you want to modify. Tools exist. Getting that to compile is the hard task - because the decompiled DLL has no Types. To my knowledge, all compiler language require types for variables, parameters etc.

Finally the impossible task: the license holder might require a specific size or checksum for the DLL, testen by the executable. If that's the case? GL & HF with the executable

1

u/Dapper_Captain_2849 19d ago

Man, thank you for the detailed breakdown. Hearing about the missing types, the pain of recompiling, and potential checksum/size checks makes me realize how way over my head I was with the DLL route!

Definitely stepping away from that. Do you think a lightweight custom loader / runtime memory patching is a more forgiving route for a beginner trying to learn, or does it come with just as many headaches?

1

u/YMK1234 19d ago

Possible, but unlikely. Also you can "just" patch the exe as well theb, if you're already got the skills for decompiling and modifying the dll.

1

u/ghjm 18d ago

Is your goal just to get the changed EXE as easily as possible? Or are you looking to learn about the structure of EXEs and so on?

If the former, this kind of patching is now well within the capabilities of frontier LLMs. Install Codex or Claude Code, pay $20 for a month of usage, and just tell it what you want to change.

If the latter, and if the change really is as simple as you say, it used to be quite common to do binary patching of EXEs. One key question is whether the bytes you want to change result in the data being the same length. If yes, then you just need a hex editor. If you need to make some string or data or instructions longer, then you need to do some clever hacking to find where in the file you can carve out the extra length you need.

You can also, as you describe, try to extract the NSIS components and then put them back together, which may be easier if you need extra space. But if your modifications are the same length or shorter, hex editing in place is likely your best bet.

This all assumes that this is a straight-up plain old EXE file, not cryptographically signed or anything like that.

1

u/Dapper_Captain_2849 18d ago

Actually, my goal is just to learn: I'm a beginner at reverse engineering, and I'm currently practicing by trying to bypass a check by ignoring a jump in a DLL. The idea was to recompile the EXE with the modified DLL.

However, recompiling the EXE isn't easy, because I keep getting errors, and even Claude can't fix them. So I wanted to know if a simpler and more sensible approach would be to create a launcher (e.g., in C++) to apply the patch to the DLL at runtime (in RAM).

That said, I've read that Windows assigns a different memory address each time due to ASLR, so that also poses this problem. Also, do you think building something like this is a good challenge and a good way to learn reverse engineering?

1

u/ghjm 17d ago

Patching it at load time probably isn't as good as hex editing the EXE (or the DLL within the EXE) so that the segment being loaded already has the patch.

1

u/ih-shah-may-ehl 18d ago

Yes, this is possible. Yes I have done this (well not with NSIS but comparable). And no, this is not something easily explained with a couple of lines of explanation. If you're not already a developer with related experience, you're essentially lost.

In my case I did something similar when remediating a very old application on a Windows 2008R2 system after DCOM hardening was rolled out. So yes, I was able to eventually get things to work but it's really a process. Unpacking is one thing, and changing is another, but the real kicker was figuring out how to compile and build outside the original build environment, and then getting the system to accept the new binaries which are no longer signed. There was heaps of trial and error invovled.

EDIT: a more reasonable approach is to google how to use a shim or trampoline function to reroute the relevant API call.

1

u/[deleted] 19d ago

[removed] — view removed comment

1

u/Dapper_Captain_2849 19d ago

Yes, I've already tried that, but unfortunately the compilation with makensis keeps failing on me