quantumpotato
quantumpotato

Reputation: 9767

Reading a program's own memory as data

I'm watching Mario glitch

Where the Mario gameboy cartridge reads its own memory as level data.

How can I get access to the current memory of a program I'm running? (Any language though I'm thinking C or Assembly is the place to start)

Upvotes: 2

Views: 83

Answers (1)

Iverelo
Iverelo

Reputation: 146

In assembly you can read the ESP (stack pointer) and EIP (instruction pointer) registers directly. They will have the address to the top of the stack and the current instruction respectively. From there you can read the memory that is the stack and instructions directly.

In that video they overrun the level data and the game started interpreting the stack data as level data. He then writes to an offset in the stack by breaking bricks that contain the memory for the next level to enter.

Since it is always the same bricks with that same data that means the memory layout is very deterministic which is no surprise for an old cartridge system where nothing else is running on the processor. You could straight up write the data if you had console access and knew the offset.

Upvotes: 2

Related Questions