Vector35 / binaryninja-api

Public API, examples, documentation and issues for Binary Ninja
https://binary.ninja/
MIT License
940 stars 213 forks source link

Option for specifying the stack growth direction of an architecture #5703

Open nootkroot opened 4 months ago

nootkroot commented 4 months ago

It'd be nice to be able to specify what direction the stack grows for an architecture. Right now binja assumes the stack always grows down, so LLIL_PUSH will subtract from the stack register and LLIL_POP will add to it.

I'm currently trying to make an architecture plugin for yan85 (custom architecture used in CTF challenges on pwn.college). The stack in this architecture grows upwards, but I can't seem to figure out a way to nicely implement this behavior. I've tried to manually implement the push and pop instead of using the normal LLIL_PUSH and LLIL_POP by modifying the stack pointer properly and loading/storing, but it led to an objectively worse looking decompilation.

I imagine the feature wouldn't be too hard to implement, as it would just change whether push and pop either adds or subtracts to the stack, but that's just my guess so I could be completely wrong.

8051Enthusiast commented 1 month ago

This is also a problem on the 8051 architecture. Another difference is that it pre-increments the SP on push instead of post-incrementing (which can mostly be worked around by subtracting 1 on loads of SP and adding 1 on stores).