Skip to content

Commit

Permalink
Add OverlayReduxSymbols ghidra script
Browse files Browse the repository at this point in the history
  • Loading branch information
acemon33 committed Nov 15, 2024
1 parent 98cb098 commit d04076c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tools/ghidra_scripts/OverlayReduxSymbols.java
Original file line number Diff line number Diff line change
@@ -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<String> choices = new ArrayList();
for (int i = 0; i < MemoryBlockList.length; i++) { if (MemoryBlockList[i].isOverlay()) choices.add(MemoryBlockList[i].getName()); }
List<String> filterList = askChoices("Title", "Message", choices);
List<String> choiceList = new ArrayList();
for (String e : choices) { choiceList.add(e + "::"); choiceList.add(e + "__"); }

List<String> symbols = new ArrayList<String>();
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());
}

Check warning on line 54 in tools/ghidra_scripts/OverlayReduxSymbols.java

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

run has a cyclomatic complexity of 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 54 in tools/ghidra_scripts/OverlayReduxSymbols.java

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

run has 3 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 54 in tools/ghidra_scripts/OverlayReduxSymbols.java

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Deep, Nested Complexity

run has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
}

0 comments on commit d04076c

Please sign in to comment.