LIEF: Library to Instrument Executable Formats
Version 1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
errors.hpp
Go to the documentation of this file.
1
/* Copyright 2021 - 2026 R. Thomas
2
* Copyright 2021 - 2026 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 <string>
20
#include <
LIEF/compiler_attributes.hpp
>
21
#include <LIEF/third-party/expected.hpp>
22
24
enum class
lief_errors
: uint32_t {
25
read_error
= 1,
26
not_found
,
27
not_implemented
,
28
not_supported
,
29
30
corrupted
,
31
conversion_error
,
32
33
read_out_of_bound
,
34
asn1_bad_tag
,
35
file_error
,
36
37
file_format_error
,
38
parsing_error
,
39
build_error
,
40
41
data_too_large
,
42
require_extended_version
,
43
inconsistent
,
44
runtime_error
,
45
/*
46
* When adding a new error, do not forget
47
* to update the Python bindings as well (pyErr.cpp) and Rust bindings:
48
* lief/src/error.rs
49
*/
50
};
51
52
const
char
*
to_string
(
lief_errors
err);
53
55
inline
tl::unexpected<lief_errors>
make_error_code
(
lief_errors
e) {
56
return
tl::make_unexpected(e);
57
}
58
59
60
namespace
LIEF
{
78
template
<
typename
T>
79
class
LIEF_MAYBE_UNUSED
result
:
public
tl::expected<T, lief_errors> {
80
public
:
81
using
ExpectedType
= T;
82
using
tl::expected<T,
lief_errors
>::expected;
83
result
(tl::expected<T, lief_errors> e) :
84
tl::expected<T,
lief_errors
>::expected(std::move(e)) {}
85
};
86
88
template
<
class
T>
89
lief_errors
get_error
(
result<T>
& err) {
90
return
err.error();
91
}
92
94
template
<
class
T>
95
lief_errors
as_lief_err
(
result<T>
& err) {
96
return
err.error();
97
}
98
100
struct
ok_t
{};
101
103
inline
ok_t
ok
() {
104
return
ok_t
{};
105
}
106
119
class
LIEF_MAYBE_UNUSED
ok_error_t
:
public
result
<ok_t> {
120
public
:
121
using
result
<
ok_t
>
::result
;
122
};
123
124
inline
bool
is_ok
(
const
ok_error_t
& val) {
125
return
val.has_value();
126
}
127
128
inline
bool
is_err
(
const
ok_error_t
& val) {
129
return
!
is_ok
(val);
130
}
131
132
}
133
134
extern
template
class
tl::expected<LIEF::ok_t, lief_errors>;
135
extern
template
class
LIEF::result<LIEF::ok_t>
;
136
extern
template
class
tl::expected<uint64_t, lief_errors>;
137
extern
template
class
LIEF::result<uint64_t>
;
138
extern
template
class
tl::expected<uint32_t, lief_errors>;
139
extern
template
class
LIEF::result<uint32_t>
;
140
extern
template
class
tl::expected<std::string, lief_errors>;
141
extern
template
class
LIEF::result<std::string>
;
142
143
#endif
LIEF::ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition
errors.hpp:119
LIEF::result
Wrapper that contains an Object (T) or an error.
Definition
errors.hpp:79
LIEF::result::result
result(tl::expected< T, lief_errors > e)
Definition
errors.hpp:83
LIEF::result::ExpectedType
T ExpectedType
Definition
errors.hpp:81
compiler_attributes.hpp
LIEF_MAYBE_UNUSED
#define LIEF_MAYBE_UNUSED
Definition
compiler_attributes.hpp:62
lief_errors
lief_errors
LIEF error codes definition.
Definition
errors.hpp:24
lief_errors::require_extended_version
@ require_extended_version
Definition
errors.hpp:42
lief_errors::file_format_error
@ file_format_error
Definition
errors.hpp:37
lief_errors::data_too_large
@ data_too_large
Definition
errors.hpp:41
lief_errors::read_out_of_bound
@ read_out_of_bound
Definition
errors.hpp:33
lief_errors::conversion_error
@ conversion_error
Definition
errors.hpp:31
lief_errors::build_error
@ build_error
Definition
errors.hpp:39
lief_errors::runtime_error
@ runtime_error
Definition
errors.hpp:44
lief_errors::not_implemented
@ not_implemented
Definition
errors.hpp:27
lief_errors::not_found
@ not_found
Definition
errors.hpp:26
lief_errors::corrupted
@ corrupted
Definition
errors.hpp:30
lief_errors::asn1_bad_tag
@ asn1_bad_tag
Definition
errors.hpp:34
lief_errors::not_supported
@ not_supported
Definition
errors.hpp:28
lief_errors::read_error
@ read_error
Definition
errors.hpp:25
lief_errors::parsing_error
@ parsing_error
Definition
errors.hpp:38
lief_errors::inconsistent
@ inconsistent
Definition
errors.hpp:43
lief_errors::file_error
@ file_error
Definition
errors.hpp:35
make_error_code
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create a standard error code from lief_errors.
Definition
errors.hpp:55
to_string
const char * to_string(lief_errors err)
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:41
LIEF::is_ok
bool is_ok(const ok_error_t &val)
Definition
errors.hpp:124
LIEF::get_error
lief_errors get_error(result< T > &err)
Get the error code associated with the result.
Definition
errors.hpp:89
LIEF::ok
ok_t ok()
Return success for function with return type ok_error_t.
Definition
errors.hpp:103
LIEF::is_err
bool is_err(const ok_error_t &val)
Definition
errors.hpp:128
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:95
LIEF::ok_t
Opaque structure used by ok_error_t.
Definition
errors.hpp:100
Generated by
1.17.0