binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Better Support For Allocation Routines

Open xusheng6 opened this issue 3 years ago • 1 comments

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

xusheng6 avatar Jul 19 '22 04:07 xusheng6

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();
   ...
}

plafosse avatar Aug 01 '22 17:08 plafosse