logoalt Hacker News

Pannoniae • yesterday at 5:17 PM • 2 replies • view on HN

Self-modifying code is a meme unless you're writing an obfuscator... (but even then you can hook the execution so it's a pretty low-tier anti-reversing effort ngl)

For perf reasons it's the equivalent of shooting your leg off to lose weight. You're flushing the instruction cache and breaking prefetch, leading to a huge stall. Then you do it again. And again. It hasn't been in vogue since the 80s...


Replies

pfdietz • yesterday at 6:34 PM

JIT compilers are essentially producing self-modifying programs (or, indeed, dynamically loaded libraries).

Dynamic languages, like Common Lisp, where things can be redefined at run time likely require modification of running code to achieve high efficiency (the alternative is to just leave a general mechanism in place and accept the runtime overhead and loss of optimization opportunities from that.)

someonebaggy • yesterday at 5:40 PM

That depends how far in advance of running the code you're modifying it. You could see a JIT compiler as an extreme type of SMC. Or a Monero miner - its hashing algorithm relies on running randomly generated programs.

➕ show 1 reply