Skip to content

Ghidra is a software reverse engineering (SRE) framework

Marshaling of hasThisPointer property

caheckmandb139d2b8185
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
index 0ce16d71e2..b3be7ca4a5 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
@@ -3683,8 +3683,6 @@ void FuncProto::saveXml(ostream &s) const
a_v_b(s,"constructor",true);
if (isDestructor())
a_v_b(s,"destructor",true);
- if (hasThisPointer())
- a_v_b(s,"hasthis",true);
s << ">\n";
ProtoParameter *outparam = store->getOutput();
s << " <returnsym";
@@ -3828,10 +3826,6 @@ void FuncProto::restoreXml(const Element *el,Architecture *glb)
if (xml_readbool(el->getAttributeValue(i)))
flags |= is_destructor;
}
- else if (attrname == "hasthis") {
- if (xml_readbool(el->getAttributeValue(i)))
- flags |= has_thisptr;
- }
}
if (mod != (ProtoModel *)0) // If a model was specified
setModel(mod); // This sets extrapop to model default
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc
index 394c5e2538..7b6c174963 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.cc
@@ -37,7 +37,7 @@ PrintLanguage *PrintJavaCapability::buildLanguage(Architecture *glb)
PrintJava::PrintJava(Architecture *glb,const string &nm) : PrintC(glb,nm)
{
- option_NULL = true; // Automatically use 'null' token
+ resetDefaultsPrintJava();
nullToken = "null"; // Java standard lower-case 'null'
mods |= hide_thisparam; // turn on hiding of 'this' parameter
if (castStrategy != (CastStrategy *)0)
@@ -46,6 +46,13 @@ PrintJava::PrintJava(Architecture *glb,const string &nm) : PrintC(glb,nm)
castStrategy = new CastStrategyJava();
}
+void PrintJava::resetDefaults(void)
+
+{
+ PrintC::resetDefaults();
+ resetDefaultsPrintJava();
+}
+
void PrintJava::docFunction(const Funcdata *fd)
{
@@ -148,6 +155,13 @@ bool PrintJava::isArrayType(const Datatype *ct)
return false;
}
+void PrintJava::resetDefaultsPrintJava(void)
+
+{
+ option_NULL = true; // Automatically use 'null' token
+ option_convention = false; // Automatically hide convention name
+}
+
/// Assuming the given Varnode is a dereferenced pointer, determine whether
/// it needs to be represented using '[0]' syntax.
/// \param vn is the given Varnode
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh
index fc62ab931f..f3f200d115 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printjava.hh
@@ -56,9 +56,11 @@ class PrintJava : public PrintC {
static OpToken instanceof; ///< The \b instanceof keyword
static bool isArrayType(const Datatype *ct); ///< Does the given data-type reference a java array
static bool needZeroArray(const Varnode *vn); ///< Do we need '[0]' syntax.
+ void resetDefaultsPrintJava(void); ///< Set options that are specific to Java
virtual void printUnicode(ostream &s,int4 onechar) const;
public:
PrintJava(Architecture *g,const string &nm="java-language"); ///< Constructor
+ virtual void resetDefaults(void);
virtual void docFunction(const Funcdata *fd);
virtual void pushTypeStart(const Datatype *ct,bool noident);
virtual void pushTypeEnd(const Datatype *ct);
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/FunctionPrototype.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/FunctionPrototype.java
index 091e1e6162..ffbc88094b 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/FunctionPrototype.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/FunctionPrototype.java
@@ -52,7 +52,9 @@ public class FunctionPrototype {
private boolean isDestruct; // Function is an object destructor
/**
- * Construct a FunctionPrototype backed by a local symbolmap
+ * Construct a FunctionPrototype backed by a local symbolmap.
+ * This is only a partial initialization. It is intended to be followed either by
+ * grabFromFunction() or readPrototypeXML()
*
* @param ls is the LocalSymbolMap backing the prototype
* @param func is the function using the symbolmap
@@ -102,7 +104,7 @@ public class FunctionPrototype {
noreturn = false;
custom = false;
extrapop = model.getExtrapop();
- hasThis = false;
+ hasThis = model.hasThisPointer();
isConstruct = false;
isDestruct = false;
// FIXME: If the FunctionDefinition has no parameters
@@ -126,6 +128,11 @@ public class FunctionPrototype {
*/
void grabFromFunction(Function f, int overrideExtrapop, boolean doOverride) {
modelname = f.getCallingConventionName();
+ PrototypeModel protoModel = f.getCallingConvention();
+ if (protoModel == null) {
+ protoModel = f.getProgram().getCompilerSpec().getDefaultCallingConvention();
+ }
+ hasThis = protoModel.hasThisPointer();
modellock =
((modelname != null) && (modelname != Function.UNKNOWN_CALLING_CONVENTION_STRING));
injectname = f.getCallFixup();
@@ -164,10 +171,6 @@ public class FunctionPrototype {
extrapop = overrideExtrapop;
}
else {
- PrototypeModel protoModel = f.getCallingConvention();
- if (protoModel == null) {
- protoModel = f.getProgram().getCompilerSpec().getDefaultCallingConvention();
- }
if (purge == Function.INVALID_STACK_DEPTH_CHANGE ||
purge == Function.UNKNOWN_STACK_DEPTH_CHANGE) {
extrapop = protoModel.getExtrapop();
@@ -343,9 +346,6 @@ public class FunctionPrototype {
if (custom) {
SpecXmlUtils.encodeBooleanAttribute(res, "custom", custom);
}
- if (hasThis) {
- SpecXmlUtils.encodeBooleanAttribute(res, "hasthis", hasThis);
- }
if (isConstruct) {
SpecXmlUtils.encodeBooleanAttribute(res, "constructor", isConstruct);
}
@@ -421,6 +421,12 @@ public class FunctionPrototype {
throws PcodeXMLException {
XmlElement node = parser.start("prototype");
modelname = node.getAttribute("model");
+ PrototypeModel protoModel =
+ dtmanage.getProgram().getCompilerSpec().getCallingConvention(modelname);
+ if (protoModel == null) {
+ throw new PcodeXMLException("Bad prototype model name: " + modelname);
+ }
+ hasThis = protoModel.hasThisPointer();
String val = node.getAttribute("extrapop");
if (val.equals("unknown")) {
extrapop = PrototypeModel.UNKNOWN_EXTRAPOP;
@@ -452,10 +458,6 @@ public class FunctionPrototype {
if (node.hasAttribute("custom")) {
custom = SpecXmlUtils.decodeBoolean(node.getAttribute("custom"));
}
- hasThis = false;
- if (node.hasAttribute("hasthis")) {
- hasThis = SpecXmlUtils.decodeBoolean(node.getAttribute("hasthis"));
- }
isConstruct = false;
if (node.hasAttribute("constructor")) {
isConstruct = SpecXmlUtils.decodeBoolean(node.getAttribute("constructor"));