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
6namespace 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
17inline constexpr int Rel32Size = 4;
18
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 */
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 */
38 int ripOffset) noexcept
39{
41 {
42 return false;
43 }
44
48 {
49 return false;
50 }
51
52 return moduleEnd - site >= static_cast<uintptr_t>(Rel32Size);
53}
54
55} // namespace VoltMod
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
constexpr bool Rel32ReadInBounds(uintptr_t moduleBase, size_t moduleSize, uintptr_t matchAddress, int ripOffset) noexcept
constexpr int Rel32Size
constexpr uintptr_t Rel32Target(uintptr_t site, int32_t displacement, int ripSize=Rel32Size) noexcept
constexpr uintptr_t Rel32Site(uintptr_t matchAddress, int ripOffset) noexcept