binaryninja-api
binaryninja-api copied to clipboard
Better Support For Allocation Routines
Currently, BN understands certain allocation routine (e.g., malloc, VirtualAlloc) and can deal with its return value properly when the user creates s (https://docs.binary.ninja/guide/type.html#smart-structures-workflow). However, this is currently done purely from the UI. The notion of an allocation routine and the BN's handling is also very little known. We should probably:
- Mention what is an allocation routine and how BN handles it in the docs
- Move the code dealing with allocation routine into the core
- Allow the user to mark a function as an allocation routine, alogn with the size of the allocation
- Add support for more allocation routines, e.g., mmap
In particular we need an API for being able to specify custom allocation routines in the Platform. Something like this below:
optional<size_t> Platform::GetSizeForKnownAllocationRoutine(MLIL mlilCall)
{
if (mlilCall.name == "malloc" && mlilCall.Parameter[0].IsConstant())
return mlilCall.Parameter[0].value()
else if (mlisCall.name == "calloc" && mlilCall.Parameter[0].IsConstant() && mlilCall.Parameter[1].IsConstant())
return mlilCall.Parameter[0].value() * mlilCall.Parameter[1].value();
...
}