VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
RelativeAddress.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstddef>
4
#include <cstdint>
5
6
namespace
VoltMod
7
{
8
9
/**
10
* @file RelativeAddress.hpp
11
* @brief Checked rel32 decoding for signature bindings.
12
*
13
* The displacement starts at `match + ripOffset` and is relative to the end of the instruction.
14
* Keeping the arithmetic pure makes malformed offsets testable without reading process memory.
15
*/
16
17
inline
constexpr
int
Rel32Size
= 4;
18
19
constexpr
uintptr_t
Rel32Site
(
uintptr_t
matchAddress
,
int
ripOffset
)
noexcept
20
{
21
return
matchAddress
+
static_cast<
uintptr_t
>
(
ripOffset
);
22
}
23
24
/**
25
* Resolve @p displacement from @p site. @p ripSize is the distance from the site to the end of the
26
* instruction and defaults to the four-byte displacement width.
27
*/
28
constexpr
uintptr_t
Rel32Target
(
uintptr_t
site
,
int32_t
displacement
,
int
ripSize
=
Rel32Size
)
noexcept
29
{
30
return
site
+
static_cast<
uintptr_t
>
(
ripSize
) +
static_cast<
uintptr_t
>
(
static_cast<
intptr_t
>
(
displacement
));
31
}
32
33
/**
34
* Whether the four-byte displacement at `matchAddress + ripOffset` fits entirely within the
35
* mapped image. Invalid and overflowing offsets return false before any read occurs.
36
*/
37
constexpr
bool
Rel32ReadInBounds
(
uintptr_t
moduleBase
,
size_t
moduleSize
,
uintptr_t
matchAddress
,
38
int
ripOffset
)
noexcept
39
{
40
if
(
ripOffset
< 0 ||
matchAddress
<
moduleBase
)
41
{
42
return
false
;
43
}
44
45
const
uintptr_t
moduleEnd
=
moduleBase
+
moduleSize
;
46
const
uintptr_t
site
=
Rel32Site
(
matchAddress
,
ripOffset
);
47
if
(
site < matchAddress || site >
=
moduleEnd
)
48
{
49
return
false
;
50
}
51
52
return
moduleEnd
-
site
>=
static_cast<
uintptr_t
>
(
Rel32Size
);
53
}
54
55
}
// namespace VoltMod
VoltMod
Definition
Options.hpp:13
VoltMod::ReadFile
static std::string ReadFile(const std::filesystem::path &path)
Definition
Loader.cpp:56
VoltMod::Rel32ReadInBounds
constexpr bool Rel32ReadInBounds(uintptr_t moduleBase, size_t moduleSize, uintptr_t matchAddress, int ripOffset) noexcept
Definition
RelativeAddress.hpp:37
VoltMod::Rel32Size
constexpr int Rel32Size
Definition
RelativeAddress.hpp:17
VoltMod::Rel32Target
constexpr uintptr_t Rel32Target(uintptr_t site, int32_t displacement, int ripSize=Rel32Size) noexcept
Definition
RelativeAddress.hpp:28
VoltMod::Rel32Site
constexpr uintptr_t Rel32Site(uintptr_t matchAddress, int ripOffset) noexcept
Definition
RelativeAddress.hpp:19
src
Engine
Memory
RelativeAddress.hpp
Generated by
1.9.8