Ghidra is a software reverse engineering (SRE) framework
allow constant pointers to be inferred inside of strings
caheckman91ef0680dac2
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.ccindex dfbec2d55f..74b587740f 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc@@ -1087,8 +1087,16 @@ SymbolEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op// Since we are looking for a global address// Assume it is address tied and use empty usepointSymbolEntry *entry = data.getScopeLocal()->getParent()->queryContainer(rampoint,1,Address());- if (needexacthit&&(entry != (SymbolEntry *)0)) {- if (entry->getAddr() != rampoint)+ if (entry != (SymbolEntry *)0) {+ Datatype *ptrType = entry->getSymbol()->getType();+ if (ptrType->getMetatype() == TYPE_ARRAY) {+ Datatype *ct = ((TypeArray *)ptrType)->getBase();+ // In the special case of strings (character arrays) we allow the constant pointer to+ // refer to the middle of the string+ if (ct->isCharPrint())+ needexacthit = false;+ }+ if (needexacthit && entry->getAddr() != rampoint)return (SymbolEntry *)0;}return entry;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.ccindex e15e9870bc..558ed12b65 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc@@ -6553,7 +6553,6 @@ bool RulePtrsubCharConstant::pushConstFurther(Funcdata &data,TypePointer *outtypVarnode *vn = op->getIn(1);if (!vn->isConstant()) return false; // that is adding a constantuintb addval = vn->getOffset();- if (addval > 128) return false; // Sanity check on string sizeaddval *= op->getIn(2)->getOffset();val += addval;Varnode *newconst = data.newConstant(vn->getSize(),val);