mirror of
https://codeberg.org/KeybadeBlox/JSRF-Decompilation.git
synced 2026-02-20 02:07:02 +03:00
Complete Ghidra symbol import script
This commit is contained in:
parent
92179ea9bd
commit
fd6815ae42
3 changed files with 1342 additions and 1263 deletions
|
|
@ -70,14 +70,14 @@ public class EnhancedExport extends GhidraScript{
|
||||||
(f.isInline() ? "inline" : "notinline") + "\t" +
|
(f.isInline() ? "inline" : "notinline") + "\t" +
|
||||||
Optional.ofNullable(f.getCallFixup())
|
Optional.ofNullable(f.getCallFixup())
|
||||||
.orElse("nofixup") + "\t" +
|
.orElse("nofixup") + "\t" +
|
||||||
f.getName(true) +
|
f.getName(true) + "\t" +
|
||||||
String.join(
|
String.join(
|
||||||
"\t",
|
"\t",
|
||||||
Arrays.stream(f.getSignature(true)
|
Arrays.stream(f.getSignature(true)
|
||||||
.getArguments())
|
.getArguments())
|
||||||
.map(arg ->
|
.map(arg ->
|
||||||
"\t" + arg.getDataType().getDisplayName() +
|
arg.getDataType().getDisplayName() + "\t" +
|
||||||
"\t" + arg.getName()
|
arg.getName()
|
||||||
).toArray(String[]::new)
|
).toArray(String[]::new)
|
||||||
) +
|
) +
|
||||||
(f.hasVarArgs() ? "\t..." : "") + "\n"
|
(f.hasVarArgs() ? "\t..." : "") + "\n"
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,12 @@ import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.data.ArrayDataType;
|
import ghidra.program.model.data.ArrayDataType;
|
||||||
import ghidra.program.model.data.DataType;
|
import ghidra.program.model.data.DataType;
|
||||||
import ghidra.program.model.data.PointerDataType;
|
import ghidra.program.model.data.PointerDataType;
|
||||||
|
import ghidra.program.model.data.Undefined4DataType;
|
||||||
import ghidra.program.model.listing.Data;
|
import ghidra.program.model.listing.Data;
|
||||||
import ghidra.program.model.listing.Function;
|
import ghidra.program.model.listing.Function;
|
||||||
|
import ghidra.program.model.listing.Function.FunctionUpdateType;
|
||||||
|
import ghidra.program.model.listing.Parameter;
|
||||||
|
import ghidra.program.model.listing.ParameterImpl;
|
||||||
import ghidra.program.model.symbol.Namespace;
|
import ghidra.program.model.symbol.Namespace;
|
||||||
import ghidra.program.model.symbol.SourceType;
|
import ghidra.program.model.symbol.SourceType;
|
||||||
import ghidra.program.model.symbol.Symbol;
|
import ghidra.program.model.symbol.Symbol;
|
||||||
|
|
@ -50,23 +54,26 @@ public class EnhancedImport extends GhidraScript{
|
||||||
final Address addr,
|
final Address addr,
|
||||||
final String[] parts
|
final String[] parts
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
final String name = unqualified(parts[3]);
|
|
||||||
|
|
||||||
print("Importing data symbol \"" + parts[3] + "\"...");
|
print("Importing data symbol \"" + parts[3] + "\"...");
|
||||||
|
|
||||||
// Create symbol
|
// Create symbol
|
||||||
final Namespace ns = importNamespace(parts[3]);
|
final Namespace ns = importNamespace(parts[3]);
|
||||||
final Symbol s = Optional.ofNullable(getSymbolAt(addr))
|
final Symbol s = Optional.ofNullable(getSymbolAt(addr))
|
||||||
.orElse(createLabel(addr, name, ns, true, SourceType.USER_DEFINED));
|
.orElse(createLabel(
|
||||||
|
addr,
|
||||||
|
unqualified(parts[3]),
|
||||||
|
ns,
|
||||||
|
true,
|
||||||
|
SourceType.USER_DEFINED
|
||||||
|
));
|
||||||
|
|
||||||
// Create data
|
// Create data
|
||||||
final Optional<DataType> t_maybe = makeType(parts[2]);
|
if (makeType(parts[2]).orElse(null) instanceof DataType t) {
|
||||||
if (t_maybe.orElse(null) instanceof DataType t) {
|
|
||||||
clearListing(addr, addr.add(Math.max(t.getLength(), 1) - 1));
|
clearListing(addr, addr.add(Math.max(t.getLength(), 1) - 1));
|
||||||
currentProgram.getListing().createData(addr, t);
|
currentProgram.getListing().createData(addr, t);
|
||||||
|
|
||||||
println(" done.");
|
println(" done.");
|
||||||
} else println(", skipping.");
|
} else println(" skipping.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String unqualified(final String qualifiedName) {
|
private static String unqualified(final String qualifiedName) {
|
||||||
|
|
@ -98,7 +105,7 @@ public class EnhancedImport extends GhidraScript{
|
||||||
.getService(DataTypeQueryService.class)
|
.getService(DataTypeQueryService.class)
|
||||||
.findDataTypes(baseName, null);
|
.findDataTypes(baseName, null);
|
||||||
if (foundTypes.size() == 0) {
|
if (foundTypes.size() == 0) {
|
||||||
print(" can't find data type \"" + baseName + "\"");
|
print(" can't find data type \"" + baseName + "\",");
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,6 +160,38 @@ public class EnhancedImport extends GhidraScript{
|
||||||
final Address addr,
|
final Address addr,
|
||||||
final String[] parts
|
final String[] parts
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
println("TODO: function \"" + parts[6] + "\"");
|
print("Importing function symbol \"" + parts[6] + "\"...");
|
||||||
|
|
||||||
|
final Function f = Optional.ofNullable(getFunctionAt(addr))
|
||||||
|
.orElse(createFunction(addr, parts[6]));
|
||||||
|
|
||||||
|
if (makeType(parts[2]).orElse(null) instanceof DataType t)
|
||||||
|
f.setReturnType(t, SourceType.USER_DEFINED);
|
||||||
|
f.setInline(parts[4].equals("inline"));
|
||||||
|
f.setCallFixup(parts[5].equals("nofixup") ? null : parts[5]);
|
||||||
|
f.setName(unqualified(parts[6]), SourceType.USER_DEFINED);
|
||||||
|
if (importNamespace(parts[6]) instanceof Namespace ns)
|
||||||
|
f.setParentNamespace(ns);
|
||||||
|
|
||||||
|
final ArrayList<Parameter> args = new ArrayList<>();
|
||||||
|
for (int i = 7; i < parts.length - 1; i += 2)
|
||||||
|
args.add(new ParameterImpl(
|
||||||
|
parts[i+1],
|
||||||
|
makeType(parts[i]).orElse(Undefined4DataType.dataType),
|
||||||
|
currentProgram
|
||||||
|
));
|
||||||
|
|
||||||
|
f.updateFunction(
|
||||||
|
parts[3],
|
||||||
|
null,
|
||||||
|
args,
|
||||||
|
FunctionUpdateType.DYNAMIC_STORAGE_FORMAL_PARAMS,
|
||||||
|
true,
|
||||||
|
SourceType.USER_DEFINED
|
||||||
|
);
|
||||||
|
|
||||||
|
f.setVarArgs(parts[parts.length - 1].equals("..."));
|
||||||
|
|
||||||
|
println(" done.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2544
ghidra/symboltable.tsv
Normal file → Executable file
2544
ghidra/symboltable.tsv
Normal file → Executable file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue