TypeLibrary

Struct TypeLibrary 

Source
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

Source

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.

Source

pub fn new(arch: CoreArchitecture, name: &str) -> Ref<TypeLibrary>

Creates an empty type library object with a random GUID and the provided name.

Source

pub fn all(arch: CoreArchitecture) -> Array<TypeLibrary>

Source

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.

Source

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.

Source

pub fn decompress_to_file(&self, output_path: &Path) -> bool

Decompresses the type library file to a JSON file at the given output_path.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_name(&self, value: &str)

Sets the name of a type library that has not been finalized.

Source

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.

Source

pub fn set_dependency_name(&self, value: &str)

Sets the dependency name of a type library instance that has not been finalized

Source

pub fn guid(&self) -> String

Returns the GUID associated with the type library

Source

pub fn set_guid(&self, value: &str)

Sets the GUID of a type library instance that has not been finalized.

Source

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

Source

pub fn add_alternate_name(&self, value: &str)

Adds an extra name to this type library used during library lookups and dependency resolution

Source

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.

Source

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.

Source

pub fn clear_platforms(&self)

Clears the list of platforms associated with a type library instance that has not been finalized.

Source

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.

Source

pub fn register(&self)

Make a created or loaded Type Library available for Platforms to use when loading binaries.

Source

pub fn query_metadata(&self, key: &str) -> Option<Ref<Metadata>>

Retrieves the metadata associated with the given key stored in the type library.

Source

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.

Source

pub fn remove_metadata(&self, key: &str)

Removes the metadata associated with key from the type library.

Source

pub fn metadata(&self) -> Ref<Metadata>

Retrieves the metadata associated with the type library.

Source

pub fn type_container(&self) -> TypeContainer

Source

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.

Source

pub fn remove_named_object(&self, name: QualifiedName)

Source

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.

Source

pub fn remove_named_type(&self, name: QualifiedName)

Source

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.

Source

pub fn get_named_type_source(&self, name: QualifiedName) -> Option<String>

Retrieve the source type library associated with the given named type, if any.

Source

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.

Source

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.

Source

pub fn named_objects(&self) -> Array<QualifiedNameAndType>

The list of all named objects provided by a type library

Source

pub fn named_types(&self) -> Array<QualifiedNameAndType>

The list of all named types provided by a type library

Trait Implementations§

Source§

impl CoreArrayProvider for TypeLibrary

Source§

impl Debug for TypeLibrary

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for TypeLibrary

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TypeLibrary

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToOwned for TypeLibrary

Source§

type Owned = Ref<TypeLibrary>

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl Eq for TypeLibrary

Source§

impl Send for TypeLibrary

Source§

impl Sync for TypeLibrary

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more