Writing a Self-Mutating x86_64 C Program (2013)
Published on: 2025-06-27 15:00:26
“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. This is not something you would ever do outside of exploring a curiosity.
Self-mutating/self-modifying programs aren’t useful for a whole lot. 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. The only good use for self-mutating programs in the wild I know of is as a cloaking mechanism for malware. My goal is purely academic so I venture into nothing of the sort here.
Warning: This post is heavy on x86_64 assembly of which I am no expert. A fair amount of research went into writing this and it’s possible (almost expected) that mistakes were made. If you find one, send an email so that it may be corrected.
The first step of writing a self-mutating program is being able to change the code at run
... Read full article.