386
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Limited support for importing a ROM map from Ghidra. '''TODO:''' We need the ability to merge the wikitext output into an already existing page. | Limited support for importing a ROM map from Ghidra. '''TODO:''' We need the ability to merge the wikitext output into an already existing page. | ||
Running this script will export all named functions in the current program to a wikitext file: | Running this script will export all named functions in the current program to a wikitext file. It will skip functions that already exist in this Wiki (by matching the address): | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="java" lines> | ||
/* ### | /* ### | ||
* IP: GHIDRA | * IP: GHIDRA | ||
Line 27: | Line 27: | ||
//@category Functions | //@category Functions | ||
import java.io.BufferedReader; | |||
import java.io.File; | import java.io.File; | ||
import java.io.FileWriter; | import java.io.FileWriter; | ||
import java.io.InputStreamReader; | |||
import java.net.HttpURLConnection; | |||
import java.net.URL; | |||
import java.util.HashSet; | |||
import ghidra.app.script.GhidraScript; | import ghidra.app.script.GhidraScript; | ||
Line 39: | Line 44: | ||
private static final String ENTRY = "entry"; | private static final String ENTRY = "entry"; | ||
private static final String SIGNATURE = "signature"; | private static final String SIGNATURE = "signature"; | ||
private HashSet<Long> knownAddresses; | |||
@Override | @Override | ||
public void run() throws Exception { | public void run() throws Exception { | ||
byte[] gameCodeBytes = new byte[4]; | |||
currentProgram.getMemory().getBytes(currentProgram.getAddressFactory().getAddress("0x080000ac"), gameCodeBytes); | |||
String gameCode = new String(gameCodeBytes, "US-ASCII"); | |||
println("Game code: " + gameCode); | |||
knownAddresses = new HashSet(); | |||
if (gameCode.equals("U3IE")) { | |||
loadKnownAddresses("https://boktaihacking.net/wiki/ROM_map_(Boktai_1)?action=raw"); | |||
} else if (gameCode.equals("U32E")) { | |||
loadKnownAddresses("https://boktaihacking.net/wiki/ROM_map_(Boktai_2)?action=raw"); | |||
} else if (gameCode.equals("U33J")) { | |||
loadKnownAddresses("https://boktaihacking.net/wiki/ROM_map_(Boktai_3)?action=raw"); | |||
} | |||
File outputFile = askFile("Please Select Output File", "Choose"); | File outputFile = askFile("Please Select Output File", "Choose"); | ||
FileWriter fileWriter = new FileWriter(outputFile); | FileWriter fileWriter = new FileWriter(outputFile); | ||
Line 56: | Line 77: | ||
Address entry = f.getEntryPoint(); | Address entry = f.getEntryPoint(); | ||
FunctionSignature sig = f.getSignature(); | FunctionSignature sig = f.getSignature(); | ||
if (knownAddresses.contains(entry.getOffset())) continue; | |||
fileWriter.write("|-\n"); | fileWriter.write("|-\n"); | ||
Line 67: | Line 90: | ||
fileWriter.close(); | fileWriter.close(); | ||
println("Wrote functions to " + outputFile); | println("Wrote functions to " + outputFile); | ||
} | |||
private void loadKnownAddresses(String url) throws Exception { | |||
println("Downloading known addresses from " + url); | |||
HttpURLConnection http = (HttpURLConnection) new URL(url).openConnection(); | |||
http.setRequestMethod("GET"); | |||
BufferedReader httpStream = new BufferedReader(new InputStreamReader(http.getInputStream())); | |||
String line; | |||
while ((line = httpStream.readLine()) != null) { | |||
if (line.startsWith("| 0x")) { | |||
long address = Integer.parseInt(line.substring(4, 12), 16); | |||
knownAddresses.add(address); | |||
} | |||
} | |||
println("Found " + knownAddresses.size() + " addresses in the Wiki"); | |||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |