Skip to content

Commit bd7d2c5

Browse files
committed
Refactor: ghidra_script OverlayReduxSymbols Extract methods
1 parent c30393d commit bd7d2c5

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed
Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Exports symbols to PCSX-Redux's symbols map including Overlays filtering
2+
//@author Nicolas "Pixel" Noble
23
//@author acemon33
3-
//@category PSX
44

55
import ghidra.app.script.GhidraScript;
66
import ghidra.program.model.symbol.*;
@@ -12,15 +12,12 @@
1212
import java.net.http.HttpResponse;
1313
import java.util.*;
1414

15-
public class OverlayReduxSymbols extends GhidraScript {
15+
public class PsxOverlayReduxSymbols extends GhidraScript {
1616

1717
public void run() throws Exception {
18-
MemoryBlock[] MemoryBlockList = state.getCurrentProgram().getMemory().getBlocks();
19-
List<String> choices = new ArrayList();
20-
for (int i = 0; i < MemoryBlockList.length; i++) { if (MemoryBlockList[i].isOverlay()) choices.add(MemoryBlockList[i].getName()); }
21-
List<String> filterList = askChoices("Title", "Message", choices);
22-
List<String> choiceList = new ArrayList();
23-
for (String e : choices) { choiceList.add(e + "::"); choiceList.add(e + "__"); }
18+
List<String> options = this.getMemoryBlockOptions();
19+
List<String> filterList = askChoices("Title", "Message", options);
20+
List<String> choiceList = this.getOptionList(options);
2421

2522
List<String> symbols = new ArrayList<String>();
2623
SymbolTable st = state.getCurrentProgram().getSymbolTable();
@@ -31,15 +28,28 @@ public void run() throws Exception {
3128
String name = sym.getName(true);
3229

3330
boolean hasFilter = true;
34-
for (String s : filterList) { if (add.toString().contains(s)) { hasFilter = false; break; } }
31+
for (String s : filterList) {
32+
if (add.toString().contains(s)) {
33+
hasFilter = false;
34+
break;
35+
}
36+
}
3537
if (hasFilter)
3638
{
3739
boolean isNext = false;
38-
for (String s : choiceList) { if (add.toString().contains(s)) { isNext = true; break; } }
39-
if (isNext) continue;
40+
for (String s : choiceList) {
41+
if (add.toString().contains(s)) {
42+
isNext = true;
43+
break;
44+
}
45+
}
46+
if (isNext)
47+
continue;
4048
}
4149

4250
symbols.add(String.format("%08x %s", add.getOffset(), name));
51+
// symbols.add(String.format("%s %s", add, name));
52+
// println(String.format("%s %s", add, name));
4353
}
4454

4555
HttpClient client = HttpClient.newHttpClient();
@@ -50,6 +60,26 @@ public void run() throws Exception {
5060

5161
client.send(request, HttpResponse.BodyHandlers.ofString());
5262

63+
// for (String address : symbols) println(address);
5364
println("size: " + symbols.size());
5465
}
66+
67+
private List<String> getMemoryBlockOptions() {
68+
MemoryBlock[] MemoryBlockList = state.getCurrentProgram().getMemory().getBlocks();
69+
List<String> options = new ArrayList();
70+
for (int i = 0; i < MemoryBlockList.length; i++) {
71+
if (MemoryBlockList[i].isOverlay())
72+
options.add(MemoryBlockList[i].getName());
73+
}
74+
return options;
75+
}
76+
77+
private List<String> getOptionList(List<String> options) {
78+
List<String> resultList = new ArrayList();
79+
for (String e : options) {
80+
resultList.add(e + "::");
81+
resultList.add(e + "__");
82+
}
83+
return resultList;
84+
}
5585
}

0 commit comments

Comments
 (0)