Last active
November 13, 2022 17:35
-
-
Save Informatic/b11e1e58489dd24ef5b7c74efa3ddf00 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
# 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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment