// Applies db/names.tsv (address, Qualified::Name, note) as forced renames with a "DB: note" comment. Arg: names.tsv import ghidra.app.script.GhidraScript; import ghidra.program.model.address.*; import ghidra.program.model.listing.*; import ghidra.program.model.symbol.*; import java.nio.file.*; public class ApplyDb extends GhidraScript { public void run() throws Exception { SymbolTable st = currentProgram.getSymbolTable(); int n = 0; for (String line : Files.readAllLines(Paths.get(getScriptArgs()[0]))) { if (line.isBlank() || line.startsWith("#")) continue; String[] c = line.split("\t", 3); Address a = toAddr(c[0]); Function fn = getFunctionAt(a); if (fn == null) { disassemble(a); fn = createFunction(a, null); } if (fn == null) { println("ApplyDb: no function at " + c[0]); continue; } String[] parts = c[1].split("::"); Namespace ns = currentProgram.getGlobalNamespace(); for (int k = 0; k < parts.length - 1; k++) { Namespace n2 = st.getNamespace(parts[k], ns); ns = n2 != null ? n2 : st.createNameSpace(ns, parts[k], SourceType.USER_DEFINED); } fn.setParentNamespace(ns); fn.setName(parts[parts.length - 1], SourceType.USER_DEFINED); fn.setComment("DB: " + (c.length > 2 ? c[2] : "")); n++; } println("ApplyDb: " + n + " names"); } }