4 ms·
All that work, and then he hits the expected killer problem - self modifying code. Getting past that without an interpreter is going to be tough. Not impossibl
by Animats 9y ago
All that work, and then he hits the expected killer problem - self modifying code. Getting past that without an interpreter is going to be tough. Not impossible, because the self modifying code isn't that dynamic in the places he found it. It's not like it's reading external input and compiling it. There are a limited number of cases to be handled.
It's amusing seeing this in a machine which gets its code from a ROM.
- Perseids 9y agoWhich is one of the reasons I hope WebAssembly becomes the de-facto standard for binary code distribution: It preserves more structure of the original program and allows less of the lowest level shenanigans (it provides a clear and protected control flow, has a small instruction set, no dynamic code generation, and no instruction misalignment / dual-alignment).
- zokier 9y agoWait, WASM disallows all dynamic code gen? That sounds really disappointing. How do JITs work on WASM?
- dangerbird2 9y agoThey don't now. The spec will almost certainly allow some form of dynamic code generation/loading in the future http://webassembly.org/docs/future-features/#platform-independent-just-in-time-jit-compilation http://webassembly.org/docs/future-features/#platform-indepe...
- pvillano 9y agoPreface: these are the questions of a CS student, not attacks. What about java/.net/regex engines? Is it required that they exist outside the browser, or are performance limited to interpreting, or is there a better solution? What's the problem with the control flow of assembly?
- boomlinde 9y agoThat example is not self-modifying, though. The BIT absolute instruction simply uses the LDY immediate instruction as operand data by means of overlapping them. This saves some bytes as you'd otherwise have to use relative branching (and there's no branch-always) or a three byte jump to load a different Y value, but the code remains unsabotaged. These tricks are IMO an indicator that they had a good idea that the game code was going to be a tight fit (or had possibly already discovered that the hard way), so they were optimizing for size. A jump would be faster than executing the BIT instruction. The manually loading an address to the stack and running RTS is an interesting trick. Wozniak used it in his SWEET-16 interpreter, pushing the interpreter loop entry point to the stack before jumping to the subroutines that execute the byte code, just so that he could use RTS to return to the interpreter loop. In that sense it fulfills an entirely different purpose than a JMP indirect and also saves some bytes, again at the expense of execution speed and non-gray hair. For a table based interpreter, it fills gap left by the lack of a JSR indirect instruction.
- dzdt 9y ago> It's not like it's reading external input and compiling it. Some games, because of bugs, allow exactly that. User input might be directly executable. That means that static compilation cannot be achievable in general. Either you have different behaviour in the event of such bugs or you have a full interpreter to fall back on. [1] https://www.polygon.com/2014/1/14/5309662/bizarre-super-mario-world-hack-turns-the-game-into-pong-snake https://www.polygon.com/2014/1/14/5309662/bizarre-super-mari...
- Gaelan 9y agoThat's an SNES game.
- XR0CSWV3h3kZWg 9y agoArbitrary execution in super mario bros 3 here: http://tasvideos.org/4961S.html http://tasvideos.org/4961S.html