mirror of
https://codeberg.org/KeybadeBlox/JSRF-Decompilation.git
synced 2026-04-06 20:40:23 +03:00
Summarize unrecognized types in EnhancedImport
Helps a little to debug things.
This commit is contained in:
parent
98d88cc212
commit
69d5bd1dbe
1 changed files with 28 additions and 12 deletions
|
|
@ -22,23 +22,25 @@ import ghidra.util.StringUtilities;
|
|||
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class EnhancedImport extends GhidraScript {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
final List<String> lines = Files.readAllLines(askFile("Select input file", "OK").toPath());
|
||||
|
||||
final Set<String> unknownTypes = new HashSet<>(256);
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
final String[] parts = lines.get(i).split("\t");;
|
||||
final Address addr = toAddr(parts[0]);
|
||||
|
||||
switch (parts[1]) {
|
||||
case "data": importData(addr, parts); break;
|
||||
case "func": importFunc(addr, parts); break;
|
||||
case "data": importData(addr, parts, unknownTypes); break;
|
||||
case "func": importFunc(addr, parts, unknownTypes); break;
|
||||
default: throw new Exception(
|
||||
"Symbol type \"" + parts[1] +
|
||||
"\" on line " + String.valueOf(i) +
|
||||
|
|
@ -46,11 +48,18 @@ public class EnhancedImport extends GhidraScript {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (unknownTypes.size() > 0)
|
||||
println(
|
||||
"\nWarning: following types were unrecognized:\n" +
|
||||
String.join(", ", unknownTypes)
|
||||
);
|
||||
}
|
||||
|
||||
private void importData(
|
||||
final Address addr,
|
||||
final String[] parts
|
||||
final Address addr,
|
||||
final String[] parts,
|
||||
final Set<String> unknownTypes
|
||||
) throws Exception {
|
||||
print("Importing data symbol \"" + parts[3] + "\"...");
|
||||
|
||||
|
|
@ -66,7 +75,7 @@ public class EnhancedImport extends GhidraScript {
|
|||
));
|
||||
|
||||
// Create data
|
||||
if (makeType(parts[2]).orElse(null) instanceof DataType t) {
|
||||
if (makeType(parts[2], unknownTypes).orElse(null) instanceof DataType t) {
|
||||
clearListing(addr, addr.add(Math.max(t.getLength(), 1) - 1));
|
||||
currentProgram.getListing().createData(addr, t);
|
||||
|
||||
|
|
@ -97,7 +106,10 @@ public class EnhancedImport extends GhidraScript {
|
|||
) : null;
|
||||
}
|
||||
|
||||
private Optional<DataType> makeType(final String type) throws Exception {
|
||||
private Optional<DataType> makeType(
|
||||
final String type,
|
||||
final Set<String> unknownTypes
|
||||
) throws Exception {
|
||||
/* Attempt to create the described type from a known base type */
|
||||
final String baseName = StringUtilities.findWord(type, 0);
|
||||
final List<DataType> foundTypes = state.getTool()
|
||||
|
|
@ -105,6 +117,7 @@ public class EnhancedImport extends GhidraScript {
|
|||
.findDataTypes(baseName, null);
|
||||
if (foundTypes.size() == 0) {
|
||||
print(" can't find data type \"" + baseName + "\",");
|
||||
unknownTypes.add(type);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
|
@ -156,16 +169,19 @@ public class EnhancedImport extends GhidraScript {
|
|||
}
|
||||
|
||||
private void importFunc(
|
||||
final Address addr,
|
||||
final String[] parts
|
||||
final Address addr,
|
||||
final String[] parts,
|
||||
final Set<String> unknownTypes
|
||||
) throws Exception {
|
||||
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.setReturnType(
|
||||
makeType(parts[2], unknownTypes).orElse(Undefined4DataType.dataType),
|
||||
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);
|
||||
|
|
@ -176,7 +192,7 @@ public class EnhancedImport extends GhidraScript {
|
|||
for (int i = 7; i < parts.length - 1; i += 2)
|
||||
args.add(new ParameterImpl(
|
||||
parts[i+1],
|
||||
makeType(parts[i]).orElse(Undefined4DataType.dataType),
|
||||
makeType(parts[i], unknownTypes).orElse(Undefined4DataType.dataType),
|
||||
currentProgram
|
||||
));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue