Skip to content

Ghidra is a software reverse engineering (SRE) framework

fix: handle namespaces when processing bitfields

Alan Tse7d666ea34c62
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/DefaultPdbMember.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/DefaultPdbMember.java
index e5de9fa215..075f66b2b5 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/DefaultPdbMember.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/DefaultPdbMember.java
@@ -15,6 +15,10 @@
*/
package ghidra.app.util.bin.format.pdb;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+
+import ghidra.app.util.SymbolPathParser;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.InvalidDataTypeException;
import ghidra.util.Msg;
@@ -82,17 +86,17 @@ public class DefaultPdbMember extends PdbMember {
}
if (kind == PdbKind.MEMBER) {
// Strip bitfield data if present (see parseBitField method)
- int bitFieldColonIndex = name.indexOf(':');
+ int bitFieldColonIndex = getBitfieldIndex(name);
if (bitFieldColonIndex >= 0) {
return name.substring(0, bitFieldColonIndex);
}
}
// name may contain namespace prefix for non-Member class members
- int lastColonIndex = name.lastIndexOf(':');
- if (lastColonIndex > 0) {
- name = name.substring(lastColonIndex + 1);
+ if (StringUtils.isEmpty(name)) {
+ return name;
}
- return name;
+ List<String> names = SymbolPathParser.parse(name);
+ return names.get(names.size() - 1);
}
@Override
@@ -122,7 +126,7 @@ public class DefaultPdbMember extends PdbMember {
if (name == null || kind != PdbKind.MEMBER) {
return;
}
- int bitFieldColonIndex = name.indexOf(':');
+ int bitFieldColonIndex = getBitfieldIndex(name);
if (bitFieldColonIndex >= 0) {
isBitField = true;
@@ -147,4 +151,37 @@ public class DefaultPdbMember extends PdbMember {
}
}
+ /**
+ * Returns the index of the bit-field component of the mixed name field that is composed of
+ * a standard namespace name and an optional (non-namespace name compliant) bit-field
+ * component passed on from the native pdb.exe parser.
+ * <p>
+ * Assumes format: nameWithMixOfEmbeddedAndNonEmbeddedNamespaceDelimeters[:bfBitLen:bfBitOff].
+ * <p>
+ * The bfBitLen and bfBitOff fields are represented as hex with "0x" prefixes.
+ * <p>
+ * Note: we are unaware of any circumstance where, if there is a bit-field component, that
+ * there could also be a name with namespace delimiters; however, this method ensures that
+ * we can process any name from the pdb.exe
+ * @param name the name to parse
+ * @return the index of the bit-field component, which is the index of the first of two
+ * singleton colon characters, or -1 if there is no bit-field component
+ */
+ private static int getBitfieldIndex(String name) {
+ int loc = name.lastIndexOf(':');
+ // Minimum location of last singleton ':" is 5 as in this example: "a:0x1:0x0"
+ if (loc < 5) {
+ return -1;
+ }
+ if (name.charAt(loc - 1) == ':') { // means we found "::"
+ return -1;
+ }
+ loc = name.lastIndexOf(':', loc - 1);
+ // Since we found a single colon above, not finding a singleton colon here would prove
+ // to be a malformed format
+ if (loc > 0 && name.charAt(loc - 1) != ':') {
+ return loc;
+ }
+ return -1;
+ }
}