Branchless Doom
github.com
github.com
So we fired it up and within about 2-3 minutes he managed to shoot PID 1 or something like that as the machine rebooted. Boss was not happy.
# kill -9 1
It's init dependent (though I think SIGKILL is blocked at the kernel – I wouldn't swear to it) - sigrtmin+3 will likely kill your init process :)
I've just run # kill -L - there seem to me rather more signals available than I remember from the past. I'm pretty sure I have never even heard of the ones >16 let alone SIGRT{MIN|MAX}{|x}. I've only ever used SIGHUP or SIGKILL in general and SIGUSR1 for dd progress (which now has --progress at last)
Time to dig out the manual 8)
"The only signals that can be sent to process ID 1, the init process, are those for which init has explicitly installed signal handlers. This is done to assure the system is not brought down accidentally."
And SIGKILL can not be captured (enforced by the kernel):
"The signals SIGKILL and SIGSTOP cannot be caught or ignored."
The key detail I'll never forget is his "Oh fuck!" face when it happened.
Not all signals are blocked by init, if init wants to be signaled :)
Favourite line.
"It gets 2 frames per hour in Branchless DOOM!"
>Q: Why did you make this? A: I thought it would be funny.
Amateur.
And it looks like float and int math is handled with lookup tables. yikes! but impressive!
Another important thing here is that it's an unconditional direct jump. A conditional direct jump can still cause speculative execution (e.g. could be vulnerable to Spectre variant 1).
So, encoding logic in dependent movs does not inherently address the cache side channel issue.
History based branch prediction one difference with with explicit branches of course.
Malboge is so complicated that nobody can really write a working program.
Brainfuck is so simple that nearly anybody can write it, but reverse-engineering it is a massive time-sink.
So I was hunting a particular pattern to replace, that I knew probably existed. A simple combination of demovfuscator, regex on the "original" asm and eyeballing it succeeded in the end.
I have also seen a similar obfuscation, although perhaps not using The Movfuscator, many years ago in some shareware. You could probably guess which parts of the code used it; it even looks very distinctive when you open the binary in a text editor for a quick glance.
Company I came in as a contractor to... Sort of repair codebases and retrain staff, had a product they were getting paid buckets to support.
Unfortunately, someone had broken the codebase quite severely, and they weren't using version control. All we had was a movfuscated release (yay for paranoid managers who go to tech conferences), but needed to fix a certain feature ASAP.
So I used demovfuscator, someone's memory of what the code once looked like, and some ASM know-how to tear out references to the old and inject the new. Took a couple months of going nowhere fast, but I was pretty far out of my depth.
They don't use movfuscator anymore.
Good work all around.
I also wonder if it would be at all possible to eventually speed it up (maybe not to actual play speed, but faster) while remaining branchless and free of speculation. It might be interesting to see if research in Doom could provide faster and more secure solutions in the real world.
HN discussion of trapcc: https://news.ycombinator.com/item?id=5261598
hehe
lol
That was until I installed it on my dad's Pentium 200, the speed increased 3x and I realized it was a completely different beast.