Vector35 / binaryninja-api

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

ARM64: unable to assemble bl instruction #6042

Closed 1337-42 closed 1 month ago

1337-42 commented 1 month ago

Version and Platform (required):

Bug Description: Binary Ninja is unable to reassemble its assembly output.

Steps To Reproduce:

>>> bv.get_disassembly(current_address, bv.arch)
'bl      0x1000700a0'
>>> disasm = bv.get_disassembly(current_address, bv.arch)
>>> print(disasm)
bl      0x1000700a0
>>> bv.arch.assemble(disasm, current_address)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Applications/Binary Ninja.app/Contents/MacOS/plugins/../../Resources/python/binaryninja/architecture.py", line 2510, in assemble
    raise ValueError(f"Could not assemble: {error_str}")
ValueError: Could not assemble: b'line 37: expected label or encodable integer pc offset\n'

Expected Behavior: The output should be the assembled bytes.

Screenshots:

image

Additional Information: Other instructions seem to assemble just fine. It's only when offsets are used in, for example, branch instructions.

xusheng6 commented 1 month ago

I am pretty sure this a known issue and we have a duplicate issue for it. Just cannot find it at the moment. Is it https://github.com/Vector35/binaryninja-api/issues/71?

1337-42 commented 1 month ago

Not sure what has changed since 2015. It could be related to that issue.

plafosse commented 1 month ago

Closing this as a duplicate of #71 Back in 2015 this was very difficult because llvm didn't support the nasm-style .org directive. Modern llvm probably supports this now and we might be able to do this without much difficulty.

plafosse commented 1 month ago

A work around is that you need to subtract your current offset from the offset provided to the assembler