pub struct TypeLibrary { /* private fields */ }Expand description
A TypeLibrary is a collection of function symbols and their associated types and metadata that
correspond to a shared library or are used in conjunction with a shared library. Type libraries
are the main way external functions in a binary view are annotated and are crucial to allowing
proper analysis of the binary.
Type libraries can share common types between them by forwarding named type references to a specified source type library. If a type library is made available to a view, it may also pull in other type libraries, it is important to not treat a type library as a complete source of information.
Implementations§
Source§impl TypeLibrary
impl TypeLibrary
Sourcepub fn duplicate(&self) -> Ref<Self>
pub fn duplicate(&self) -> Ref<Self>
Duplicate the type library. This creates a new, non-finalized type library object that shares the same underlying name and architecture.
IMPORTANT: This does not actually duplicate the type library currently, you still need to copy over the named types, named objects, platforms, and metadata.
Sourcepub fn new(arch: CoreArchitecture, name: &str) -> Ref<TypeLibrary>
pub fn new(arch: CoreArchitecture, name: &str) -> Ref<TypeLibrary>
Creates an empty type library object with a random GUID and the provided name.
pub fn all(arch: CoreArchitecture) -> Array<TypeLibrary>
Sourcepub fn load_from_file(path: &Path) -> Option<Ref<TypeLibrary>>
pub fn load_from_file(path: &Path) -> Option<Ref<TypeLibrary>>
Loads a finalized type library instance from the given path.
The returned type library cannot be modified.
Sourcepub fn write_to_file(&self, path: &Path) -> bool
pub fn write_to_file(&self, path: &Path) -> bool
Saves a type library at the given path on disk, overwriting any existing file.
The path must be writable, and the parent directory must exist.
Sourcepub fn decompress_to_file(&self, output_path: &Path) -> bool
pub fn decompress_to_file(&self, output_path: &Path) -> bool
Decompresses the type library file to a JSON file at the given output_path.
Sourcepub fn from_name(arch: CoreArchitecture, name: &str) -> Option<Ref<TypeLibrary>>
pub fn from_name(arch: CoreArchitecture, name: &str) -> Option<Ref<TypeLibrary>>
Looks up the first type library found with a matching name. Keep in mind that names are not necessarily unique.
NOTE: If the type library architecture’s associated platform has not been initialized, this will
return None. To make sure that the platform has been initialized, one should instead get the type
libraries through Platform::get_type_libraries_by_name.
Sourcepub fn from_guid(arch: CoreArchitecture, guid: &str) -> Option<Ref<TypeLibrary>>
pub fn from_guid(arch: CoreArchitecture, guid: &str) -> Option<Ref<TypeLibrary>>
Attempts to grab a type library associated with the provided Architecture and GUID pair.
NOTE: If the associated platform for the architecture has not been initialized,
this will return None. Avoid calling this outside of a view context.
Sourcepub fn arch(&self) -> CoreArchitecture
pub fn arch(&self) -> CoreArchitecture
The CoreArchitecture this type library is associated with.
Type libraries will always have a single architecture associated with it. It can have multiple
platforms associated with it, see TypeLibrary::platform_names for more detail.
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
The primary name associated with this type library, this will not be used for importing type
libraries automatically into a binary view, that is the job of TypeLibrary::dependency_name.
Sourcepub fn set_name(&self, value: &str)
pub fn set_name(&self, value: &str)
Sets the name of a type library that has not been finalized.
Sourcepub fn dependency_name(&self) -> String
pub fn dependency_name(&self) -> String
The dependency_name of a library is the name used to record dependencies across
type libraries. This allows, for example, a library with the name “musl_libc” to have
dependencies on it recorded as “libc_generic”, allowing a type library to be used across
multiple platforms where each has a specific libc that also provides the name “libc_generic”
as an alternate_name.
Sourcepub fn set_dependency_name(&self, value: &str)
pub fn set_dependency_name(&self, value: &str)
Sets the dependency name of a type library instance that has not been finalized
Sourcepub fn set_guid(&self, value: &str)
pub fn set_guid(&self, value: &str)
Sets the GUID of a type library instance that has not been finalized.
Sourcepub fn alternate_names(&self) -> Array<BnString>
pub fn alternate_names(&self) -> Array<BnString>
A list of extra names that will be considered a match by Platform::get_type_libraries_by_name
Sourcepub fn add_alternate_name(&self, value: &str)
pub fn add_alternate_name(&self, value: &str)
Adds an extra name to this type library used during library lookups and dependency resolution
Sourcepub fn platform_names(&self) -> Array<BnString>
pub fn platform_names(&self) -> Array<BnString>
Returns a list of all platform names that this type library will register with during platform type registration.
Because type libraries can be distributed with platforms that do not exist, we return the names.
Sourcepub fn add_platform(&self, plat: &Platform)
pub fn add_platform(&self, plat: &Platform)
Associate a platform with a type library instance that has not been finalized.
This will cause the library to be searchable by Platform::get_type_libraries_by_name
when loaded.
This does not have side effects until finalization of the type library.
Sourcepub fn clear_platforms(&self)
pub fn clear_platforms(&self)
Clears the list of platforms associated with a type library instance that has not been finalized.
Sourcepub fn finalize(&self) -> bool
pub fn finalize(&self) -> bool
Flags a newly created type library instance as finalized and makes it available for Platform and Architecture type library searches.
Sourcepub fn register(&self)
pub fn register(&self)
Make a created or loaded Type Library available for Platforms to use when loading binaries.
Sourcepub fn query_metadata(&self, key: &str) -> Option<Ref<Metadata>>
pub fn query_metadata(&self, key: &str) -> Option<Ref<Metadata>>
Retrieves the metadata associated with the given key stored in the type library.
Sourcepub fn store_metadata(&self, key: &str, md: &Metadata)
pub fn store_metadata(&self, key: &str, md: &Metadata)
Stores a Metadata object in the given key for the type library.
This is primarily intended as a way to store Platform specific information relevant to BinaryView implementations; for example, the PE BinaryViewType uses type library metadata to retrieve ordinal information, when available.
Sourcepub fn remove_metadata(&self, key: &str)
pub fn remove_metadata(&self, key: &str)
Removes the metadata associated with key from the type library.
Sourcepub fn metadata(&self) -> Ref<Metadata>
pub fn metadata(&self) -> Ref<Metadata>
Retrieves the metadata associated with the type library.
pub fn type_container(&self) -> TypeContainer
Sourcepub fn add_named_object(&self, name: QualifiedName, type_: &Type)
pub fn add_named_object(&self, name: QualifiedName, type_: &Type)
Directly inserts a named object into the type library’s object store.
Referenced types will not automatically be added, so make sure to add referenced types to the
library or use TypeLibrary::add_type_source to mark the references originating source.
To add objects from a binary view, prefer using BinaryViewExt::export_object_to_library which
will automatically pull in all referenced types and record additional dependencies as needed.
pub fn remove_named_object(&self, name: QualifiedName)
Sourcepub fn add_named_type(&self, name: QualifiedName, type_: &Type)
pub fn add_named_type(&self, name: QualifiedName, type_: &Type)
Directly inserts a named type into the type library’s type store.
Referenced types will not automatically be added, so make sure to add referenced types to the
library or use TypeLibrary::add_type_source to mark the references originating source.
To add types from a binary view, prefer using BinaryViewExt::export_type_to_library which
will automatically pull in all referenced types and record additional dependencies as needed.
pub fn remove_named_type(&self, name: QualifiedName)
Sourcepub fn add_type_source(&self, name: QualifiedName, source: &str)
pub fn add_type_source(&self, name: QualifiedName, source: &str)
Flag any outgoing named type reference with the given name as belonging to the source type library.
This allows type libraries to share types between them, automatically pulling in dependencies into the binary view as needed.
Sourcepub fn get_named_type_source(&self, name: QualifiedName) -> Option<String>
pub fn get_named_type_source(&self, name: QualifiedName) -> Option<String>
Retrieve the source type library associated with the given named type, if any.
Sourcepub fn get_named_object(&self, name: QualifiedName) -> Option<Ref<Type>>
pub fn get_named_object(&self, name: QualifiedName) -> Option<Ref<Type>>
Get the object (function) associated with the given name, if any.
Prefer BinaryViewExt::import_type_library_object as it will recursively import types required.
Sourcepub fn get_named_type(&self, name: QualifiedName) -> Option<Ref<Type>>
pub fn get_named_type(&self, name: QualifiedName) -> Option<Ref<Type>>
Get the type associated with the given name, if any.
Prefer BinaryViewExt::import_type_library_type as it will recursively import types required.
Sourcepub fn named_objects(&self) -> Array<QualifiedNameAndType>
pub fn named_objects(&self) -> Array<QualifiedNameAndType>
The list of all named objects provided by a type library
Sourcepub fn named_types(&self) -> Array<QualifiedNameAndType>
pub fn named_types(&self) -> Array<QualifiedNameAndType>
The list of all named types provided by a type library