Skip to content

Ghidra is a software reverse engineering (SRE) framework

Adjusting some guard analysis

caheckman163fa4af5775
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
index 359f3867c8..9dd21579b9 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
@@ -25,8 +25,8 @@
vector<ArchitectureCapability *> ArchitectureCapability::thelist;
-const uint4 ArchitectureCapability::majorversion = 3;
-const uint4 ArchitectureCapability::minorversion = 5;
+const uint4 ArchitectureCapability::majorversion = 4;
+const uint4 ArchitectureCapability::minorversion = 0;
/// This builds a list of just the ArchitectureCapability extensions
void ArchitectureCapability::initialize(void)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc
index ee4ccc9053..9e666c8fb5 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc
@@ -1033,6 +1033,15 @@ void JumpBasic::analyzeGuards(BlockBasic *bl,int4 pathout)
PcodeOp *cbranch = prevbl->lastOp();
if ((cbranch==(PcodeOp *)0)||(cbranch->code() != CPUI_CBRANCH))
break;
+ if (i != 0) {
+ // Check that this CBRANCH isn't protecting some other switch
+ BlockBasic *otherbl = (BlockBasic *)prevbl->getOut(1-indpath);
+ PcodeOp *otherop = otherbl->lastOp();
+ if (otherop != (PcodeOp *)0 && otherop->code() == CPUI_BRANCHIND) {
+ if (otherop != jumptable->getIndirectOp())
+ break;
+ }
+ }
bool toswitchval = (indpath == 1);
if (cbranch->isBooleanFlip())
toswitchval = !toswitchval;
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc
index e5bfe0ac0b..54980406bb 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/rangeutil.cc
@@ -1066,8 +1066,9 @@ Varnode *CircleRange::pullBack(PcodeOp *op,Varnode **constMarkup,bool usenzmask)
CircleRange nzrange;
if (!nzrange.setNZMask(res->getNZMask(),res->getSize()))
return res;
- if (0!=intersect(nzrange))
- return (Varnode *)0;
+ intersect(nzrange);
+ // If the intersect does not succeed (i.e. produces 2 pieces) the original range is
+ // preserved and we still consider this pullback successful.
}
return res;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
index 454afad54f..dc75dd8d0d 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
@@ -2487,6 +2487,7 @@ int4 RuleZextEliminate::applyOp(PcodeOp *op,Funcdata &data)
if (!vn2->isConstant()) return 0;
zext = vn1->getDef();
if (!zext->getIn(0)->isHeritageKnown()) return 0;
+ if (vn1->loneDescend() != op) return 0; // Make sure extension is not used for anything else
smallsize = zext->getIn(0)->getSize();
val = vn2->getOffset();
if ((val>>(8*smallsize))==0) { // Is zero extension unnecessary