Is there a way for a program to know if it's executed under the simulator and not on an actual CPU?
... you haven't given one single reason why it would be a problem to program a specific memory cell by the debugger script ...
Well, because it wouldn't be a problem! It's sad if you have the impression that I'm rejecting this method out of hand. Actually, this is a good method, arguably better than mine. I just need some time to think which one I'll be using...