Ghidra is a software reverse engineering (SRE) framework
GP-4376 Add setPackedOutput to Emit
caheckman49af7f2db5b6
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.ccindex ac94d261c5..0237adb820 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc@@ -964,7 +964,9 @@ void IfcPrintCXml::execute(istream &s)dcp->conf->print->setOutputStream(status->fileoptr);dcp->conf->print->setMarkup(true);+ dcp->conf->print->setPackedOutput(false);dcp->conf->print->docFunction(dcp->fd);+ *status->fileoptr << endl;dcp->conf->print->setMarkup(false);}diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hhindex 6750a239d9..1fca0ed368 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh@@ -432,7 +432,7 @@ class XmlEncode : public Encoder {tag_stop = 2 ///< No tag is currently being written};static const char spaces[]; ///< Array of ' ' characters for emitting indents- static const int4 MAX_SPACES;+ static const int4 MAX_SPACES; ///< Maximum number of leading spaces when indenting XMLostream &outStream; ///< The stream receiving the encoded dataint4 tagStatus; ///< Stage of writing an element tagint4 depth; ///< Depth of open elementsdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.ccindex 459ee5c341..ad8a6ded10 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.cc@@ -329,6 +329,17 @@ void EmitMarkup::setOutputStream(ostream *t)encoder = new PackedEncode(*s);}+void EmitMarkup::setPackedOutput(bool val)++{+ if (encoder == (Encoder *)0) return;+ delete encoder;+ if (val)+ encoder = new PackedEncode(*s);+ else+ encoder = new XmlEncode(*s);+}+int4 TokenSplit::countbase = 0;/// Emit markup or content corresponding to \b this token on a low-level emitter.@@ -1199,9 +1210,6 @@ void EmitPrettyPrint::flush(void)lowlevel->flush();}-/// This method toggles the low-level emitter between EmitMarkup and EmitNoMarkup depending-/// on whether markup is desired.-/// \param val is \b true if markup is desiredvoid EmitPrettyPrint::setMarkup(bool val){diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hhindex 4b96b8cace..da60367503 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/prettyprint.hh@@ -349,6 +349,19 @@ public:virtual void clear(void) { parenlevel = 0; indentlevel=0; pendPrint=(PendPrint *)0; }virtual void setOutputStream(ostream *t)=0; ///< Set the output stream for the emittervirtual ostream *getOutputStream(void) const=0; ///< Get the current output stream++ /// \brief Toggle whether \b this emits mark-up or not++ /// If the emitter supports it, \b true turns on mark-up, \b false turns it off. Otherwise there is no effect.+ /// \param val is \b true if markup is desired+ virtual void setMarkup(bool val) {}++ /// \brief Toggle whether \b this emitter produces packed output+ ///+ /// If the emitter supports it, \b true selects packed output and \b false selects unpacked XML output.+ /// Otherwise the method has no effect.+ /// \param val is \b true for packed or \b false for unpacked+ virtual void setPackedOutput(bool val) {}virtual void spaces(int4 num,int4 bump=0);/// \brief Start a new indent level@@ -522,6 +535,7 @@ public:virtual void closeParen(const string &paren,int4 id);virtual void setOutputStream(ostream *t);virtual ostream *getOutputStream(void) const { return s; }+ virtual void setPackedOutput(bool val);virtual bool emitsMarkup(void) const { return true; }};@@ -1085,6 +1099,7 @@ public:virtual void clear(void);virtual void setOutputStream(ostream *t) { lowlevel->setOutputStream(t); }virtual ostream *getOutputStream(void) const { return lowlevel->getOutputStream(); }+ virtual void setPackedOutput(bool val) { lowlevel->setPackedOutput(val); }virtual void spaces(int4 num,int4 bump=0);virtual int4 startIndent(void);virtual void stopIndent(int4 id);@@ -1096,7 +1111,7 @@ public:virtual void setCommentFill(const string &fill) { commentfill = fill; }virtual bool emitsMarkup(void) const { return lowlevel->emitsMarkup(); }virtual void resetDefaults(void);- void setMarkup(bool val); ///< Toggle whether the low-level emitter emits markup or not+ virtual void setMarkup(bool val);};/// \brief Helper class for sending cancelable print commands to an ExitXmldiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.ccindex d29bd4e2a8..cee8630e70 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.cc@@ -648,12 +648,12 @@ void PrintLanguage::emitLineComment(int4 indent,const Comment *comm)comm->setEmitted(true);}-/// Tell the emitter whether to emit just the raw tokens or if additional mark-up should be provided.-/// \param val is \b true for additional mark-up-void PrintLanguage::setMarkup(bool val)+/// Select packed or unpacked (XML) output, if the emitter supports it.+/// \param val is \b true for packed or \b false for unpacked+void PrintLanguage::setPackedOutput(bool val){- ((EmitPrettyPrint *)emit)->setMarkup(val);+ emit->setPackedOutput(val);}/// Emitting formal code structuring can be turned off, causing all control-flowdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hhindex 07e3bda04e..7cdb7069cf 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/printlanguage.hh@@ -454,7 +454,8 @@ public:uint4 getHeaderComment(void) const { return head_comment_type; } ///< Get the type of comments suitable for a function headervoid setHeaderComment(uint4 val) { head_comment_type = val; } ///< Set the type of comments suitable for a function headerbool emitsMarkup(void) const { return emit->emitsMarkup(); } ///< Does the low-level emitter, emit markup- void setMarkup(bool val); ///< Set whether the low-level emitter, emits markup+ void setMarkup(bool val) { emit->setMarkup(val); } ///< Turn on/off mark-up in emitted output+ void setPackedOutput(bool val); ///< Turn on/off packed outputvoid setFlat(bool val); ///< Set whether nesting code structure should be emittedvirtual void initializeFromArchitecture(void)=0; ///< Initialize architecture specific aspects of printer