LIEF: Library to Instrument Executable Formats
Version 0.17.4
Toggle main menu visibility
Loading...
Searching...
No Matches
install
linux
x86_64
sdk
static
include
LIEF
errors.hpp
Go to the documentation of this file.
1
/* Copyright 2021 - 2025 R. Thomas
2
* Copyright 2021 - 2025 Quarkslab
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
#ifndef LIEF_ERROR_H
17
#define LIEF_ERROR_H
18
#include <cstdint>
19
#include <LIEF/third-party/expected.hpp>
20
#include <cstdint>
21
23
enum class
lief_errors
: uint32_t {
24
read_error
= 1,
25
not_found
,
26
not_implemented
,
27
not_supported
,
28
29
corrupted
,
30
conversion_error
,
31
32
read_out_of_bound
,
33
asn1_bad_tag
,
34
file_error
,
35
36
file_format_error
,
37
parsing_error
,
38
build_error
,
39
40
data_too_large
,
41
require_extended_version
42
/*
43
* When adding a new error, do not forget
44
* to update the Python bindings as well (pyErr.cpp) and Rust bindings:
45
* lief/src/error.rs
46
*/
47
};
48
49
const
char
*
to_string
(
lief_errors
err);
50
52
inline
tl::unexpected<lief_errors>
make_error_code
(
lief_errors
e) {
53
return
tl::make_unexpected(e);
54
}
55
56
57
namespace
LIEF
{
74
template
<
typename
T>
75
class
[[maybe_unused]]
result
:
public
tl::expected<T, lief_errors> {
76
public
:
77
using
tl::expected<T,
lief_errors
>::expected;
78
};
79
81
template
<
class
T>
82
lief_errors
get_error
(
result<T>
& err) {
83
return
err.error();
84
}
85
87
template
<
class
T>
88
lief_errors
as_lief_err
(
result<T>
& err) {
89
return
err.error();
90
}
91
93
struct
ok_t
{};
94
96
inline
ok_t
ok
() {
97
return
ok_t
{};
98
}
99
112
class
[[maybe_unused]]
ok_error_t
:
public
result
<ok_t> {
113
public
:
114
using
result
<
ok_t
>
::result
;
115
};
116
117
inline
bool
is_ok
(
const
ok_error_t
& val) {
118
return
val.has_value();
119
}
120
121
inline
bool
is_err
(
const
ok_error_t
& val) {
122
return
!
is_ok
(val);
123
}
124
125
}
126
127
128
129
130
131
#endif
LIEF::ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition
errors.hpp:112
LIEF::result
Wrapper that contains an Object (T) or an error.
Definition
errors.hpp:75
lief_errors
lief_errors
LIEF error codes definition.
Definition
errors.hpp:23
lief_errors::require_extended_version
@ require_extended_version
Definition
errors.hpp:41
lief_errors::file_format_error
@ file_format_error
Definition
errors.hpp:36
lief_errors::data_too_large
@ data_too_large
Definition
errors.hpp:40
lief_errors::read_out_of_bound
@ read_out_of_bound
Definition
errors.hpp:32
lief_errors::conversion_error
@ conversion_error
Definition
errors.hpp:30
lief_errors::build_error
@ build_error
Definition
errors.hpp:38
lief_errors::not_implemented
@ not_implemented
Definition
errors.hpp:26
lief_errors::not_found
@ not_found
Definition
errors.hpp:25
lief_errors::corrupted
@ corrupted
Definition
errors.hpp:29
lief_errors::asn1_bad_tag
@ asn1_bad_tag
Definition
errors.hpp:33
lief_errors::not_supported
@ not_supported
Definition
errors.hpp:27
lief_errors::read_error
@ read_error
Definition
errors.hpp:24
lief_errors::parsing_error
@ parsing_error
Definition
errors.hpp:37
lief_errors::file_error
@ file_error
Definition
errors.hpp:34
make_error_code
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create an standard error code from lief_errors.
Definition
errors.hpp:52
to_string
const char * to_string(lief_errors err)
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:40
LIEF::is_ok
bool is_ok(const ok_error_t &val)
Definition
errors.hpp:117
LIEF::get_error
lief_errors get_error(result< T > &err)
Get the error code associated with the result.
Definition
errors.hpp:82
LIEF::ok
ok_t ok()
Return success for function with return type ok_error_t.
Definition
errors.hpp:96
LIEF::is_err
bool is_err(const ok_error_t &val)
Definition
errors.hpp:121
LIEF::as_lief_err
lief_errors as_lief_err(result< T > &err)
Return the lief_errors when the provided result<T> is an error.
Definition
errors.hpp:88
LIEF::ok_t
Opaque structure used by ok_error_t.
Definition
errors.hpp:93
Generated by
1.17.0