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
|
|
@ -8,8 +8,12 @@ import ghidra.program.model.address.Address;
|
|||
import ghidra.program.model.data.ArrayDataType;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.data.PointerDataType;
|
||||
import ghidra.program.model.data.Undefined4DataType;
|
||||
import ghidra.program.model.listing.Data;
|
||||
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.SourceType;
|
||||
import ghidra.program.model.symbol.Symbol;
|
||||
|
|
@ -50,23 +54,26 @@ public class EnhancedImport extends GhidraScript{
|
|||
final Address addr,
|
||||
final String[] parts
|
||||
) throws Exception {
|
||||
final String name = unqualified(parts[3]);
|
||||
|
||||
print("Importing data symbol \"" + parts[3] + "\"...");
|
||||
|
||||
// Create symbol
|
||||
final Namespace ns = importNamespace(parts[3]);
|
||||
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
|
||||
final Optional<DataType> t_maybe = makeType(parts[2]);
|
||||
if (t_maybe.orElse(null) instanceof DataType t) {
|
||||
if (makeType(parts[2]).orElse(null) instanceof DataType t) {
|
||||
clearListing(addr, addr.add(Math.max(t.getLength(), 1) - 1));
|
||||
currentProgram.getListing().createData(addr, t);
|
||||
|
||||
println(" done.");
|
||||
} else println(", skipping.");
|
||||
} else println(" skipping.");
|
||||
}
|
||||
|
||||
private static String unqualified(final String qualifiedName) {
|
||||
|
|
@ -98,7 +105,7 @@ public class EnhancedImport extends GhidraScript{
|
|||
.getService(DataTypeQueryService.class)
|
||||
.findDataTypes(baseName, null);
|
||||
if (foundTypes.size() == 0) {
|
||||
print(" can't find data type \"" + baseName + "\"");
|
||||
print(" can't find data type \"" + baseName + "\",");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
|
@ -153,6 +160,38 @@ public class EnhancedImport extends GhidraScript{
|
|||
final Address addr,
|
||||
final String[] parts
|
||||
) 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.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue