I have an existing Win32 .exe with a PE stub in the beginning, and I have another PE stub stored in a separate file. This separate PE stub is longer than 20 KiB, the original PE stub is at most 512 bytes. I don't have the source code, so I'm not able to recompile or relink. How do I replace the PE stub in the Win32 .exe?
Probably I need a tool for that which updates section file offsets. But that's not enough: according to diff of the outputs of objdump -x file.exe, these also have to updated: AddressOfEntryPoint, BaseOfCode, BaseOfData, SizeOfImage, SizeOfHeaders, offsets in the data directory, addresses in relocation fixups.