Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2422: Fixed bugs with generating PE .exports files

Ryan Kurtz25a32e00237f
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 8ea6d4b268..2f1228e076 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
@@ -107,25 +107,36 @@ class LibrarySymbolTable {
while (iter.hasNext()) {
monitor.checkCanceled();
Symbol sym = iter.next();
+
+ // Only consider ordinal exports, not ordinal imports
+ if (!(sym.isGlobal() && sym.isExternalEntryPoint())) {
+ continue;
+ }
+
int ordinal = SymbolUtilities.getOrdinalValue(sym.getName());
if (ordinal == -1) {
- throw new RuntimeException("Should never happen!");
- }
- Address symAddr = sym.getAddress();
- String realName = sym.getName();
- Symbol primary = symTab.getPrimarySymbol(symAddr);
- if (primary != null) {
- realName = primary.getName();
+ continue;
}
- // assumes that Ordinal_# name comes right before the actual name
+ // The symbols at the given address should be in a list ordered like:
+ // [realName1, ordinalName1, realName2, ordinalName2, ...]
+ // where the realName elements are optional. For example,
+ // [ordinalName1, realName2, ordinalName2, ordinalName3, ...]
+ // is also valid. We want to find our ordinalName in the list and look at the
+ // previous entry to find its corresponding realName. If there is no previous
+ // entry or the previous entry starts with Ordinal_, then we'll assume it's
+ // a [NONAME] export and we'll just use the ordinalName as the realName.
+ String ordinalName = sym.getName();
+ String realName = ordinalName;
+ Address symAddr = sym.getAddress();
Symbol symbolsAt[] = symTab.getSymbols(symAddr);
for (int i = 0; i < symbolsAt.length; i++) {
- if (symbolsAt[i].getName().equals(sym.getName())) {
- if (i + 1 < symbolsAt.length) {
- realName = symbolsAt[i + 1].getName();
- break;
+ if (symbolsAt[i].getName().equals(ordinalName)) {
+ if (i > 0 &&
+ !symbolsAt[i - 1].getName().startsWith(SymbolUtilities.ORDINAL_PREFIX)) {
+ realName = symbolsAt[i - 1].getName();
}
+ break;
}
}