Skip to content

Instantly share code, notes, and snippets.

@roblabla
Created March 29, 2020 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roblabla/471da6c3685c3132e1bdc02065e22b6e to your computer and use it in GitHub Desktop.
Save roblabla/471da6c3685c3132e1bdc02065e22b6e to your computer and use it in GitHub Desktop.
#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