angr.knowledge_base¶
Representing the artifacts of a project.
- class angr.knowledge_base.KnowledgeBase¶
Bases:
objectRepresents a “model” of knowledge about an artifact.
Contains things like a CFG, data references, etc.
- functions: FunctionManager
- comments: Comments
- bookmarks: Bookmarks
- variables: VariableManager
- defs: KeyDefinitionManager
- cfgs: CFGManager
- types: TypesStore
- propagations: PropagationManager
- xrefs: XRefManager
- decompilations: StructuredCodeManager
- obfuscations: Obfuscations
- rtdb: RuntimeDb
- __init__(project, obj=None, name=None)¶
- property callgraph¶
- property unresolved_indirect_jumps¶
- property resolved_indirect_jumps¶
- has_plugin(name)¶
- get_plugin(name)¶
- register_plugin(name, plugin)¶
- release_plugin(name)¶
- get_knowledge[K: KnowledgeBasePlugin](requested_plugin_cls)¶
Type inference safe method to request a knowledge base plugin Explicitly passing the type of the requested plugin achieves two things: 1. Every location using this plugin can be easily found with an IDE by searching explicit references to the type 2. Basic type inference can deduce the result type and properly type check usages of it
If there isn’t already an instance of this class None will be returned to make it clear to the caller that there is no existing knowledge of this type yet. The code that initially creates this knowledge should use the register_plugin method to register the initial knowledge state :type requested_plugin_cls:
type[K] :param requested_plugin_cls:
- request_knowledge[K: KnowledgeBasePlugin](requested_plugin_cls)¶
- Return type:
K- Parameters:
requested_plugin_cls (type[K])
- class angr.knowledge_base.KnowledgeBaseSnapshot¶
Bases:
objectA restore point for a
KnowledgeBase, so that the same project and CFG can be analyzed repeatedly (for example, decompiling one function under several option sets) from an identical starting state.A snapshot records:
the plugin table, as a shallow copy of the name-to-plugin mapping;
by-value copies of the plugins named in
included_plugins(defaultCOPIED_PLUGINS) that exist at snapshot time;for each function resident in memory, its per-flavor prototypes, prototype sources, set of resolved flavors, and calling convention.
Without a rollback, a later
Decompilerrun sees the callee prototypes that Clinic installed onFunctionobjects during an earlier run, inherits that run’s variable numbering throughdec_variables, and, when its cache parameters match, reuses the earlierdecompilationsentry instead of running the pipeline.Functions are captured by object identity, and only the resident ones, because iterating a spilling function dict would evict the
Functionobjects that callers hold. As a result, prototype changes on functions that were spilled at snapshot time and loaded later are not rolled back.- COPIED_PLUGINS = ('types', 'custom_strings', 'callsite_prototypes', 'comments', 'variables')¶
- __init__(kb, included_plugins=None)¶
- Parameters:
kb (
KnowledgeBase) – The knowledge base to snapshot.included_plugins (
Iterable[str] |None) – Names of the plugins to restore by value; the others are kept by reference. Defaults toCOPIED_PLUGINS.
- restore()¶
Roll the knowledge base back to this snapshot. Plugins created after the snapshot are removed. Each included plugin is replaced by a fresh copy of the snapshot’s copy, so the snapshot itself is never modified. All other plugins are reinstated by reference, which means changes made to them in place are kept. Resident functions get their prototype state back. This method may be called any number of times.
- Return type: