mirror of
https://codeberg.org/KeybadeBlox/JSRF-Decompilation.git
synced 2026-02-20 02:07:02 +03:00
86 lines
2.4 KiB
Java
86 lines
2.4 KiB
Java
// Writes user-defined data and function symbols to a specified TSV file for
|
|
// re-import by the EnhancedImport script.
|
|
//
|
|
// @category Export
|
|
|
|
import ghidra.app.script.GhidraScript;
|
|
import ghidra.program.model.address.Address;
|
|
import ghidra.program.model.data.DataType;
|
|
import ghidra.program.model.listing.Data;
|
|
import ghidra.program.model.listing.Function;
|
|
import ghidra.program.model.symbol.SourceType;
|
|
import ghidra.program.model.symbol.Symbol;
|
|
|
|
import java.io.FileWriter;
|
|
import java.util.Arrays;
|
|
import java.util.Optional;
|
|
|
|
|
|
public class EnhancedExport extends GhidraScript{
|
|
@Override
|
|
public void run() throws Exception {
|
|
final FileWriter out = new FileWriter(askFile("Specify output file", "OK"));
|
|
|
|
for (final Symbol s : currentProgram.getSymbolTable()
|
|
.getPrimarySymbolIterator(true)) {
|
|
if (s.getSource() != SourceType.USER_DEFINED) continue;
|
|
|
|
final Object obj = s.getObject();
|
|
if (obj != null) switch (obj) {
|
|
case Data d:
|
|
outputData(s.getAddress(), d.getDataType(), s.getName(true), out);
|
|
break;
|
|
|
|
case Function f:
|
|
outputFunc(s.getAddress(), f, out);
|
|
break;
|
|
|
|
default: {}
|
|
}
|
|
}
|
|
|
|
out.close();
|
|
}
|
|
|
|
private static void outputData(
|
|
final Address addr,
|
|
final DataType type,
|
|
final String name,
|
|
final FileWriter out
|
|
) throws Exception {
|
|
out.write(
|
|
"0x" + addr.toString() + "\t" +
|
|
"data" + "\t" +
|
|
type.getDisplayName() + "\t" +
|
|
name + "\n"
|
|
);
|
|
}
|
|
|
|
private static void outputFunc(
|
|
final Address addr,
|
|
final Function f,
|
|
final FileWriter out
|
|
) throws Exception {
|
|
out.write(
|
|
"0x" + addr.toString() + "\t" +
|
|
"func" + "\t" +
|
|
f.getSignature(true).getReturnType()
|
|
.getDisplayName() + "\t" +
|
|
f.getCallingConventionName() + "\t" +
|
|
(f.isInline() ? "inline" : "notinline") + "\t" +
|
|
Optional.ofNullable(f.getCallFixup())
|
|
.orElse("nofixup") + "\t" +
|
|
f.getName(true) + "\t" +
|
|
String.join(
|
|
"\t",
|
|
Arrays.stream(f.getSignature(true)
|
|
.getArguments())
|
|
.map(arg ->
|
|
arg.getDataType().getDisplayName() + "\t" +
|
|
arg.getName()
|
|
).toArray(String[]::new)
|
|
) +
|
|
(f.hasVarArgs() ? "\t..." : "") + "\n"
|
|
);
|
|
}
|
|
}
|