typecontainer module¶
A |
- class TypeContainer(handle: LP_BNTypeContainer)[source]¶
Bases:
object
A
TypeContainer
is a generic interface to access various Binary Ninja models that contain types. Types are stored with both a unique id and a unique name.- Parameters:
handle (LP_BNTypeContainer) –
- add_types(types: Mapping[Iterable[str | bytes] | str | QualifiedName, Type], progress_func: Callable[[int, int], bool] | None = None) Mapping[QualifiedName, str] | None [source]¶
Add or update types to a Type Container. If the Type Container already contains a type with the same name as a type being added, the existing type will be replaced with the definition given to this function, and references will be updated in the source model.
An optional progress callback is included because adding many types can be a slow operation.
- Parameters:
- Returns:
Dict from name -> id of type in Type Container for all added types if successful, None otherwise.
- Return type:
Mapping[QualifiedName, str] | None
- delete_type(type_id: str) bool [source]¶
Delete a type in the Type Container. Behavior of references to this type is not specified and you may end up with broken references if any still exist. :param type_id: Id of type to delete :return: True if successful
- get_type_by_id(type_id: str) Type | None [source]¶
Get the definition of the type in the Type Container with the given id. If no type with that id exists, returns None. :param type_id: Id of type :return: Type object, if exists, else, None
- get_type_by_name(type_name: Iterable[str | bytes] | str | QualifiedName) Type | None [source]¶
Get the definition of the type in the Type Container with the given name. If no type with that name exists, returns None. :param type_name: Name of type :return: Type object, if exists, else, None
- get_type_id(type_name: Iterable[str | bytes] | str | QualifiedName) str | None [source]¶
Get the unique id of the type in the Type Container with the given name. If no type with that name exists, returns None. :param type_name: Name of type :return: Type id, if exists, else, None
- get_type_name(type_id: str) QualifiedName | None [source]¶
Get the unique name of the type in the Type Container with the given id. If no type with that id exists, returns None. :param type_id: Id of type :return: Type name, if exists, else, None
- Parameters:
type_id (str) –
- Return type:
QualifiedName | None
- parse_types_from_source(source: str, file_name: str, options: List[str] | None = None, include_dirs: List[str] | None = None, auto_type_source: str = '') Tuple[TypeParserResult | None, List[TypeParserError]] [source]¶
Parse an entire block of source into types, variables, and functions, with knowledge of the types in the Type Container.
- Parameters:
source (str) – Source code to parse
file_name (str) – Name of the file containing the source (optional: exists on disk)
options (List[str] | None) – Optional string arguments to pass as options, e.g. command line arguments
include_dirs (List[str] | None) – Optional list of directories to include in the header search path
auto_type_source (str) – Optional source of types if used for automatically generated types
- Returns:
A tuple of (result, errors) where the result is None if there was a fatal error
- Return type:
Tuple[TypeParserResult | None, List[TypeParserError]]
- rename_type(type_id: str, new_name: Iterable[str | bytes] | str | QualifiedName) bool [source]¶
Rename a type in the Type Container. All references to this type will be updated (by id) to use the new name. :param type_id: Id of type to update :param new_name: New name for the type :return: True if successful
- property container_type: TypeContainerType¶
Get the type of underlying model the Type Container is accessing. :return: Container type enum
- property id: str¶
Get an id string for the Type Container. This will be unique within a given analysis session, but may not be globally unique. :return: Identifier string
- property mutable: bool¶
Test if the Type Container supports mutable operations (add, rename, delete) :return: True if mutable
- property platform: Platform¶
Get the Platform object associated with this Type Container. All Type Containers have exactly one associated Platform (as opposed to, e.g. Type Libraries). :return: Associated Platform object
- property type_ids: List[str] | None¶
Get all type ids in a Type Container. :return: List of all type ids
- property type_names: List[QualifiedName] | None¶
Get all type names in a Type Container. :return: List of all type names
- property type_names_and_ids: Mapping[str, QualifiedName] | None¶
Get a mapping of all type ids and type names in a Type Container. :return: Dict of type id -> type name