If you add new instructions, the addresses in operands should be changed.
So, adding a new executable section after the end of the executable file will be OK.
Sorry, I should've been more specific. I'd like to know of any C or Python libraries that can be used to do this, and any approaches others have taken.
So far I figure I can probably use pydasm or libdisasm directly, and write back to the binary using basic binary I/O calls.
The code snippet creator maybe easier to start with.
Years ago, I used pefile + pyasm + IDAPro to create PE file manipulation utility that can modify functions.
radare let you to do this in interactive mode or automated in radare scripting or from ruby,python,perl or lua. It also supports multiple syntax for assembling (frontends for nasm,gas,olly,..) and PE/Elf/Mach0/Class information is supported too.
If you need something else, let me know
Note: Registration is required to post to the forums.