>>31
Yes I am aware.
There is nothing "high fantasy novel" about writing self modifying programs.
First allocate some memory. Now get a pointer to that memory and write a program there. To "evaluate" that program either x86 JMP your way there (or equivalent inline assembler) or (, if your new program obeys the "host" (for lack of a better word) program's compiler's various conventions) cast the address to a function pointer. This is called run time (or dynamic) code generation. It's done all the time e.g. my Common Lisp implementation does it, as does the Hotspot JVM.
Now, If you want to change that program, then just write to that same memory. This is called "self modifying code".
If you want to specify the programs you write to that memory in some language, then you need to be able to compile that language. For example you may want to use libtcc if you wish to specify programs in C.
Now, because of "modern" operating systems you can't just allocate memory and have it be executable willy nilly; you have to ask first. If you are on Linux you want mman.h (specifically
mprotect
) and if you're on Windows you want Windows.h (specifically
VirtualProtect
). idk about other operating systems.
I should add in the case you want to modify the "host" program directly as it is in memory, you use function pointers or your compiler's equivalent of GCC's labels as values extension and then jump whatever hoops your operating system require you to.
Again, this is not esoteric, macho or arcane. It's just programming.