Created
March 29, 2020 14:40
-
-
Save roblabla/471da6c3685c3132e1bdc02065e22b6e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#Uses at51's libfind command to find C51 functions | |
#@author roblabla | |
#@category 8051 | |
#@keybinding | |
#@menupath | |
#@toolbar | |
import subprocess | |
import json | |
from ghidra.program.model.symbol import SourceType | |
file_location = currentProgram.getDomainFile().getMetadata()["Executable Location"] | |
dir = askDirectory("C51 libraries directory", "Choose Directory").getAbsolutePath() | |
at51 = subprocess.Popen(["at51", "libfind", "--json", file_location, dir], stdout=subprocess.PIPE) | |
json_data, _ = at51.communicate() | |
data = json.loads(json_data) | |
CLIBL_NAMESPACE = getNamespace(None, "clibl") | |
if CLIBL_NAMESPACE is None: | |
CLIBL_NAMESPACE = currentProgram.getSymbolTable().createNameSpace(None, "clibl", SourceType.USER_DEFINED) | |
for elem in data: | |
fun = getFunctionAt(toAddr(elem['location'])) | |
if fun is not None: | |
fun.setName(elem['name'], SourceType.USER_DEFINED) | |
else: | |
fun = createFunction(toAddr(elem['location']), elem['name']) | |
fun.setParentNamespace(CLIBL_NAMESPACE) | |
if elem['description'] is not None: | |
setPlateComment(toAddr(elem['location']), elem['description']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment