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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of self

self

Photo of C program

C program

Related news:

News photo

Tesla Full-Self Driving Veers Off Road, Hits Tree, and Flips Car for No Obvious Reason

News photo

Musk says Tesla’s self-driving tests will be geofenced to ‘the safest’ parts of Austin

News photo

Self-Hosting Moose with Docker Compose, Redis, Temporal, Redpanda and ClickHouse