I\'m looking at writing a JIT compiler for a hobby virtual machine I\'ve been working on recently. I know a bit of assembly, (I\'m mainly a C programmer. I can read most ass
I'm working on a self-modifying game to teach x86 assembly, and had to solve this exact problem. I used the following three libraries:
AsmJit + AsmTk for assembling: https://github.com/asmjit/asmjit + https://github.com/asmjit/asmtk UDIS86 for disassembling: https://github.com/vmt/udis86
Instructions are read with Udis86, the user can edit them as a string, and then AsmJit/AsmTk is used to assemble the new bytes. These can be written back to memory, and as other users have pointed out, the write-back requires using VirtualProtect on Windows or mprotect on Unix to fix the memory page permissions.
The code samples are a just a little long for StackOverflow, so I'll refer you to an article I wrote with code samples:
https://medium.com/squallygame/how-we-wrote-a-self-hacking-game-in-c-d8b9f97bfa99
A functioning repo is here (very light-weight):
https://github.com/Squalr/SelfHackingApp