Ghidra is a software reverse engineering (SRE) framework
GP-4976 Only send back <typeref>
caheckmane80f52c22e34
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.ccindex 0f6f5d8c2f..2596d8629a 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc@@ -4825,6 +4825,7 @@ int4 ActionInternalStorage::apply(Funcdata &data)void ActionInferTypes::propagationDebug(Architecture *glb,Varnode *vn,const Datatype *newtype,PcodeOp *op,int4 slot,Varnode *ptralias){+ if (!TypeFactory::propagatedbg_on) return;ostringstream s;vn->printRaw(s);@@ -5225,9 +5226,11 @@ int4 ActionInferTypes::apply(Funcdata &data)VarnodeLocSet::const_iterator iter;#ifdef TYPEPROP_DEBUG- ostringstream s;- s << "Type propagation pass - " << dec << localcount;- data.getArch()->printDebug(s.str());+ if (TypeFactory::propagatedbg_on) {+ ostringstream s;+ s << "Type propagation pass - " << dec << localcount;+ data.getArch()->printDebug(s.str());+ }#endifif (localcount >= 7) { // This constant arrived at empiricallyif (localcount == 7) {diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.ccindex e73485a861..59284ecbab 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.cc@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -79,7 +79,7 @@ void CPoolRecord::encode(Encoder &encoder) constencoder.writeString(ATTRIB_CONTENT, token);encoder.closeElement(ELEM_TOKEN);}- type->encode(encoder);+ type->encodeRef(encoder);encoder.closeElement(ELEM_CPOOLREC);}diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.ccindex d6ead436ac..9e03ab2de3 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.cc@@ -5,9 +5,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -257,7 +257,16 @@ void FileManage::directoryList(vector<string> &res,const string &dirname,bool alif (dir == (DIR *)0) return;entry = readdir(dir);while(entry != (struct dirent *)0) {- if (entry->d_type == DT_DIR) {+ bool isDirectory = false;+ if (entry->d_type == DT_DIR)+ isDirectory = true;+ else if (entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK) {+ string path = dirfinal + entry->d_name;+ struct stat stbuf;+ stat(path.c_str(), &stbuf);+ isDirectory = S_ISDIR(stbuf.st_mode);+ }+ if (isDirectory) {string fullname(entry->d_name);if ((fullname!=".")&&(fullname!="..")) {if (allowdot || (fullname[0] != '.'))diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.ccindex 6ebec206c9..d78b78731c 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc@@ -3378,7 +3378,7 @@ void ProtoStoreInternal::encode(Encoder &encoder) constif (outparam->isTypeLocked())encoder.writeBool(ATTRIB_TYPELOCK,true);outparam->getAddress().encode(encoder);- outparam->getType()->encode(encoder);+ outparam->getType()->encodeRef(encoder);encoder.closeElement(ELEM_RETPARAM);}else {@@ -3406,7 +3406,7 @@ void ProtoStoreInternal::encode(Encoder &encoder) constif (param->isHiddenReturn())encoder.writeBool(ATTRIB_HIDDENRETPARM, true);param->getAddress().encode(encoder);- param->getType()->encode(encoder);+ param->getType()->encodeRef(encoder);encoder.closeElement(ELEM_PARAM);}encoder.closeElement(ELEM_INTERNALLIST);@@ -3422,7 +3422,7 @@ void ProtoStoreInternal::decode(Decoder &decoder,ProtoModel *model)proto.firstVarArgSlot = -1;bool addressesdetermined = true;- pieces.push_back( ParameterPieces() ); // Push on placeholder for output pieces+ pieces.emplace_back(); // Push on placeholder for output piecespieces.back().type = outparam->getType();pieces.back().flags = 0;if (outparam->isTypeLocked())@@ -4599,7 +4599,7 @@ void FuncProto::encode(Encoder &encoder) constif (outparam->isTypeLocked())encoder.writeBool(ATTRIB_TYPELOCK, true);outparam->getAddress().encode(encoder,outparam->getSize());- outparam->getType()->encode(encoder);+ outparam->getType()->encodeRef(encoder);encoder.closeElement(ELEM_RETURNSYM);encodeEffect(encoder);encodeLikelyTrash(encoder);diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.ccindex 0237adb820..455d35bffe 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -155,6 +155,10 @@ void IfaceDecompCapability::registerCommands(IfaceStatus *status)status->registerCom(new IfcTraceList(),"trace","list");status->registerCom(new IfcBreakjump(),"break","jumptable");#endif++#ifdef TYPEPROP_DEBUG+ status->registerCom(new IfcTracePropagation(),"trace","propagation");+#endif}/// Runs over every function in the scope, or any sub-scope , calling@@ -3586,6 +3590,24 @@ void IfcBreakjump::execute(istream &s)#endif+#ifdef TYPEPROP_DEBUG++void IfcTracePropagation::execute(istream &s)++{+ string token;+ s >> ws >> token;+ if (token == "on")+ TypeFactory::propagatedbg_on = true;+ else if (token == "off")+ TypeFactory::propagatedbg_on = false;+ else+ throw IfaceParseError("Must specific on/off");+ *status->optr << "Data-type propagation trace set to: "<< token << endl;+}++#endif+/// Execute one command and handle any exceptions./// Error messages are printed to the console. For low-level errors,/// the current function is reset to nulldiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hhindex 2c305158e9..5958f67c88 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.hh@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -668,5 +668,14 @@ public:#endif+#ifdef TYPEPROP_DEBUG++class IfcTracePropagation : public IfaceDecompCommand {+public:+ virtual void execute(istream &s);+};++#endif+} // End namespace ghidra#endifdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.ccindex 66c239e66f..935f2fc2db 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/paramid.cc@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -165,7 +165,7 @@ void ParamMeasure::encode( Encoder &encoder,ElementId &tag,bool moredetail ) conencoder.openElement(ELEM_ADDR);vndata.space->encodeAttributes( encoder, vndata.offset, vndata.size );encoder.closeElement(ELEM_ADDR);- vntype->encode(encoder);+ vntype->encodeRef(encoder);if( moredetail ) {encoder.openElement(ELEM_RANK);encoder.writeSignedInteger(ATTRIB_VAL, rank);diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/test.ccindex 603aaa5bb8..cd982a461a 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -38,7 +38,10 @@ int UnitTest::run(set<string> &testNames)t->func();++passed;cerr << " passed." << endl;+ } catch(LowlevelError &err) {+ cerr << " fail: " << err.explain << endl;} catch(...) {+ cerr << " fail" << endl;}}cerr << "==============================" << endl;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.ccindex 229d07c0c6..59dcc55949 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc@@ -3026,6 +3026,10 @@ void TypeSpacebase::decode(Decoder &decoder,TypeFactory &typegrp)// decoder.closeElement(elemId);}+#ifdef TYPEPROP_DEBUG+bool TypeFactory::propagatedbg_on = false;+#endif+/// Initialize an empty container/// \param g is the owning ArchitectureTypeFactory::TypeFactory(Architecture *g)@@ -4358,7 +4362,7 @@ Datatype *TypeFactory::decodeTypeNoRef(Decoder &decoder,bool forcecore)break;case TYPE_SPACEBASE:{- TypeSpacebase tsb((AddrSpace *)0,Address(),glb);+ TypeSpacebase tsb(glb);tsb.decode(decoder,*this);if (forcecore)tsb.flags |= Datatype::coretype;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/type.hhindex 0fb1a2891a..2f2d1344a7 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh@@ -690,6 +690,8 @@ public:TypeSpacebase(const TypeSpacebase &op) : Datatype(op) {spaceid = op.spaceid; localframe=op.localframe; glb=op.glb;}+ /// Constructor for use with decode+ TypeSpacebase(Architecture *g) : Datatype(0,1,TYPE_SPACEBASE) { spaceid = (AddrSpace *)0; glb = g; }/// Construct given an address space, scope, and architectureTypeSpacebase(AddrSpace *id,const Address &frame,Architecture *g): Datatype(0,1,TYPE_SPACEBASE), localframe(frame) { spaceid = id; glb = g; }@@ -820,6 +822,9 @@ public:void cacheCoreTypes(void); ///< Cache common typeslist<DatatypeWarning>::const_iterator beginWarnings(void) const { return warnings.begin(); } ///< Start of data-type warningslist<DatatypeWarning>::const_iterator endWarnings(void) const { return warnings.end(); } ///< End of data-type warnings+#ifdef TYPEPROP_DEBUG+ static bool propagatedbg_on; ///< If \b true, display data-type propagation trace+#endif};/// The display format for the data-type is changed based on the given format. A value ofdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/types.h b/Ghidra/Features/Decompiler/src/decompile/cpp/types.hindex ddbff99431..ef752b5924 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/types.h+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/types.h@@ -5,9 +5,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -88,8 +88,8 @@ CPUI_DEBUG -- This is the ONE debug switch that should be passed in#ifdef CPUI_DEBUG# define OPACTION_DEBUG# define PRETTY_DEBUG+# define TYPEPROP_DEBUG//# define __REMOTE_SOCKET__-//# define TYPEPROP_DEBUG//# define DFSVERIFY_DEBUG//# define BLOCKCONSISTENT_DEBUG//# define MERGEMULTI_DEBUGdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.ccindex 7fa2c47667..08f48726de 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.cc@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -845,7 +845,7 @@ void HighVariable::encode(Encoder &encoder) constif (symboloffset >= 0)encoder.writeSignedInteger(ATTRIB_OFFSET, symboloffset);}- getType()->encode(encoder);+ getType()->encodeRef(encoder);for(int4 j=0;j<inst.size();++j) {encoder.openElement(ELEM_ADDR);encoder.writeUnsignedInteger(ATTRIB_REF, inst[j]->getCreateIndex());