I have seen code that adds or removes sections from PE files after they
are created, but it's non-trivial. Apparently offsets in the PE file
are all absolute (rather than relative to the section), so adding more
code at the beginning of the file mucks everything up.
Can you cheat a bit? How
You cannot reliably use the return value of tellg for a file with
windows-style endlines opened in text mode due to the following bug
https https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64064://
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64064gcc.gnu.org