Loading...
Searching...
No Matches
BinaryNinja::TypeLibrary Class Reference

Public Member Functions

 TypeLibrary (BNTypeLibrary *handle)
 
 TypeLibrary (Ref< Architecture > arch, const std::string &name)
 Creates an empty type library object with a random GUID and the provided name.
 
std::string Decompress (const std::string &path)
 Decompresses a type library from a file.
 
bool WriteToFile (const std::string &path)
 Saves a finalized type library instance to file.
 
Ref< ArchitectureGetArchitecture ()
 The Architecture this type library is associated with.
 
std::string GetGuid ()
 Returns the GUID associated with the type library.
 
std::string GetName ()
 The primary name associated with this type library.
 
std::set< std::string > GetAlternateNames ()
 A list of extra names that will be considered a match by ``Platform::GetTypeLibrariesByName``.
 
std::string GetDependencyName ()
 The dependency name of a library is the name used to record dependencies across type libraries.
 
std::set< std::string > GetPlatformNames ()
 Returns a list of all platform names that this type library will register with during platform type registration.
 
Ref< MetadataQueryMetadata (const std::string &key)
 Retrieves a metadata associated with the given key stored in the type library.
 
void SetGuid (const std::string &guid)
 Sets the GUID of a type library instance that has not been finalized.
 
TypeContainer GetTypeContainer ()
 Type Container for all TYPES within the Type Library.
 
Ref< TypeGetNamedObject (const QualifiedName &name)
 Direct extracts a reference to a contained object – when attempting to extract types from a library into a BinaryView, consider using BinaryView::ImportTypeLibraryObject instead.
 
Ref< TypeGetNamedType (const QualifiedName &name)
 Direct extracts a reference to a contained type – when attempting to extract types from a library into a BinaryView, consider using BinaryView.ImportTypeLibraryType>` instead.
 
std::vector< QualifiedNameAndTypeGetNamedObjects ()
 A list containing all named objects (functions, exported variables) provided by a type library.
 
std::vector< QualifiedNameAndTypeGetNamedTypes ()
 A list containing all named types provided by a type library.
 
void SetName (const std::string &name)
 Sets the name of a type library instance that has not been finalized.
 
void AddAlternateName (const std::string &alternate)
 Adds an extra name to this type library used during library lookups and dependency resolution.
 
void SetDependencyName (const std::string &depName)
 Sets the dependency name of a type library instance that has not been finalized.
 
void ClearPlatforms ()
 Clears the list of platforms associated with a type library instance that has not been finalized.
 
void AddPlatform (Ref< Platform > platform)
 Associate a platform with a type library instance that has not been finalized.
 
void StoreMetadata (const std::string &key, Ref< Metadata > value)
 Stores an object for the given key in the current type library.
 
void RemoveMetadata (const std::string &key)
 Removes the metadata associated with key from the current type library.
 
Ref< MetadataGetMetadata ()
 Returns a base Metadata object associated with the current type library.
 
void AddNamedObject (const QualifiedName &name, Ref< Type > type)
 Directly inserts a named object into the type library's object store.
 
void AddNamedType (const QualifiedName &name, Ref< Type > type)
 Directly inserts a named object into the type library's object store.
 
void AddNamedTypeSource (const QualifiedName &name, const std::string &source)
 Manually flag NamedTypeReferences to the given QualifiedName as originating from another source TypeLibrary with the given dependency name.
 
void Finalize ()
 Flags a newly created type library instance as finalized and makes it available for Platform and Architecture type library searches.
 
- Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNTypeLibrary, BNNewTypeLibraryReference, BNFreeTypeLibrary >
 CoreRefCountObject ()
 
virtual ~CoreRefCountObject ()
 
BNTypeLibraryGetObject () const
 
void AddRef ()
 
void Release ()
 
void AddRefForRegistration ()
 
void ReleaseForRegistration ()
 
void AddRefForCallback ()
 
void ReleaseForCallback ()
 

Static Public Member Functions

static bool DecompressToFile (const std::string &path, const std::string &output)
 Decompresses a type library from a file.
 
static Ref< TypeLibraryLoadFromFile (const std::string &path)
 Loads a finalized type library instance from file.
 
static Ref< TypeLibraryLookupByName (Ref< Architecture > arch, const std::string &name)
 Looks up the first type library found with a matching name.
 
static Ref< TypeLibraryLookupByGuid (Ref< Architecture > arch, const std::string &guid)
 Attempts to grab a type library associated with the provided Architecture and GUID pair.
 
- Static Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNTypeLibrary, BNNewTypeLibraryReference, BNFreeTypeLibrary >
static BNTypeLibraryGetObject (CoreRefCountObject *obj)
 
static BNTypeLibraryGetObject (const CoreRefCountObject *obj)
 

Additional Inherited Members

- Public Attributes inherited from BinaryNinja::CoreRefCountObject< BNTypeLibrary, BNNewTypeLibraryReference, BNFreeTypeLibrary >
std::atomic< int > m_refs
 
bool m_registeredRef
 
BNTypeLibrarym_object
 

Constructor & Destructor Documentation

◆ TypeLibrary() [1/2]

TypeLibrary::TypeLibrary ( BNTypeLibrary * handle)

◆ TypeLibrary() [2/2]

TypeLibrary::TypeLibrary ( Ref< Architecture > arch,
const std::string & name )

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

Parameters
arch
name

Member Function Documentation

◆ Decompress()

std::string BinaryNinja::TypeLibrary::Decompress ( const std::string & path)

Decompresses a type library from a file.

Parameters
path
Returns
The string contents of the decompressed type library

◆ DecompressToFile()

bool TypeLibrary::DecompressToFile ( const std::string & path,
const std::string & output )
static

Decompresses a type library from a file.

Parameters
path
output
Returns
True if the type library was successfully decompressed

◆ LoadFromFile()

Ref< TypeLibrary > TypeLibrary::LoadFromFile ( const std::string & path)
static

Loads a finalized type library instance from file.

Parameters
path
Returns
True if the type library was successfully loaded

◆ LookupByName()

Ref< TypeLibrary > TypeLibrary::LookupByName ( Ref< Architecture > arch,
const std::string & name )
static

Looks up the first type library found with a matching name.

Keep in mind that names are not necessarily unique.

Parameters
arch
name
Returns

◆ LookupByGuid()

Ref< TypeLibrary > TypeLibrary::LookupByGuid ( Ref< Architecture > arch,
const std::string & guid )
static

Attempts to grab a type library associated with the provided Architecture and GUID pair.

Parameters
arch
guid
Returns

◆ WriteToFile()

bool TypeLibrary::WriteToFile ( const std::string & path)

Saves a finalized type library instance to file.

Parameters
path

◆ GetArchitecture()

Ref< Architecture > TypeLibrary::GetArchitecture ( )

The Architecture this type library is associated with.

Returns

◆ GetGuid()

std::string TypeLibrary::GetGuid ( )

Returns the GUID associated with the type library.

Returns

◆ GetName()

std::string TypeLibrary::GetName ( )

The primary name associated with this type library.

Returns

◆ GetAlternateNames()

std::set< std::string > TypeLibrary::GetAlternateNames ( )

A list of extra names that will be considered a match by ``Platform::GetTypeLibrariesByName``.

Returns

◆ GetDependencyName()

std::string TypeLibrary::GetDependencyName ( )

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`.

Returns

◆ GetPlatformNames()

std::set< std::string > TypeLibrary::GetPlatformNames ( )

Returns a list of all platform names that this type library will register with during platform type registration.

This returns strings, not Platform objects, as type libraries can be distributed with support for Platforms that may not be present.

Returns

◆ QueryMetadata()

Ref< Metadata > TypeLibrary::QueryMetadata ( const std::string & key)

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

Parameters
keyKey to query
Returns
Metadata associated with the key

◆ SetGuid()

void TypeLibrary::SetGuid ( const std::string & guid)

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

Parameters
guid

◆ GetTypeContainer()

TypeContainer TypeLibrary::GetTypeContainer ( )

Type Container for all TYPES within the Type Library.

Objects are not included. The Type Container's Platform will be the first platform associated with the Type Library.

Returns
Type Library Type Container

◆ GetNamedObject()

Ref< Type > TypeLibrary::GetNamedObject ( const QualifiedName & name)

Direct extracts a reference to a contained object – when attempting to extract types from a library into a BinaryView, consider using BinaryView::ImportTypeLibraryObject instead.

Parameters
name
Returns

◆ GetNamedType()

Ref< Type > TypeLibrary::GetNamedType ( const QualifiedName & name)

Direct extracts a reference to a contained type – when attempting to extract types from a library into a BinaryView, consider using BinaryView.ImportTypeLibraryType>` instead.

Parameters
name
Returns

◆ GetNamedObjects()

std::vector< QualifiedNameAndType > TypeLibrary::GetNamedObjects ( )

A list containing all named objects (functions, exported variables) provided by a type library.

Returns

◆ GetNamedTypes()

std::vector< QualifiedNameAndType > TypeLibrary::GetNamedTypes ( )

A list containing all named types provided by a type library.

Returns

◆ SetName()

void TypeLibrary::SetName ( const std::string & name)

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

Parameters
name

◆ AddAlternateName()

void TypeLibrary::AddAlternateName ( const std::string & alternate)

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

Parameters
alternate

◆ SetDependencyName()

void TypeLibrary::SetDependencyName ( const std::string & depName)

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

Parameters
depName

◆ ClearPlatforms()

void TypeLibrary::ClearPlatforms ( )

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

◆ AddPlatform()

void TypeLibrary::AddPlatform ( Ref< Platform > platform)

Associate a platform with a type library instance that has not been finalized.

This will cause the library to be searchable by Platform::GetTypeLibrariesByName when loaded.

This does not have side affects until finalization of the type library.

Parameters
platform

◆ StoreMetadata()

void TypeLibrary::StoreMetadata ( const std::string & key,
Ref< Metadata > value )

Stores an object for the given key in the current type library.

Objects stored using StoreMetadata can be retrieved from any reference to the 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.

Parameters
keyKey value to associate the Metadata object with
valueObject to store.

◆ RemoveMetadata()

void TypeLibrary::RemoveMetadata ( const std::string & key)

Removes the metadata associated with key from the current type library.

Parameters
keyKey associated with metadata

◆ GetMetadata()

Ref< Metadata > TypeLibrary::GetMetadata ( )

Returns a base Metadata object associated with the current type library.

Returns
Metadata object associated with the type library

◆ AddNamedObject()

void TypeLibrary::AddNamedObject ( const QualifiedName & name,
Ref< Type > type )

Directly inserts a named object into the type library's object store.

This is not done recursively, so care should be taken that types referring to other types through NamedTypeReferences are already appropriately prepared.

To add types and objects from an existing BinaryView, it is recommended to use BinaryView::ExportObjectToLibrary, which will automatically pull in all referenced types and record additional dependencies as needed.

Parameters
name
type

◆ AddNamedType()

void TypeLibrary::AddNamedType ( const QualifiedName & name,
Ref< Type > type )

Directly inserts a named object into the type library's object store.

This is not done recursively, so care should be taken that types referring to other types through NamedTypeReferences are already appropriately prepared.

To add types and objects from an existing BinaryView, it is recommended to use BinaryView::ExportTypeToLibrary, which will automatically pull in all referenced types and record additional dependencies as needed.

Parameters
name
type

◆ AddNamedTypeSource()

void TypeLibrary::AddNamedTypeSource ( const QualifiedName & name,
const std::string & source )

Manually flag NamedTypeReferences to the given QualifiedName as originating from another source TypeLibrary with the given dependency name.

Warning
Use this api with extreme caution.
Parameters
name
source

◆ Finalize()

void TypeLibrary::Finalize ( )

Flags a newly created type library instance as finalized and makes it available for Platform and Architecture type library searches.