Convert to array indexing for accessing out-of-size struct members instead of `__offset()` hex values
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cpp
- Domain
- compilers, reverse-engineering
Research direction
Start by locating the existing array-indexing support and the rendering path that emits struct-member __offset() expressions. Verify signed division and remainder behavior for positive and negative offsets, and define done as equivalent array-indexed member expressions for cross-struct accesses while preserving existing behavior otherwise.
Written by the indexing model from the issue text.
Description
What is the feature you'd like to have?
I think there's a refinement it could make to the existing array indexing support. Currently Binary Ninja already supports array indexing notation, but when accessing struct members across boundaries, it still uses offset notation.
Is your feature request related to a problem?
This creates a readability issue when analyzing code that uses pointer arithmetic with negative offsets.
Current behavior:
If sizeof(struct) == 8 then:
ps_op_stack_ptr_2->__offset(0x8).b = tmp.type
ps_op_stack_ptr_2->__offset(0x9).b = tmp.perms
ps_op_stack_ptr_2->__offset(0xa).w = tmp.length
ps_op_stack_ptr_2->__offset(0xfffffffffffffff8).b = prev_tmp.type // negative offset
Proposed enhancement:
When the offset crosses struct boundaries, automatically convert to array indexing + member access:
ps_op_stack_ptr_2[1].type = tmp.type // was ->__offset(0x8).b
ps_op_stack_ptr_2[1].perms = tmp.perms // was ->__offset(0x9).b
ps_op_stack_ptr_2[1].length = tmp.length // was ->__offset(0xa).w
ps_op_stack_ptr_2[-1].type = tmp.prev_type // was ->__offset(0xfffffffffffffff8).b
Are any alternative solutions acceptable?
Expected Algorithm would be:
- Detect when
offset >= sizeof(struct) - Calculate array index:
array_index = (signed)offset / sizeof(struct) - Calculate member offset:
member_offset = offset % sizeof(struct) - Convert to:
ptr[array_index].memberinstead ofptr->__offset(hex_value).member
Additional Information:
Binary is: gentle forest glows calmly
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 298
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 19
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Vector35/binaryninja-api
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Vector35/binaryninja-api#8540 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Vector35/binaryninja-api#8516 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Vector35/binaryninja-api#8503 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Vector35/binaryninja-api#8446 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Vector35/binaryninja-api#8444 ·
All issues in Vector35/binaryninja-api
Similar issues
-
Website Doc Typo Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 92/100
autowarefoundation/autoware_universe#13413 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
automated-analysis bug memory-safety
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100