Skip to content

Instantly share code, notes, and snippets.

@Informatic
Last active November 13, 2022 17:35

Revisions

  1. Informatic revised this gist Nov 13, 2022. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions AutoMatchExternals.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,15 @@
    # Looks for matching libraries in current project and automatically assigns to current program
    # Looks for matching libraries in current project and automatically assigns to current program.
    # "Link existing project libraries" doesn't seem to fully work when using bulk import, and this
    # pretty much reimplements this.
    #
    # After running this script you will probably want to use FixupELFExternalSymbolsScript.java too.
    #
    #@author infowski
    #@category Symbol
    #@keybinding F11
    #@menupath
    #@toolbar


    #TODO Add User Code Here

    projdata = ghidra.framework.main.AppInfo().getActiveProject().getProjectData()

    def findLibrary(name, base=None):
  2. Informatic created this gist Nov 12, 2022.
    40 changes: 40 additions & 0 deletions AutoMatchExternals.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Looks for matching libraries in current project and automatically assigns to current program
    #@author infowski
    #@category Symbol
    #@keybinding F11
    #@menupath
    #@toolbar


    #TODO Add User Code Here

    projdata = ghidra.framework.main.AppInfo().getActiveProject().getProjectData()

    def findLibrary(name, base=None):
    if base is None:
    base = projdata.getRootFolder()

    for f in base.getFiles():
    if f.getName().startswith(name):
    return f

    for f in base.getFolders():
    tgt = findLibrary(name, f)
    if tgt:
    return tgt

    return None


    exm = getState().currentProgram.getExternalManager()

    for lib in exm.getExternalLibraryNames():
    if lib == '<EXTERNAL>': continue

    #print(lib, '->', exm.getExternalLibraryPath(lib))
    path = exm.getExternalLibraryPath(lib)
    if path is None:
    found = findLibrary(lib)
    if found:
    print('Setting %s to %s' % (lib, found.getPathname()))
    exm.setExternalPath(lib, found.getPathname(), True)