Get the latest tech news
Writing a Self-Mutating x86_64 C Program (2013)
“Why would you ever want to write a program that changes its code while it’s running? That’s a horrible idea!” Yes, yes it is. It’s a good learning experience though.
They make for difficult debugging, the program becomes hardware dependent, and the code is extremely tedious and confusing to read unless you are an expert assembly programmer. Programmers figured out long ago that this was a bad idea and since then protections have been added to prevent a program’s code from being changed at runtime. Remember that we zero'd%rax earlier so we only have to push this register to the stack to get our NULL value.\x57push %rdi By convention, the first argument in the argv array is the name of the program.
Or read this on Hacker News