C++

The original Doxygen documentation is also available here

Error Handling

template<typename T>
using LIEF::result = boost::leaf::result<T>

Wrapper that contains an Object (T) or an error.

The LEAF implementation exposes the method value() to access the underlying object (if no error)

Typical usage is:

result<int> intval = my_function();
if (intval) {
 int val = intval.value();
} else { // There is an error
 std::cout << get_error(intval).message() << "\n";
}

See https://boostorg.github.io/leaf/ for more details

template<class T>
lief_errors LIEF::as_lief_err(result<T> &err)

Return the lief_errors when the provided result<T> is an error.

enum class lief_errors

LIEF error codes definition.

Values:

enumerator read_error = 1
enumerator not_found
enumerator not_implemented
enumerator not_supported
enumerator corrupted
enumerator conversion_error
enumerator read_out_of_bound
enumerator asn1_bad_tag
enumerator file_error
enumerator file_format_error
enumerator parsing_error
enumerator build_error
enumerator data_too_large
using LIEF::ok_error_t = result<ok_t>

Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead, it makes the output explicit such as:

ok_error_t process() {
  if (fail) {
    return make_error_code(...);
  }
  return ok();
}

inline ok_t LIEF::ok()

Return success for function with return type ok_error_t.

struct ok_t

Opaque structure used by ok_error_t.

See also the section Error Handling

Exceptions

Warning

Exceptions will be progressively removed as explained in Error Handling

class LIEF::exception : public std::exception

Subclassed by LIEF::bad_file, LIEF::builder_error, LIEF::conversion_error, LIEF::corrupted, LIEF::integrity_error, LIEF::not_found, LIEF::not_implemented, LIEF::not_supported, LIEF::parser_error, LIEF::pe_error, LIEF::read_out_of_bound, LIEF::type_error

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
virtual ~exception() noexcept
class LIEF::bad_file : public LIEF::exception

Subclassed by LIEF::bad_format

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::bad_format : public LIEF::bad_file

Public Functions

const char *what() const noexcept override
class LIEF::not_implemented : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::not_supported : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::integrity_error : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::read_out_of_bound : public LIEF::exception

Public Functions

explicit read_out_of_bound(uint64_t offset, uint64_t size)
explicit read_out_of_bound(uint64_t offset)
exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::not_found : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::corrupted : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::conversion_error : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::type_error : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::builder_error : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::parser_error : public LIEF::exception

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::pe_error : public LIEF::exception

Subclassed by LIEF::pe_bad_section_name

Public Functions

exception(const exception &other)
explicit exception(std::string msg)
explicit exception(const char *msg)
const char *what() const noexcept override
class LIEF::pe_bad_section_name : public LIEF::pe_error

Public Functions

const char *what() const noexcept override

Iterators

template<class T, typename U = typename decay_t<T>::value_type, class ITERATOR_T = typename decay_t<T>::iterator>
class LIEF::ref_iterator

Iterator which returns reference on container’s values.

Public Types

using iterator_category = std::bidirectional_iterator_tag
using value_type = decay_t<U>
using difference_type = ptrdiff_t
using pointer = typename std::remove_pointer<U>::type*
using reference = typename std::remove_pointer<U>::type&
using container_type = T
using DT_VAL = U
using DT = decay_t<T>
using ref_t = typename ref_iterator::reference
using pointer_t = typename ref_iterator::pointer

Public Functions

inline ref_iterator(T container)
inline ref_iterator(const ref_iterator &copy)
inline ref_iterator operator=(ref_iterator other)
inline void swap(ref_iterator &other)
inline ref_iterator &operator++()
inline ref_iterator operator++(int)
inline ref_iterator &operator--()
inline ref_iterator operator--(int)
inline ref_iterator &operator+=(const typename ref_iterator::difference_type &movement)
inline ref_iterator &operator-=(const typename ref_iterator::difference_type &movement)
inline std::enable_if<!std::is_const<ref_t>::value, remove_const_t<ref_t>>::type operator[](size_t n)
inline add_const_t<ref_t> operator[](size_t n) const
inline ref_iterator operator+(typename ref_iterator::difference_type n) const
inline ref_iterator operator-(typename ref_iterator::difference_type n) const
inline ref_iterator::difference_type operator-(const ref_iterator &rhs) const
inline bool operator<(const ref_iterator &rhs) const
inline bool operator>(const ref_iterator &rhs) const
inline bool operator>=(const ref_iterator &rhs) const
inline bool operator<=(const ref_iterator &rhs) const
inline ref_iterator begin() const
inline ref_iterator cbegin() const
inline ref_iterator end() const
inline ref_iterator cend() const
inline bool operator==(const ref_iterator &other) const
inline bool operator!=(const ref_iterator &other) const
inline size_t size() const
inline bool empty() const
inline std::enable_if<!std::is_const<ref_t>::value, remove_const_t<ref_t>>::type operator*()
template<typename V = DT_VAL>
inline std::enable_if<std::is_pointer<V>::value, add_const_t<ref_t>>::type operator*() const
template<typename V = DT_VAL>
inline std::enable_if<!std::is_pointer<V>::value, add_const_t<ref_t>>::type operator*() const
inline std::enable_if<!std::is_const<pointer_t>::value, pointer_t>::type operator->()
inline add_const_t<pointer_t> operator->() const
template<class T, typename U = typename decay_t<T>::value_type, class CT = typename std::add_const<T>::type>
using LIEF::const_ref_iterator = ref_iterator<CT, U, typename decay_t<CT>::const_iterator>

Iterator which return const ref on container’s values.

template<class T, typename U = typename decay_t<T>::value_type, class ITERATOR_T = typename decay_t<T>::iterator>
class LIEF::filter_iterator

Iterator which return a ref on container’s values given predicates.

Public Types

using iterator_category = std::forward_iterator_tag
using value_type = decay_t<U>
using difference_type = ptrdiff_t
using pointer = typename std::remove_pointer<U>::type*
using reference = typename std::remove_pointer<U>::type&
using container_type = T
using DT_VAL = U
using DT = decay_t<T>
using ref_t = typename filter_iterator::reference
using pointer_t = typename filter_iterator::pointer
using filter_t = std::function<bool(const typename DT::value_type&)>

Public Functions

inline filter_iterator(T container, filter_t filter)
inline filter_iterator(T container, const std::vector<filter_t> &filters)
inline filter_iterator(T container)
inline filter_iterator(const filter_iterator &copy)
inline filter_iterator operator=(filter_iterator other)
inline void swap(filter_iterator &other)
inline filter_iterator &def(filter_t func)
inline filter_iterator &operator++()
inline filter_iterator operator++(int)
inline filter_iterator begin() const
inline filter_iterator cbegin() const
inline filter_iterator end() const
inline filter_iterator cend() const
inline std::enable_if<!std::is_const<ref_t>::value, remove_const_t<ref_t>>::type operator*()
template<typename V = DT_VAL>
inline std::enable_if<std::is_pointer<V>::value, add_const_t<ref_t>>::type operator*() const
template<typename V = DT_VAL>
inline std::enable_if<!std::is_pointer<V>::value, add_const_t<ref_t>>::type operator*() const
inline std::enable_if<!std::is_const<ref_t>::value, remove_const_t<ref_t>>::type operator[](size_t n)
inline add_const_t<ref_t> operator[](size_t n) const
inline std::enable_if<!std::is_const<pointer_t>::value, pointer_t>::type operator->()
inline add_const_t<pointer_t> operator->() const
inline size_t size() const
inline bool empty() const
inline bool operator==(const filter_iterator &other) const
inline bool operator!=(const filter_iterator &other) const
template<class T, typename U = typename decay_t<T>::value_type, class CT = typename std::add_const<T>::type>
using LIEF::const_filter_iterator = filter_iterator<CT, U, typename decay_t<CT>::const_iterator>

Iterator which return a const ref on container’s values given predicates.

Logging

void LIEF::logging::disable()

Globally disable the logging module.

void LIEF::logging::enable()

Globally enable the logging module.

void LIEF::logging::set_level(LOGGING_LEVEL level)

Change the logging level (hierarchical)

Logging levels

enum LIEF::logging::LOGGING_LEVEL

Hierarchical logging level

From a given level set, all levels below this level are enabled

For example, if LOG_INFO is enabled then LOG_WARN, LOG_ERR are also enabled

Values:

enumerator LOG_TRACE
enumerator LOG_DEBUG
enumerator LOG_INFO
enumerator LOG_WARN
enumerator LOG_ERR
enumerator LOG_CRITICAL