import ghidra.app.script.GhidraScript; import ghidra.program.model.symbol.Reference; import ghidra.program.model.symbol.ReferenceIterator; import ghidra.program.model.address.Address; import ghidra.program.model.address.AddressSpace; import ghidra.program.model.listing.Function; import ghidra.program.model.listing.FunctionManager; import java.io.PrintWriter; public class XrefDsp extends GhidraScript { @Override public void run() throws Exception { String[] targets = {"1805631c0","180563260","180563a60","180563fa0","180563ce0","180563440", "18056e3e0","180529fe0","180509900","180564a00","180537410","1805374e0", "18052e3e0","18052e9b0"}; AddressSpace as = currentProgram.getAddressFactory().getDefaultAddressSpace(); PrintWriter pw = new PrintWriter(new java.io.BufferedWriter( new java.io.FileWriter("/home/m/re-tools/xrefs2.txt"))); FunctionManager fm = currentProgram.getFunctionManager(); for (String ts : targets) { long ta = Long.parseLong(ts,16); Address t = as.getAddress(ta); pw.println("### TARGET " + ts); ReferenceIterator it = currentProgram.getReferenceManager().getReferencesTo(t); int n=0; while (it.hasNext() && n<200) { Reference r = it.next(); Function cf = null; if (r.getFromAddress()!=null) cf = fm.getFunctionContaining(r.getFromAddress()); pw.println(" from " + r.getFromAddress() + " type=" + r.getReferenceType() + " in=" + (cf!=null?Long.toHexString(cf.getEntryPoint().getOffset()):"?")); n++; } } pw.close(); println("XREFS2_DONE"); } }