angr.state_plugins.plugin¶
- class angr.state_plugins.plugin.SimStatePlugin¶
Bases:
objectThis is a base class for SimState plugins. A SimState plugin will be copied along with the state when the state is branched. They are intended to be used for things such as tracking open files, tracking heap details, and providing storage and persistence for SimProcedures.
- STRONGREF_STATE = False¶
- __init__()¶
- Return type:
None
- static memo(f)¶
A decorator function you should apply to
copy
- copy(_memo)¶
Should return a copy of the plugin without any state attached. Should check the memo first, and add itself to memo if it ends up making a new copy.
In order to simplify using the memo, you should annotate implementations of this function with
SimStatePlugin.memoThe base implementation of this function constructs a new instance of the plugin’s class without calling its initializer. If you super-call down to it, make sure you instantiate all the fields in your copy method!
- Parameters:
- Return type:
- merge(others, merge_conditions, common_ancestor=None)¶
Should merge the state plugin with the provided others. This will be called by
state.merge()after copying the target state, so this should mutate the current instance to merge with the others.Note that when multiple instances of a single plugin object (for example, a file) are referenced in the state, it is important that merge only ever be called once. This should be solved by designating one of the plugin’s referees as the “real owner”, who should be the one to actually merge it. This technique doesn’t work to resolve the similar issue that arises during copying because merging doesn’t produce a new reference to insert.
There will be n
othersand n+1 merge conditions, since the first condition corresponds to self. To match elements up to conditions, sayzip([self] + others, merge_conditions)When implementing this, make sure that you “deepen” both
othersandcommon_ancestorbefore calling sub-elements’ merge methods, e.g.self.foo.merge( [o.foo for o in others], merge_conditions, common_ancestor=common_ancestor.foo if common_ancestor is not None else None )
During static analysis, merge_conditions can be None, in which case you should use
state.solver.union(values). TODO: fish please make this less bullshitThere is a utility
claripy.ite_caseswhich will help with constructing arbitrarily large merged ASTs. Use it likeself.bar = claripy.ite_cases(zip(conditions[1:], [o.bar for o in others]), self.bar)- Parameters:
others – the other state plugins to merge with
merge_conditions – a symbolic condition for each of the plugins
common_ancestor – a common ancestor of this plugin and the others being merged
- Returns:
True if the state plugins are actually merged.
- Return type:
- widen(others)¶
The widening operation for plugins. Widening is a special kind of merging that produces a more general state from several more specific states. It is used only during intensive static analysis. The same behavior regarding copying and mutation from
mergeshould be followed.- Parameters:
others (
Iterable[SimStatePlugin]) – the other state plugins to widen with- Returns:
True if the state plugin is actually widened.
- Return type:
- classmethod register_default(name, xtr=None)¶
- Return type:
- Parameters:
name (str)
xtr (type[SimStatePlugin] | str | None)