Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7087: Improved the handling of JDOM attribute errors in the PE LibraryLookupTable (Closes #6288)

Ryan Kurtzebb5497940fb
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java
index 5e950ebf8c..021feb2bea 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java
@@ -94,7 +94,8 @@ public abstract class AbstractOrdinalSupportLoader extends AbstractLibrarySuppor
log.appendMsg("Created exports file: " + newExportsFile);
}
catch (IOException e) {
- log.appendMsg("Unable to create exports file for " + libFsrl);
+ log.appendMsg(
+ "Unable to create exports file for %s: %s".formatted(libFsrl, e.getMessage()));
}
}
else {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibraryLookupTable.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibraryLookupTable.java
index 13cc9933c1..01e1a6a089 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibraryLookupTable.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibraryLookupTable.java
@@ -19,6 +19,9 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
+import org.jdom2.IllegalDataException;
+import org.jdom2.IllegalNameException;
+
import generic.jar.ResourceFile;
import ghidra.app.util.bin.format.pe.ResourceDataDirectory;
import ghidra.app.util.importer.MessageLog;
@@ -173,7 +176,12 @@ public class LibraryLookupTable {
Msg.warn(LibraryLookupTable.class, "Can't write to installation directory");
}
else {
- symTab.write(f, new File(program.getExecutablePath()), version);
+ try {
+ symTab.write(f, new File(program.getExecutablePath()), version);
+ }
+ catch (IllegalNameException | IllegalDataException e) {
+ throw new IOException(e);
+ }
}
return file;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibrarySymbolTable.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibrarySymbolTable.java
index c26cc0ba5b..256b4a7e02 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibrarySymbolTable.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/LibrarySymbolTable.java
@@ -485,7 +485,8 @@ class LibrarySymbolTable {
//}
}
- void write(File output, File input, String lversion) throws IOException {
+ void write(File output, File input, String lversion)
+ throws IOException, IllegalNameException, IllegalDataException {
Element root = new Element("LIBRARY");
root.setAttribute("NAME", tableName);
@@ -515,16 +516,12 @@ class LibrarySymbolTable {
root.addContent(export);
}
- FileOutputStream fos = new FileOutputStream(output);
- try {
+ try (FileOutputStream fos = new FileOutputStream(output)) {
Document doc = new Document(root);
XMLOutputter xmlout = GenericXMLOutputter.getInstance();
xmlout.output(doc, fos);
}
- finally {
- fos.close();
- }
//StringBuffer buffer = new StringBuffer();
//Iterator iter = exportList.iterator();