Ghidra is a software reverse engineering (SRE) framework
Propagation of data-types across signed comparisons
caheckman193ad764e539
diff --git a/Ghidra/Features/Decompiler/certification.manifest b/Ghidra/Features/Decompiler/certification.manifestindex 1bf74fa054..dc6f847d42 100644--- a/Ghidra/Features/Decompiler/certification.manifest+++ b/Ghidra/Features/Decompiler/certification.manifest@@ -25,6 +25,7 @@ src/decompile/datatests/noforloop_iterused.xml||GHIDRA||||END|src/decompile/datatests/offsetarray.xml||GHIDRA||||END|src/decompile/datatests/promotecompare.xml||GHIDRA||||END|src/decompile/datatests/readvolatile.xml||GHIDRA||||END|+src/decompile/datatests/sbyte.xml||GHIDRA||||END|src/decompile/datatests/threedim.xml||GHIDRA||||END|src/decompile/datatests/twodim.xml||GHIDRA||||END|src/decompile/datatests/wayoffarray.xml||GHIDRA||||END|diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.ccindex b9c43246fe..c9451d0b72 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc@@ -4305,6 +4305,8 @@ bool ActionInferTypes::propagateGoodEdge(PcodeOp *op,int4 inslot,int4 outslot,Vacase CPUI_MULTIEQUAL:if ((inslot!=-1)&&(outslot!=-1)) return false; // Must propagate input <-> outputbreak;+ case CPUI_INT_SLESS:+ case CPUI_INT_SLESSEQUAL:case CPUI_INT_LESS:case CPUI_INT_LESSEQUAL:if ((inslot==-1)||(outslot==-1)) return false; // Must propagate input <-> input@@ -4400,6 +4402,11 @@ bool ActionInferTypes::propagateTypeEdge(TypeFactory *typegrp,PcodeOp *op,int4 ielsenewtype = alttype;break;+ case CPUI_INT_SLESS:+ case CPUI_INT_SLESSEQUAL:+ if (alttype->getMetatype() != TYPE_INT) return false; // Only propagate signed things+ newtype = alttype;+ break;case CPUI_NEW:{Varnode *invn = op->getIn(0);diff --git a/Ghidra/Features/Decompiler/src/decompile/datatests/sbyte.xml b/Ghidra/Features/Decompiler/src/decompile/datatests/sbyte.xmlnew file mode 100644index 0000000000..3f62c807bc--- /dev/null+++ b/Ghidra/Features/Decompiler/src/decompile/datatests/sbyte.xml@@ -0,0 +1,30 @@+<decompilertest>+<binaryimage arch="x86:LE:64:default:gcc">+<!--+ Contrived example comparing a signed byte. The decompiler+ should not use the 'char' data-type.+-->+<bytechunk space="ram" offset="0x100000" readonly="true">+0fb647043c0a0f94c13cf70f94c208d1+75043c617e1a8b17488d3513000000bf+0100000031c0e9dd0f0000+</bytechunk>+<bytechunk space="ram" offset="0x100030" readonly="true">+f3c3+</bytechunk>+</binaryimage>+<script>+ <com>map fun r0x101008 printf nocode</com>+ <com>map fun r0x100000 printStruct</com>+ <com>parse line struct mystruct { int4 val; int1 thebyte; };</com>+ <com>parse line extern void printStruct(mystruct *ptr);</com>+ <com>override flow r0x100026 callreturn</com>+ <com>decompile</com>+ <com>print C</com>+ <com>quit</com>+</script>+<stringmatch name="Signed byte #1" min="1" max="1">Var1 = ptr->thebyte</stringmatch>+<stringmatch name="Signed byte #2" min="1" max="1">Var1 != 10</stringmatch>+<stringmatch name="Signed byte #3" min="1" max="1">Var1 != -9</stringmatch>+<stringmatch name="Signed byte #4" min="1" max="1">Var1 < 0x62</stringmatch>+</decompilertest>