Ghidra is a software reverse engineering (SRE) framework
setReturnBytesConsumed correctly evaluates if change has occurred
caheckmanaee17d9999c3
diff --git a/Ghidra/Features/Decompiler/certification.manifest b/Ghidra/Features/Decompiler/certification.manifestindex 1bf74fa054..58568e61c6 100644--- a/Ghidra/Features/Decompiler/certification.manifest+++ b/Ghidra/Features/Decompiler/certification.manifest@@ -17,6 +17,7 @@ src/decompile/datatests/forloop_thruspecial.xml||GHIDRA||||END|src/decompile/datatests/forloop_varused.xml||GHIDRA||||END|src/decompile/datatests/forloop_withskip.xml||GHIDRA||||END|src/decompile/datatests/loopcomment.xml||GHIDRA||||END|+src/decompile/datatests/multiret.xml||GHIDRA||||END|src/decompile/datatests/namespace.xml||GHIDRA||||END|src/decompile/datatests/nestedoffset.xml||GHIDRA||||END|src/decompile/datatests/noforloop_alias.xml||GHIDRA||||END|diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.ccindex bb40b24eef..e15ac703a5 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc@@ -3174,17 +3174,20 @@ void FuncProto::setOutputLock(bool val)store->getOutput()->setTypeLock(val);}-/// This value can be used as a hint as to how much of the return value is important and-/// is used to inform the dead code \e consume algorithm.-/// \param val is the estimated number of bytes or 0-/// \return \b true if the value was changed+/// Provide a hint as to how many bytes of the return value are important.+/// The smallest hint is used to inform the dead-code removal algorithm.+/// \param val is the hint (number of bytes or 0 for all bytes)+/// \return \b true if the smallest hint has changedbool FuncProto::setReturnBytesConsumed(int4 val){- int4 oldVal = returnBytesConsumed;- if (oldVal == 0 || val < oldVal)+ if (val == 0)+ return false;+ if (returnBytesConsumed == 0 || val < returnBytesConsumed) {returnBytesConsumed = val;- return (oldVal != val);+ return true;+ }+ return false;}/// \brief Assuming \b this prototype is locked, calculate the \e extrapopdiff --git a/Ghidra/Features/Decompiler/src/decompile/datatests/multiret.xml b/Ghidra/Features/Decompiler/src/decompile/datatests/multiret.xmlnew file mode 100644index 0000000000..b7e67d337b--- /dev/null+++ b/Ghidra/Features/Decompiler/src/decompile/datatests/multiret.xml@@ -0,0 +1,30 @@+<decompilertest>+<binaryimage arch="x86:LE:64:default:gcc">+<!--+ Contrived example that seems to set up multiple return value sizes.+ This used to make the decompiler enter an infinite loop.+-->+<bytechunk space="ram" offset="0x100000" readonly="true">+4883ec1864488b042528000000488944+240831c083fe01744f83fe02742a897c+2404488d7c2404e8dc0f00008b442404+488b542408644833142528000000753d+4883c418c3000000488d7c2404b8e903+00006689442404e8ac0f00008b442404+ebce000000000000488d7c2404c64424+0461e8910f00008b442404ebb3e88e0f+0000+</bytechunk>+</binaryimage>+<script>+ <com>map fun r0x100000 getval</com>+ <com>override flow r0x10007d callreturn</com>+ <com>lo fu getval</com>+ <com>decompile</com>+ <com>print C</com>+ <com>quit</com>+</script>+<stringmatch name="Multi-size return #1" min="1" max="1">Stack20 = CONCAT31.*0x61</stringmatch>+<stringmatch name="Multi-size return #2" min="1" max="1">Stack20 = CONCAT22.*0x3e9</stringmatch>+<stringmatch name="Multi-size return #3" min="1" max="1">Stack20 = param_1</stringmatch>+</decompilertest>