C++

The original Doxygen documentation is also available here

Error Handling

template<typename T>
using LIEF::result = tl::expected<T, lief_errors>

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

The tl/expected 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://tl.tartanllama.xyz/en/latest/api/expected.html 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

Iterators

template<class T, typename U = typename decay_t<T>::value_type, class ITERATOR_T = typename decay_t<T>::iterator>
class 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 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)

void LIEF::logging::set_path(const std::string &path)

Change the logger as a file-base logging and set its path.

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