import ghidra.app.script.GhidraScript; import ghidra.app.decompiler.DecompInterface; import ghidra.app.decompiler.DecompileResults; import ghidra.program.model.listing.Function; import ghidra.program.model.listing.FunctionManager; import ghidra.program.model.address.Address; import java.io.PrintWriter; import java.io.FileWriter; import java.util.LinkedHashMap; import java.util.Map; public class DumpDsp extends GhidraScript { @Override public void run() throws Exception { Map vts = new LinkedHashMap(); vts.put("SpectralProcessor", new long[]{0x1824abb90L, 64}); vts.put("Soothe2ModuleBase", new long[]{0x1824ac7a8L, 64}); vts.put("CloudyAudioProcessor", new long[]{0x1824ab7c0L, 64}); vts.put("AudioProcessingModule", new long[]{0x1824ac638L, 64}); vts.put("IIRFilterExtended", new long[]{0x1824ac5d8L, 64}); vts.put("Soothe2FilterGraph", new long[]{0x1824be810L, 64}); vts.put("FilterGraph_6_0x400", new long[]{0x1824be228L, 64}); vts.put("FilterGraphGrid", new long[]{0x1824be0a8L, 64}); DecompInterface di = new DecompInterface(); di.openProgram(currentProgram); FunctionManager fm = currentProgram.getFunctionManager(); PrintWriter pw = new PrintWriter(new java.io.BufferedWriter(new FileWriter("/home/m/re-tools/decomp_dsp.txt", false))); for (Map.Entry e : vts.entrySet()) { long base = e.getValue()[0]; int n = (int) e.getValue()[1]; pw.println("############ VTABLE " + e.getKey() + " 0x" + Long.toHexString(base)); pw.println("SLOTLIST:"); for (int i = 0; i < n; i++) { Address va = currentProgram.getAddressFactory().getDefaultAddressSpace(). getAddress(base + i * 8L); long tgt = (long) currentProgram.getMemory().getLong(va); if (tgt < 0x180000000L || tgt > 0x182a00000L) continue; Address a = currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(tgt); Function f = fm.getFunctionAt(a); long sz = (f == null) ? 0 : f.getBody().getNumAddresses(); pw.println(" [" + i + "] 0x" + Long.toHexString(tgt) + " size=" + sz); } pw.println("CCODE:"); for (int i = 0; i < n; i++) { Address va = currentProgram.getAddressFactory().getDefaultAddressSpace(). getAddress(base + i * 8L); long tgt = (long) currentProgram.getMemory().getLong(va); if (tgt < 0x180000000L || tgt > 0x182a00000L) continue; Address a = currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(tgt); Function f = fm.getFunctionAt(a); if (f == null) continue; long sz = f.getBody().getNumAddresses(); if (sz < 60) continue; DecompileResults res = di.decompileFunction(f, 90, monitor); if (res != null && res.getDecompiledFunction() != null) { pw.println(" --- [" + i + "] 0x" + Long.toHexString(tgt) + " size=" + sz + " ---"); pw.println(res.getDecompiledFunction().getC()); } } } pw.close(); di.dispose(); println("DSP_DONE"); } }