LIEF: Library to Instrument Executable Formats
Version 1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
install
linux
x86_64
sdk
static
include
LIEF
runtime
runtime/utils.hpp
Go to the documentation of this file.
1
/* Copyright 2017 - 2026 R. Thomas
2
* Copyright 2017 - 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_RUNTIME_UTILS_H
17
#define LIEF_RUNTIME_UTILS_H
18
#include <cstdint>
19
#include "
LIEF/config.h
"
20
21
#if defined(LIEF_RUNTIME_SUPPORT)
22
#include "LIEF/runtime/config.h"
23
#endif
24
25
namespace
LIEF
{
26
namespace
runtime
{
27
28
enum class
PLATFORMS
: uint32_t {
29
NONE
= 0,
30
LINUX
,
31
WINDOWS
,
32
ANDROID_
,
33
OSX
,
34
IOS
,
35
};
36
37
enum class
ARCH
: uint32_t {
38
NONE
,
39
X86_64
,
40
ARM64
,
41
RISCV64
,
42
};
43
45
static
constexpr
bool
is_enabled() {
46
return
lief_runtime_support;
47
}
48
50
static
constexpr
PLATFORMS
platform() {
51
#if !defined(LIEF_RUNTIME_SUPPORT)
52
return
PLATFORMS::NONE
;
53
#else
54
#if defined(LIEF_RUNTIME_PLATFORM_LINUX)
55
return
PLATFORMS::LINUX
;
56
#elif defined(LIEF_RUNTIME_PLATFORM_WINDOWS)
57
return
PLATFORMS::WINDOWS
;
58
#elif defined(LIEF_RUNTIME_PLATFORM_ANDROID)
59
return
PLATFORMS::ANDROID_
;
60
#elif defined(LIEF_RUNTIME_PLATFORM_OSX)
61
return
PLATFORMS::OSX
;
62
#elif defined(LIEF_RUNTIME_PLATFORM_IOS)
63
return
PLATFORMS::IOS
;
64
#else
65
return
PLATFORMS::NONE
;
66
#endif
67
#endif
68
}
69
71
static
constexpr
ARCH
arch() {
72
#if !defined(LIEF_RUNTIME_SUPPORT)
73
return
ARCH::NONE
;
74
#else
75
#if defined(LIEF_RUNTIME_ARCH_ARM64)
76
return
ARCH::ARM64
;
77
#elif defined(LIEF_RUNTIME_ARCH_X86_64)
78
return
ARCH::X86_64
;
79
#elif defined(LIEF_RUNTIME_ARCH_RISCV64)
80
return
ARCH::RISCV64
;
81
#else
82
return
ARCH::NONE
;
83
#endif
84
85
#endif
86
}
87
88
static
inline
constexpr
uintptr_t page_mask(uintptr_t page_size) {
89
return
~(page_size - 1);
90
}
91
92
static
inline
constexpr
uintptr_t page_start(uintptr_t address,
93
uintptr_t page_size) {
94
return
address & page_mask(page_size);
95
}
96
97
static
inline
constexpr
uintptr_t page_align(uintptr_t address,
98
uintptr_t page_size) {
99
return
(address + (page_size - 1)) & page_mask(page_size);
100
}
101
102
static
inline
constexpr
uintptr_t page_offset(uintptr_t address,
103
uintptr_t page_size) {
104
return
(address & ~page_mask(page_size));
105
}
106
107
static
inline
constexpr
uintptr_t page_end(uintptr_t address,
108
uintptr_t page_size) {
109
return
page_start(address + (page_size - 1), page_size);
110
}
111
112
}
113
}
114
#endif
config.h
LIEF::runtime
Definition
android/Host.hpp:24
LIEF::runtime::ARCH
ARCH
Definition
runtime/utils.hpp:37
LIEF::runtime::ARCH::X86_64
@ X86_64
Definition
runtime/utils.hpp:39
LIEF::runtime::ARCH::RISCV64
@ RISCV64
Definition
runtime/utils.hpp:41
LIEF::runtime::ARCH::NONE
@ NONE
Definition
runtime/utils.hpp:38
LIEF::runtime::ARCH::ARM64
@ ARM64
Definition
runtime/utils.hpp:40
LIEF::runtime::PLATFORMS
PLATFORMS
Definition
runtime/utils.hpp:28
LIEF::runtime::PLATFORMS::OSX
@ OSX
Definition
runtime/utils.hpp:33
LIEF::runtime::PLATFORMS::NONE
@ NONE
Definition
runtime/utils.hpp:29
LIEF::runtime::PLATFORMS::IOS
@ IOS
Definition
runtime/utils.hpp:34
LIEF::runtime::PLATFORMS::WINDOWS
@ WINDOWS
Definition
runtime/utils.hpp:31
LIEF::runtime::PLATFORMS::LINUX
@ LINUX
Definition
runtime/utils.hpp:30
LIEF::runtime::PLATFORMS::ANDROID_
@ ANDROID_
Definition
runtime/utils.hpp:32
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:41
Generated by
1.18.0