C++

Note

You can also find the Doxygen documentation here: here

Metadata

class Metadata

This class is the main interface to inspect Objective-C metadata.

It can be instantiated using the function LIEF::MachO::Binary::objc_metadata

Public Types

using classes_it = iterator_range<Class::Iterator>
using protocols_it = iterator_range<Protocol::Iterator>
using categories_it = iterator_range<Category::Iterator>

Public Functions

Metadata(std::unique_ptr<details::Metadata> impl)
classes_it classes() const

Return an iterator over the different Objective-C classes (@interface).

protocols_it protocols() const

Return an iterator over the Objective-C protocols declared in this binary (@protocol).

categories_it categories() const

Return an iterator over the Objective-C categories declared in this binary (e.g. @interface NSString (MyAdditions)).

std::unique_ptr<Class> get_class(const std::string &name) const

Try to find the Objective-C class with the given mangled name.

std::unique_ptr<Protocol> get_protocol(const std::string &name) const

Try to find the Objective-C protocol with the given mangled name.

std::string to_decl(const DeclOpt &opt = DeclOpt()) const

Generate a header-like of all the Objective-C metadata identified in the binary. The generated output can be configured with the DeclOpt.

~Metadata()

Class

class Class

This class represents an Objective-C class (@interface).

Public Types

using methods_t = iterator_range<Method::Iterator>

Iterator for the class’s methods.

using protocols_t = iterator_range<Protocol::Iterator>

Iterator for the protocols implemented by this class.

using properties_t = iterator_range<Property::Iterator>

Iterator for the properties declared by this class.

using ivars_t = iterator_range<IVar::Iterator>

Iterator for the instance variables defined by this class.

Public Functions

Class(std::unique_ptr<details::Class> impl)
std::string name() const

Name of the class.

std::string demangled_name() const

Demangled name of the class.

std::unique_ptr<Class> super_class() const

Parent class in case of inheritance.

This returns the superclass object only when it is defined in the same binary. For root classes (e.g. NSObject) or superclasses imported from another image, it returns a null pointer even though the name can still be resolved through super_name() / demangled_super_name().

std::string super_name() const

(raw) name of the superclass (empty for root classes or when it could not be resolved).

std::string demangled_super_name() const

Demangled name of the superclass.

bool is_meta() const
methods_t methods() const

Iterator over the different methods defined by this class.

protocols_t protocols() const

Iterator over the different protocols implemented by this class.

properties_t properties() const

Iterator over the properties of this class.

ivars_t ivars() const

Iterator over the different instance variables defined in this class.

std::string to_decl(const DeclOpt &opt = DeclOpt()) const

Generate a header-like string for this specific class.

The generated output can be configured with DeclOpt

~Class()
class Iterator : public LIEF::iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Class, std::ptrdiff_t, const Class*, const Class&>

Public Types

using implementation = details::ClassIt

Public Functions

Iterator()
Iterator(std::unique_ptr<details::ClassIt> impl)
Iterator(const Iterator&)
Iterator &operator=(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator &operator=(Iterator&&) noexcept
~Iterator()
Iterator &operator++()
Iterator &operator--()
const Class &operator*() const
const Class *operator->() const
std::unique_ptr<Class> yield()

Transfer ownership of the class at the current position to the caller. Returns nullptr if the iterator is past-the-end.

inline DerivedT operator++(int)
inline DerivedT operator--(int)

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)

Category

class Category

This class represents an Objective-C category (e.g. @interface NSString (MyAdditions)).

Public Types

using methods_t = iterator_range<Method::Iterator>

Iterator for the category’s methods.

using protocols_t = iterator_range<Protocol::Iterator>

Iterator for the protocols adopted by this category.

using properties_t = iterator_range<Property::Iterator>

Iterator for the properties declared by this category.

Public Functions

Category(std::unique_ptr<details::Category> impl)
std::string name() const

Name of the category.

std::string class_name() const

(demangled) name of the class extended by this category

methods_t methods() const

Iterator over the different methods defined by this category.

protocols_t protocols() const

Iterator over the different protocols adopted by this category.

properties_t properties() const

Iterator over the properties of this category.

std::string to_decl(const DeclOpt &opt = DeclOpt()) const

Generate a header-like string for this specific category.

The generated output can be configured with DeclOpt

~Category()
class Iterator : public LIEF::iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Category, std::ptrdiff_t, const Category*, const Category&>

Public Types

using implementation = details::CategoryIt

Public Functions

Iterator()
Iterator(std::unique_ptr<details::CategoryIt> impl)
Iterator(const Iterator&)
Iterator &operator=(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator &operator=(Iterator&&) noexcept
~Iterator()
Iterator &operator++()
Iterator &operator--()
const Category &operator*() const
const Category *operator->() const
std::unique_ptr<Category> yield()

Transfer ownership of the category at the current position to the caller. Returns nullptr if the iterator is past-the-end.

inline DerivedT operator++(int)
inline DerivedT operator--(int)

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)

Protocol

class Protocol

This class represents an Objective-C @protocol.

Public Types

using methods_it = iterator_range<Method::Iterator>
using properties_it = iterator_range<Property::Iterator>
using protocols_it = iterator_range<Iterator>

Public Functions

Protocol(std::unique_ptr<details::Protocol> impl)
std::string mangled_name() const

Mangled name of the protocol.

protocols_it protocols() const

Iterator over the protocols adopted by this protocol (e.g. the <Bar, Baz> in @protocol Foo <Bar, Baz>).

methods_it optional_methods() const

Iterator over the methods that could be overridden.

methods_it required_methods() const

Iterator over the methods of this protocol that must be implemented.

properties_it properties() const

Iterator over the properties defined in this protocol.

std::string to_decl(const DeclOpt &opt = DeclOpt()) const

Generate a header-like string for this specific protocol.

The generated output can be configured with DeclOpt

~Protocol()
class Iterator : public LIEF::iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Protocol, std::ptrdiff_t, const Protocol*, const Protocol&>

Public Types

using implementation = details::ProtocolIt

Public Functions

Iterator()
Iterator(std::unique_ptr<details::ProtocolIt> impl)
Iterator(const Iterator&)
Iterator &operator=(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator &operator=(Iterator&&) noexcept
~Iterator()
Iterator &operator++()
Iterator &operator--()
const Protocol &operator*() const
const Protocol *operator->() const
std::unique_ptr<Protocol> yield()

Transfer ownership of the protocol at the current position to the caller. Returns nullptr if the iterator is past-the-end.

inline DerivedT operator++(int)
inline DerivedT operator--(int)

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)

Instance Variable (IVar)

class IVar

This class represents an instance variable (ivar).

Public Functions

IVar(std::unique_ptr<details::IVar> impl)
std::string name() const

Name of the instance variable.

std::string mangled_type() const

Type of the instance var in its mangled representation ([29i]).

~IVar()
class Iterator : public LIEF::iterator_facade_base<Iterator, std::bidirectional_iterator_tag, IVar, std::ptrdiff_t, const IVar*, const IVar&>

Public Types

using implementation = details::IVarIt

Public Functions

Iterator()
Iterator(std::unique_ptr<details::IVarIt> impl)
Iterator(const Iterator&)
Iterator &operator=(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator &operator=(Iterator&&) noexcept
~Iterator()
Iterator &operator++()
Iterator &operator--()
const IVar &operator*() const
const IVar *operator->() const
std::unique_ptr<IVar> yield()

Transfer ownership of the ivar at the current position to the caller. Returns nullptr if the iterator is past-the-end.

inline DerivedT operator++(int)
inline DerivedT operator--(int)

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)

Method

class Method

This class represents an Objective-C Method.

Public Functions

Method(std::unique_ptr<details::Method> impl)
std::string name() const

Name of the method.

std::string mangled_type() const

Prototype of the method in its mangled representation (e.g. @16@0:8).

uintptr_t address() const

Virtual address where this method is implemented in the binary.

bool is_instance() const

Whether it’s an instance method.

~Method()
class Iterator : public LIEF::iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Method, std::ptrdiff_t, const Method*, const Method&>

Public Types

using implementation = details::MethodIt

Public Functions

Iterator()
Iterator(std::unique_ptr<details::MethodIt> impl)
Iterator(const Iterator&)
Iterator &operator=(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator &operator=(Iterator&&) noexcept
~Iterator()
Iterator &operator++()
Iterator &operator--()
const Method &operator*() const
const Method *operator->() const
std::unique_ptr<Method> yield()

Transfer ownership of the method at the current position to the caller. Returns nullptr if the iterator is past-the-end.

inline DerivedT operator++(int)
inline DerivedT operator--(int)

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)

Property

class Property

This class represents a @property in Objective-C.

Public Functions

Property(std::unique_ptr<details::Property> impl)
std::string name() const

Name of the property.

std::string attribute() const

(raw) property’s attributes (e.g. T@"NSString",C,D,N)

~Property()
class Iterator : public LIEF::iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Property, std::ptrdiff_t, const Property*, const Property&>

Public Types

using implementation = details::PropertyIt

Public Functions

Iterator()
Iterator(std::unique_ptr<details::PropertyIt> impl)
Iterator(const Iterator&)
Iterator &operator=(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator &operator=(Iterator&&) noexcept
~Iterator()
Iterator &operator++()
Iterator &operator--()
const Property &operator*() const
const Property *operator->() const
std::unique_ptr<Property> yield()

Transfer ownership of the property at the current position to the caller. Returns nullptr if the iterator is past-the-end.

inline DerivedT operator++(int)
inline DerivedT operator--(int)

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)

DeclOpt

struct DeclOpt

This structure wraps options to tweak the generated output of functions like LIEF::objc::Metadata::to_decl.

Public Members

bool show_annotations = true

Whether annotations like method’s address should be printed.