Commit b37eb16f by Enkelmann

replaced Ghidra address computation workaround by correct API function

parent 9a57a3cc
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# - Open the binary in Ghidra and run this file as a script. Select the generated json file when prompted. # - Open the binary in Ghidra and run this file as a script. Select the generated json file when prompted.
import json import json
from ghidra.app.util.opinion import ElfLoader
def bookmark_cwe(ghidra_address, text): def bookmark_cwe(ghidra_address, text):
...@@ -45,12 +46,16 @@ def compute_ghidra_address(address_string): ...@@ -45,12 +46,16 @@ def compute_ghidra_address(address_string):
fixed_address_string = address_string.replace(':32u', '').replace(':64u', '') fixed_address_string = address_string.replace(':32u', '').replace(':64u', '')
address_int = int(fixed_address_string, 16) address_int = int(fixed_address_string, 16)
# Ghidra sometimes adds an offset to all addresses. # Ghidra sometimes adds an offset to all addresses.
# Unfortunately, I havent't found a way to reliably detect this yet. try:
# Instead we detect the obvious case and hope that it works in most cases. # try for ELF-files
if address_int < currentProgram.getMinAddress().getOffset(): offset = currentProgram.getMinAddress().getOffset() - int(ElfLoader.getElfOriginalImageBase(currentProgram))
return currentProgram.getMinAddress().add(address_int) return currentProgram.getAddressFactory().getAddress(fixed_address_string).add(offset)
else: except:
return currentProgram.getAddressFactory().getAddress(fixed_address_string) # the file is probably not an ELF file, so we use a workaround that should work in most cases.
if address_int < currentProgram.getMinAddress().getOffset():
return currentProgram.getMinAddress().add(address_int)
else:
return currentProgram.getAddressFactory().getAddress(fixed_address_string)
def main(): def main():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment