Can a C program modify its executable file?

后端 未结 9 2031
情歌与酒
情歌与酒 2020-12-29 04:35

I had a little too much time on my hands and started wondering if I could write a self-modifying program. To that end, I wrote a \"Hello World\" in C, then used a hex editor

9条回答
  •  误落风尘
    2020-12-29 05:06

    It is very operating system dependent. Some operating systems lock the file, so you could try to cheat by making a new copy of it somewhere, but the you're just running another compy of the program.

    Other operating systems do security checks on the file, e.g. iPhone, so writing it will be a lot of work, plus it resides as a readonly file.

    With other systems you might not even know where the file is.

提交回复
热议问题