Skip to content

Ghidra is a software reverse engineering (SRE) framework

Added escape to enum XML marshalling

caheckman2d1bd78759aa
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java
index 09b05e6453..2b9f8475d8 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java
@@ -120,9 +120,12 @@ public class PcodeDataTypeManager {
}
/**
- * Find a data type with the given name.
- * @param nm name of data type
- * @return may return null if no data type exists with the given name
+ * Find a base/built-in data-type with the given name and/or id. If an id is provided and
+ * a corresponding data-type exists, this data-type is returned. Otherwise the first
+ * built-in data-type with a matching name is returned
+ * @param nm name of data-type
+ * @param idstr is an optional string containing a data-type id number
+ * @return the data-type object or null if no matching data-type exists
*/
public DataType findBaseType(String nm, String idstr) {
long id = 0;
@@ -154,11 +157,12 @@ public class PcodeDataTypeManager {
}
/**
- * Get the data type that corresponds to the given XML element.
- * @param el element
- * @return data type
- * @throws PcodeXMLException if the data type could be resolved from the
- * element
+ * Read a data-type from the given XML stream. Either a <type>, <typeref>, or <void> tag is
+ * parsed. The described data-type object is either looked up from this DataTypeManager or
+ * minted (from components in this DataTypeManager) and returned.
+ * @param parser is the given XML stream
+ * @return the parse data-type
+ * @throws PcodeXMLException if the data type could be resolved
*/
public DataType readXMLDataType(XmlPullParser parser) throws PcodeXMLException {
XmlElement el = parser.start("type", "void", "typeref");
@@ -242,8 +246,13 @@ public class PcodeDataTypeManager {
}
/**
- * @param type to be converted
- * @return either a typeref tag giving the name, or a full type tag
+ * Generate an XML tag describing the given data-type. Most data-types produce a <type> tag,
+ * fully describing the data-type. Where possible a <typeref> tag is produced, which just gives
+ * the name of the data-type, deferring a full description of the data-type. For certain simple or
+ * nameless data-types, a <type> tag is emitted giving a full description.
+ * @param type is the data-type to be converted
+ * @param size is the size in bytes of the specific instance of the data-type
+ * @return a StringBuilder containing the XML tag
*/
public StringBuilder buildTypeRef(DataType type, int size) {
if (type != null && type.getDataTypeManager() != progDataTypes) {
@@ -424,7 +433,7 @@ public class PcodeDataTypeManager {
resBuf.append(">\n");
for (long key : keys) {
resBuf.append("<val");
- SpecXmlUtils.encodeStringAttribute(resBuf, "name", enumDt.getName(key));
+ SpecXmlUtils.xmlEscapeAttribute(resBuf, "name", enumDt.getName(key));
SpecXmlUtils.encodeSignedIntegerAttribute(resBuf, "value", key);
resBuf.append("/>");
}