Vector35 / binaryninja-api

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

BN does not propogate enum type from array member to constant values #4813

Open reversing-dev opened 7 months ago

reversing-dev commented 7 months ago

Version and Platform (required):

Bug Description:

Initial analysis: image

After fixing the array size, the initial enum name is lost: image

Expected output: (I had to map each enum val to name manually) image

Also, if it's possible to default select the last used enum in the Select Enum dialogue box it will be useful in similar scenarios.

xusheng6 commented 7 months ago

Related to: https://github.com/Vector35/binaryninja-api/issues/4431

xusheng6 commented 1 month ago

I have created a simpler binary to reproduce this:

test_enum_arrary.zip

Screenshot 2024-06-06 at 1 01 46 PM

Looking at the expression type, it seems that we correctly deduce the type of arr[0] is the enum, we just fail to propagate that to the right side of the comparison

xusheng6 commented 1 month ago

If I look at the MLIL, if explains:

>>> current_il_instruction
<MediumLevelILSetVarField: arr[0] = 1>
>>> current_il_instruction.dest
<var enum foobar arr[0x3]>
>>> current_il_instruction.dest.type
<type: immutable:ArrayTypeClass 'enum foobar[0x3]'>