mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
Roughed in alias block option
This commit is contained in:
parent
e4084b40ee
commit
04b4011166
5 changed files with 51 additions and 2 deletions
|
@ -96,6 +96,7 @@ Architecture::Architecture(void)
|
||||||
infer_pointers = true;
|
infer_pointers = true;
|
||||||
funcptr_align = 0;
|
funcptr_align = 0;
|
||||||
flowoptions = 0;
|
flowoptions = 0;
|
||||||
|
alias_block_level = 2; // Block structs and arrays by default
|
||||||
defaultfp = (ProtoModel *)0;
|
defaultfp = (ProtoModel *)0;
|
||||||
defaultReturnAddr.space = (AddrSpace *)0;
|
defaultReturnAddr.space = (AddrSpace *)0;
|
||||||
evalfp_current = (ProtoModel *)0;
|
evalfp_current = (ProtoModel *)0;
|
||||||
|
|
|
@ -130,6 +130,7 @@ public:
|
||||||
vector<AddrSpace *> inferPtrSpaces; ///< Set of address spaces in which a pointer constant is inferable
|
vector<AddrSpace *> inferPtrSpaces; ///< Set of address spaces in which a pointer constant is inferable
|
||||||
int4 funcptr_align; ///< How many bits of alignment a function ptr has
|
int4 funcptr_align; ///< How many bits of alignment a function ptr has
|
||||||
uint4 flowoptions; ///< options passed to flow following engine
|
uint4 flowoptions; ///< options passed to flow following engine
|
||||||
|
int4 alias_block_level; ///< Aliases blocked by 0=none, 1=struct, 2=array, 3=all
|
||||||
vector<Rule *> extra_pool_rules; ///< Extra rules that go in the main pool (cpu specific, experimental)
|
vector<Rule *> extra_pool_rules; ///< Extra rules that go in the main pool (cpu specific, experimental)
|
||||||
|
|
||||||
Database *symboltab; ///< Memory map of global variables and functions
|
Database *symboltab; ///< Memory map of global variables and functions
|
||||||
|
|
|
@ -784,3 +784,34 @@ string OptionToggleRule::apply(Architecture *glb,const string &p1,const string &
|
||||||
}
|
}
|
||||||
return res;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -258,4 +258,10 @@ public:
|
||||||
virtual string apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const;
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1084,6 +1084,7 @@ void ScopeLocal::markUnaliased(const vector<uintb> &alias)
|
||||||
if (rangemap == (EntryMap *)0) return;
|
if (rangemap == (EntryMap *)0) return;
|
||||||
list<SymbolEntry>::iterator iter,enditer;
|
list<SymbolEntry>::iterator iter,enditer;
|
||||||
|
|
||||||
|
int4 alias_block_level = glb->alias_block_level;
|
||||||
bool aliason = false;
|
bool aliason = false;
|
||||||
uintb curalias=0;
|
uintb curalias=0;
|
||||||
int4 i=0;
|
int4 i=0;
|
||||||
|
@ -1107,8 +1108,17 @@ void ScopeLocal::markUnaliased(const vector<uintb> &alias)
|
||||||
aliason = false;
|
aliason = false;
|
||||||
if (!aliason)
|
if (!aliason)
|
||||||
symbol->getScope()->setAttribute(symbol,Varnode::nolocalalias);
|
symbol->getScope()->setAttribute(symbol,Varnode::nolocalalias);
|
||||||
if (symbol->isTypeLocked())
|
if (symbol->isTypeLocked() && alias_block_level != 0) {
|
||||||
aliason = false;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue