From d04076cf6bd30ef4d56336225dcf150dae447d23 Mon Sep 17 00:00:00 2001 From: acemno33 Date: Fri, 15 Nov 2024 19:31:16 +0300 Subject: [PATCH] Add OverlayReduxSymbols ghidra script --- tools/ghidra_scripts/OverlayReduxSymbols.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tools/ghidra_scripts/OverlayReduxSymbols.java diff --git a/tools/ghidra_scripts/OverlayReduxSymbols.java b/tools/ghidra_scripts/OverlayReduxSymbols.java new file mode 100644 index 000000000..b6958e959 --- /dev/null +++ b/tools/ghidra_scripts/OverlayReduxSymbols.java @@ -0,0 +1,55 @@ +// Exports symbols to PCSX-Redux's symbols map including Overlays filtering +//@author acemon33 +//@category PSX + +import ghidra.app.script.GhidraScript; +import ghidra.program.model.symbol.*; +import ghidra.program.model.address.*; +import ghidra.program.model.mem.*; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.*; + +public class OverlayReduxSymbols extends GhidraScript { + + public void run() throws Exception { + MemoryBlock[] MemoryBlockList = state.getCurrentProgram().getMemory().getBlocks(); + List choices = new ArrayList(); + for (int i = 0; i < MemoryBlockList.length; i++) { if (MemoryBlockList[i].isOverlay()) choices.add(MemoryBlockList[i].getName()); } + List filterList = askChoices("Title", "Message", choices); + List choiceList = new ArrayList(); + for (String e : choices) { choiceList.add(e + "::"); choiceList.add(e + "__"); } + + List symbols = new ArrayList(); + SymbolTable st = state.getCurrentProgram().getSymbolTable(); + SymbolIterator iter = st.getSymbolIterator(true); + while (iter.hasNext() && !monitor.isCancelled()) { + Symbol sym = iter.next(); + Address add = sym.getAddress(); + String name = sym.getName(true); + + boolean hasFilter = true; + for (String s : filterList) { if (add.toString().contains(s)) { hasFilter = false; break; } } + if (hasFilter) + { + boolean isNext = false; + for (String s : choiceList) { if (add.toString().contains(s)) { isNext = true; break; } } + if (isNext) continue; + } + + symbols.add(String.format("%08x %s", add.getOffset(), name)); + } + + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://localhost:8080/api/v1/assembly/symbols?function=upload")) + .POST(HttpRequest.BodyPublishers.ofString(String.join("\n", symbols))) + .build(); + + client.send(request, HttpResponse.BodyHandlers.ofString()); + + println("size: " + symbols.size()); + } +}