Vector35 / Vector35/binaryninja-api
Improve Use-Case for Patching Relocations with MemoryMap
Open
@bpotchik is already working on this.
Since Sep 10, 2024.
Component: Relocations
Effort: Medium
Impact: Medium
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 298
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 19
Description
Additional work required from original issue: #4950 While we have the ability to patch bytes in regions with relocations using the new MemoryMap, the current implementation is somewhat raw and can be improved for better usability and control. Here’s an example demonstrating the existing behavior:
>>> relo = bv.relocation_ranges[0]
>>> relo_size = relo[1] - relo[0]
>>> relo_size
4
>>> bv.read(relo[0], relo_size)
b'H\x10\x01\x00'
>>> bv.write(relo[0], b'\xff' * 4)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Binary Ninja.app/Contents/MacOS/plugins/../../Resources/python/binaryninja/binaryview.py", line 4232, in write
raise RelocationWriteException("Attempting to write to a location which has a relocation")
binaryninja.exceptions.RelocationWriteException: Attempting to write to a location which has a relocation
# Note we do not define any permissions, the region will inherit the permissions from the existing shadowed region.
>>> bv.memory_map.add_memory_region("my_writable_relo", relo[0], b'\xff' * 4)
True
>>> bv.read(relo[0], relo_size)
b'\xff\xff\xff\xff'
>>> bv.write(relo[0], b'\xda' * 4)
4
>>> bv.read(relo[0], relo_size)
b'\xda\xda\xda\xda'
While this works, currently adding a memory region ends up modifying the segment map:
r-x 0x00008000-0x00008528
rw- 0x00010f0c-0x0001100c
rw- 0x0001100c-0x00011010 <<<< 4 byte segment for the relocation
Need to investigate the following:
- Implement a method to prevent segment bloat when patching relocations. Perhaps adding a hidden MemoryMap layer that handles patches and relocations separately from the main memory regions.
- Explore ways to automate the relocation patching process in the UI
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.
Assessment
This issue has not been assessed yet.