Lurker News
OFRAK Tetris is a project I started at work about two weeks ago. It's a web-based game that works on desktop and mobile. I made it for my company to bring to events like DEF CON, and to promote our binary analysis and patching framework called OFRAK.

In the game, 32-bit, little-endian ARM assembly instructions fall, and you can modify the operands before executing them on a CPU emulator. There are two segments mapped – one for instructions, and one for data (though both have read, write, and execute permissions). Your score is a four byte signed integer stored at the virtual address pointed to by the R12 register, and the goal is to use the instructions that fall to make the score value in memory as high as possible. When it's game over, you can download your game as an ELF to relive the glory in GDB on your favorite ARM device.
The CPU emulator is a version of Unicorn (https://www.unicorn-engine.org/) that has been cross-compiled to WebAssembly (https://alexaltea.github.io/unicorn.js/), so everything on the page runs in the browser without the need for any complicated infrastructure on the back end.
Since I've only been working on this for a short period of time leading up to its debut at DEF CON, there are still many more features I'd eventually like to implement. These include adding support for other ISAs besides ARM, adding an instruction reference manual, and lots of little cleanups, bug fixes, and adjustments.
My highest score is 509,644,979, but my average is about 131,378.
I look forward to feedback, bug reports, feature requests, and strategy discussions!

Comments (53) 23 threads

once_inc#
As a programmer with practically 0 experience in working with assembly, this is a pretty cool tool to learn! I've been holding a cheatsheet in another tab to find out what each instruction is doing.

Kudos for building this, very cool!
edit: getting -4.8 billion as a high score because of my first segfault was... a disappointment, though. :-P

LoganSnow1 reply#
This is really cool! So far I have a high score of 65612 :)

Some feedback:
- When opening the help menu, it wasn't obvious how to close it (I think the only way is by pressing '?')
- I like the Goblin music!
- It's a pretty nice interface to play with the instructions and I appreciate the color coding. It would be neat if there was a "sandbox mode" where you could preview the effects of running an instruction, and maybe modify your program once the game is over. I could see this being pretty useful for someone learning ARM assembly.

jstrieb#
I like the idea of sandbox mode!

I'm definitely much quicker at reading ARM assembly after playing a few hours of this game over the course of making it.

mpeg2 replies#
This is so clever, I couldn't help but smile when I saw "Your score is stored in memory at the address pointed to by R12" :)

Thanks for sharing, it does makes me miss DEFCON, maybe next year...

velosol1 reply#
Is the reason for R12 making you smile something you could share?
mpeg#
It's the fact that the score is handled within the game mechanics itself – so the way to get a high score is not just to play but to play with the goal of modifying R12 (so it points to a high value)

They could have easily made score be handled outside the game and you get a point per every executed statement within the time limit etc – but that would not be as fun

Jerry85381 reply#
> Your score is stored in memory at the address pointed to by R12

As someone who has very little idea of what instructions or addresses are, what is this a reference to?
Edit: I had the page loaded before your reply, so I didn't see it until I replied, reloading the page lol

justsid1 reply#
It's not a reference, it's just a really neat game mechanic. Normally the high score is guarded by the game and changes only if the game deems it fit to change it. In this game, because the high score is accessible within the game and you can execute arbitrary instructions, you can use that to modify the high score.

It's as if in a more normal game the high score was kept in a big chest somewhere in the game world and once discovered you can start messing with the contents of it all within the rules of the world itself.

jstrieb1 reply#
So far, I've used two good strategies:

- Spray PC into as many registers as possible, try to add those registers together as many times as possible, and store the sum at zero (or wherever the score ends up)
- Load an assembled instruction from an old value of PC as an int into a register, then do some subtraction to make it non-negative (since it's usually negative in my experience), then store in the score location
I'm curious what other strategies people have tried?

stavros#
I've had a lot of success segfaulting the game, as I don't know any assembly.

Load more comments