Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3487_emteere_MachOImportRegression fixed sorting of Macho Symboltable

emteere626f25f1bc47
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java
index 5a2cfbcc78..afdafe4e23 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java
@@ -84,19 +84,20 @@ public class SymbolTableCommand extends LoadCommand {
nlistList.add(NList.createNList(reader, is32bit));
}
// sort the entries by the index in the string table, so don't jump around reading
- List<NList> sortedList = nlistList
- .stream()
- .sorted(
- (o1, o2) -> Integer.compare(o1.getStringTableIndex(), o2.getStringTableIndex()))
- .collect(Collectors.toList());
+ List<NList> sortedList =
+ nlistList.stream().sorted((o1, o2) -> Integer.compare(o1.getStringTableIndex(),
+ o2.getStringTableIndex())).collect(Collectors.toList());
- // initialize the NList strings from string table
+ // initialize the sorted NList strings from string table
long stringTableOffset = stroff;
for (NList nList : sortedList) {
nList.initString(reader, stringTableOffset);
- symbols.add(nList);
}
+ // the symbol table should be in the original order.
+ // The table is indexed by other tables in the MachO headers
+ symbols = nlistList;
+
reader.setPointerIndex(index);
}