PokéWTrainer freeze
Posted by: Stackout
Date: 2014-03-28 15:35:14
And first on my list was pokewtrainer..
Turns out the cause for the freeze is.. buffer overflow.
I don't know the entire specifics, but as part of sprite loading the game calls AlignSpriteDataCentered (at $16C2).
It copies data between two sprite buffers.
Now, the sprite buffers are located at the start of SRAM; there are three of them, each 392 bytes in size (7*7 tiles, where a tile is 8 bytes long). (And for those who don't know, SRAM is located at the start of RAM.)
Of course, the sprite data is abnormal. The sprite width of PokéWTrainer's front sprite just happens to be 00.
And this byte is equal to the number of loops taken. So the function loops 256 times and ends up trying to copy $179E0 bytes (or over 94KB) from $A188 to $A0F0. This obviously means both these pointers wrap around, and we end up overwriting nearly the entirety of RAM (and attempting to overwrite ROM, something that will never succeed except maybe in some lame flashcarts). Go figure.
We freeze thanks to the vblank interrupt handler. Therefore I doubt this will ever be exploitable to run arbitrary code (although I'm not TheZZAZZGlitch so…).
And yes, I know what you're thinking. Here, take a screenshot. This is what could happen to your save file.
[img]http://goput.it/a8c6.png[/img]