Created
July 6, 2020 15:21
-
-
Save 8051Enthusiast/8c0d940c24afddee07613e4f6d31196a to your computer and use it in GitHub Desktop.
Ghidra script to import functions found by at51's libfind into ghidra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports the functions found by at51 into the program | |
import json | |
import subprocess | |
import sys.exit as exit | |
state = getState() | |
currentProgram = state.getCurrentProgram() | |
filepath = currentProgram.getExecutablePath() | |
# note: this won't work properly if the file is loaded at an offset | |
proc = subprocess.Popen(["at51", "libfind", "-j", filepath], | |
stdout = subprocess.PIPE, stderr = subprocess.PIPE) | |
(at51ret,err) = proc.communicate() | |
if proc.returncode != 0: | |
print("Error executing at51: {}".format(err)) | |
exit(1) | |
funcdefs = json.loads(at51ret) | |
for func in funcdefs: | |
addr = currentProgram.getAddressFactory().getAddressSpace("CODE").getAddress(func['location']) | |
createLabel(addr, func['name'], False, ghidra.program.model.symbol.SourceType.ANALYSIS) | |
createFunction(addr, func['name']) | |
if func['description']: | |
setPreComment(addr, func['description']) | |
disassemble(addr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment