Ghidra is a software reverse engineering (SRE) framework
Roughed in alias block option
caheckman04b40111666d
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.ccindex 9dd21579b9..875078ec31 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc@@ -96,6 +96,7 @@ Architecture::Architecture(void)infer_pointers = true;funcptr_align = 0;flowoptions = 0;+ alias_block_level = 2; // Block structs and arrays by defaultdefaultfp = (ProtoModel *)0;defaultReturnAddr.space = (AddrSpace *)0;evalfp_current = (ProtoModel *)0;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hhindex e8a84eda04..0a67163fbd 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh@@ -130,6 +130,7 @@ public:vector<AddrSpace *> inferPtrSpaces; ///< Set of address spaces in which a pointer constant is inferableint4 funcptr_align; ///< How many bits of alignment a function ptr hasuint4 flowoptions; ///< options passed to flow following engine+ int4 alias_block_level; ///< Aliases blocked by 0=none, 1=struct, 2=array, 3=allvector<Rule *> extra_pool_rules; ///< Extra rules that go in the main pool (cpu specific, experimental)Database *symboltab; ///< Memory map of global variables and functionsdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/options.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/options.ccindex d998c5ec7f..a4deac3ae5 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/options.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/options.cc@@ -784,3 +784,34 @@ string OptionToggleRule::apply(Architecture *glb,const string &p1,const string &}return res;}++/// \class OptionAliasBlock+/// \brief Set how locked data-types on the stack affect alias heuristics+///+/// Stack analysis uses the following simple heuristic: a pointer is unlikely to reference (alias)+/// a stack location if there is a locked data-type between the pointer base and the location.+/// This option determines what kind of locked data-types \b block aliases in this way.+/// - none - no data-types will block an alias+/// - struct - only structure data-types will block an alias+/// - array - array data-types (and structure data-types) will block an alias+/// - all - all locked data-types will block an alias+string OptionAliasBlock::apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const++{+ if (p1.size() == 0)+ throw ParseError("Must specify alias block level");+ int4 oldVal = glb->alias_block_level;+ if (p1 == "none")+ glb->alias_block_level = 0;+ else if (p1 == "struct")+ glb->alias_block_level = 1;+ else if (p1 == "array")+ glb->alias_block_level = 2; // The default. Let structs and arrays block aliases+ else if (p1 == "all")+ glb->alias_block_level = 3;+ else+ throw ParseError("Unknown alias block level: "+p1);+ if (oldVal == glb->alias_block_level)+ return "Alias block level unchanged";+ return "Alias block level set to " + p1;+}diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/options.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/options.hhindex ad166b1289..d9f0cf62f4 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/options.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/options.hh@@ -258,4 +258,10 @@ public:virtual string apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const;};+class OptionAliasBlock : public ArchOption {+public:+ OptionAliasBlock(void) { name = "aliasblock"; } ///< Constructor+ virtual string apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const;+};+#endifdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.ccindex cadeb05f5a..e8b8e02b50 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc@@ -1084,6 +1084,7 @@ void ScopeLocal::markUnaliased(const vector<uintb> &alias)if (rangemap == (EntryMap *)0) return;list<SymbolEntry>::iterator iter,enditer;+ int4 alias_block_level = glb->alias_block_level;bool aliason = false;uintb curalias=0;int4 i=0;@@ -1107,8 +1108,17 @@ void ScopeLocal::markUnaliased(const vector<uintb> &alias)aliason = false;if (!aliason)symbol->getScope()->setAttribute(symbol,Varnode::nolocalalias);- if (symbol->isTypeLocked())- aliason = false;+ if (symbol->isTypeLocked() && alias_block_level != 0) {+ if (alias_block_level == 3)+ aliason = false; // For this level, all locked data-types block aliases+ else {+ type_metatype meta = symbol->getType()->getMetatype();+ if (meta == TYPE_STRUCT)+ aliason = false; // Only structures block aliases+ else if (meta == TYPE_ARRAY && alias_block_level > 1)+ aliason = false; // Only arrays (and structures) block aliases+ }+ }}}}