Vector35 / binaryninja-api

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

Implement Slicing on TypedDataAccessor for ArrayType DataVars #5501

Open w1282 opened 4 months ago

w1282 commented 4 months ago

What is the feature you'd like to have? It would be nice if ArrayType datavars could be extended to allow for slicing arrays of structures, without having to reference the .value attribute.

Is your feature request related to a problem? This behavior is unexpected, as iterating over the datavar directly works as expected but slicing does not.

Additional Information:

my_array = bv.get_data_var_at(here)
for elem in my_array:
    print(elem)

Works as expected (handled by TypedDataAccessor.__iter__)

my_array = bv.get_data_var_at(here)
for elem in my_array[::-1]:
    print(elem)

Does not work as expected (handled by TypedDataAccessor.__getitem__)

xusheng6 commented 3 months ago

The problem is we are only considering an int, and not a slice when we handle the case of an array: https://github.com/Vector35/binaryninja-api/blob/4152126289652104982292308858511197568097/python/binaryview.py#L10598-L10601