Vector35 / binaryninja-api

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

Support specifying a stack location as an argument and return value in calling convention #3340

Open fuzyll opened 2 years ago

fuzyll commented 2 years ago

What is the feature you'd like to have? You can specify a register as the location for an argument in binary ninja by doing something like int32_t arg1@rax (to specify that arg1 is in rax). You cannot specify a stack location, which is problematic for certain compilers and/or languages (like Go).

Is your feature request related to a problem? See above. We would have much better support for languages like Go that tend to do this a fair amount, even if doing this were a manual process instead of an automated one.

Additional Information: There are many ways this could be implemented. In my head, it would be simple enough to just extend the @ syntax to allow for something like int32_t arg1@rsp+4 (e.g. register + offset instead of just register) when setting the type for the return value or an argument. Ideally we would also update our analysis to be able to identify these things automatically, but being able to manually fix things up is an important first step.

It should be noted that I don't think you can specify the return location in a specific register through the y button (the "Change Type" menu) at all right now, either, which maybe means this should be split into two issues? I believe you need to do it through the Edit Function Properties window instead. I've campaigned for merging these together on a few occasions, so consider this another suggestion to consider doing so. 🙂

fuzyll commented 2 years ago

Half of this is probably covered by #2032.

fuzyll commented 2 years ago

Issue #1003 is also probably related.

plafosse commented 3 months ago

also https://github.com/Vector35/binaryninja-api/issues/3875

plafosse commented 3 months ago

I'm closing all the other issues in favor of this one. I modified this to mention that we also need to be able to specify the location of return value on the stack

plafosse commented 3 months ago

Another addendum: https://github.com/Vector35/binaryninja-api/issues/2793 Calling conventions should allow specification of partial registers.

plafosse commented 3 months ago

Another addendum: https://github.com/Vector35/binaryninja-api/issues/2801 Support for indirect return result locations

CouleeApps commented 2 months ago

As of >=4.2.5919-dev, the syntax support for stack locations was added, but only syntax support and not analysis support. Spelling a function as int foo(int bar @ 8) will now return a FunctionType object which has the bar parameter with a non-default location of StackVariableSourceType with storage 0x8.

Again, this is only syntax spelling support, not analysis support.