CommonLib
Loading...
Searching...
No Matches
mem.h File Reference
#include <array>
#include <vector>
#include "ut/expr/string_expr.h"
#include "mem.inl"
#include "arch/mem_x86.inl"

Go to the source code of this file.

Classes

struct  hedgedev::csl::mem::branch_info

Namespaces

namespace  hedgedev
namespace  hedgedev::csl
namespace  hedgedev::csl::mem

Macros

#define ASLR(ADDRESS)
#define IS_NOP(ADDRESS)
#define READ(ADDRESS, TYPE)
#define READ_ARRAY(ADDRESS, TYPE, COUNT)
#define READ_INSTR_ADDRESS(ADDRESS, TYPE, OFFSET, STRIDE)
#define READ_CALL(ADDRESS)
#define READ_JUMP(ADDRESS)
#define WRITE(ADDRESS, TYPE, ...)
#define WRITE_ARRAY(ADDRESS, TYPE, DATA)
#define WRITE_CALL(ADDRESS, DESTINATION)
#define WRITE_JUMP(ADDRESS, DESTINATION)
#define WRITE_NOP(ADDRESS, COUNT)
#define WRITE_STRING(ADDRESS, STR)
#define WRITE_STRING_FIXED(ADDRESS, STR, ...)

Enumerations

enum class  hedgedev::csl::mem::page_protection {
  hedgedev::csl::mem::no_access = 0 << 0 , hedgedev::csl::mem::read = 1 << 0 , hedgedev::csl::mem::write = 1 << 1 , hedgedev::csl::mem::execute = 1 << 2 ,
  hedgedev::csl::mem::read_write = read | write , hedgedev::csl::mem::read_execute = read | execute , hedgedev::csl::mem::read_write_execute = read | write | execute , hedgedev::csl::mem::r = read ,
  hedgedev::csl::mem::w = write , hedgedev::csl::mem::x = execute , hedgedev::csl::mem::rw = read_write , hedgedev::csl::mem::rx = read_execute ,
  hedgedev::csl::mem::rwx = read_write_execute
}

Functions

void * hedgedev::csl::mem::get_original_module_base ()
uint32_t hedgedev::csl::mem::get_protect_flags (page_protection in_protection)
bool hedgedev::csl::mem::protect (void *in_address, size_t in_length, uint32_t in_new_protect_flags, uint32_t *out_old_protect_flags=nullptr)
void * hedgedev::csl::mem::to_aslr (void *in_address, void *in_base_address=nullptr)
void * hedgedev::csl::mem::from_aslr (void *in_address, void *in_base_address=nullptr)
bool hedgedev::csl::mem::is_nop (void *in_address)
template<typename T>
requires (std::is_integral_v<T>)
constexpr T hedgedev::csl::mem::align (T in_address, T in_alignment)
void * hedgedev::csl::mem::align (void *in_address, uintptr_t in_alignment)
template<typename T>
T hedgedev::csl::mem::read (void *in_address)
template<typename T, size_t count>
std::array< T, count > hedgedev::csl::mem::read (void *in_address)
branch_info hedgedev::csl::mem::get_branch_info (void *in_address)
template<typename T>
void * hedgedev::csl::mem::read_instr_address (void *in_address, ptrdiff_t in_offset, size_t in_stride)
void * hedgedev::csl::mem::read_call (void *in_address)
void * hedgedev::csl::mem::read_jump (void *in_address)
template<typename T>
constexpr T hedgedev::csl::mem::byteswap (T in_value)
template<typename T>
constexpr void hedgedev::csl::mem::byteswap_inplace (T &io_value)
template<typename T>
bool hedgedev::csl::mem::write (void *in_address, const T &in_data, size_t in_count=1)
template<typename T>
bool hedgedev::csl::mem::write (void *in_address, const std::vector< T > &in_data)
bool hedgedev::csl::mem::write_call (void *in_address, void *in_destination)
bool hedgedev::csl::mem::write_jump (void *in_address, void *in_destination, bool in_call=false)
bool hedgedev::csl::mem::write_nop (void *in_address, size_t in_count=1)
template<ut::expr::any_string T>
bool hedgedev::csl::mem::write_string (void *in_address, const T &in_str)
template<ut::expr::any_string T>
bool hedgedev::csl::mem::write_string_fixed_length (void *in_address, const T &in_str, size_t in_length=0)

Macro Definition Documentation

◆ ASLR

#define ASLR ( ADDRESS)
Value:
(hedgedev::csl::mem::to_aslr(reinterpret_cast<void*>(ADDRESS)))
void * to_aslr(void *in_address, void *in_base_address=nullptr)
Definition mem_win32.inl:63

Transforms a virtual address to the current module's ASLR base.

Parameters
ADDRESSThe address to transform.
Returns
The input address transformed into the ASLR base.

◆ IS_NOP

#define IS_NOP ( ADDRESS)
Value:
(hedgedev::csl::mem::is_nop(reinterpret_cast<void*>(ADDRESS)))
bool is_nop(void *in_address)
Definition mem_x86.inl:39

Checks if the instruction at the given memory address is a no-operation (NOP) instruction.

Parameters
ADDRESSThe address to check.
Returns
true if the instruction is no-operation (NOP). Otherwise, false.

◆ READ

#define READ ( ADDRESS,
TYPE )
Value:
(hedgedev::csl::mem::read<TYPE>(reinterpret_cast<void*>(ADDRESS)))

Reads a value in memory.

Parameters
ADDRESSThe address to read from.
TYPEThe type to read.
Returns
An instance of the type read from memory.

◆ READ_ARRAY

#define READ_ARRAY ( ADDRESS,
TYPE,
COUNT )
Value:
(hedgedev::csl::mem::read<TYPE, COUNT>(reinterpret_cast<void*>(ADDRESS)))

Reads an array of values in memory.

Parameters
ADDRESSThe address to read from.
TYPEThe type to read.
COUNTThe total number of values to read.
Returns
An array of instances of the type read from memory.

◆ READ_CALL

#define READ_CALL ( ADDRESS)
Value:
(hedgedev::csl::mem::read_call(reinterpret_cast<void*>(ADDRESS)))
void * read_call(void *in_address)
Definition mem_x86.inl:136

Reads the address of a call instruction in memory.

Parameters
ADDRESSThe address of the call instruction to read.
Returns
The address referenced by the call instruction.

◆ READ_INSTR_ADDRESS

#define READ_INSTR_ADDRESS ( ADDRESS,
TYPE,
OFFSET,
STRIDE )
Value:
(hedgedev::csl::mem::read_instr_address<TYPE>(reinterpret_cast<void*>(ADDRESS), OFFSET, STRIDE))
void * read_instr_address(void *in_address, ptrdiff_t in_offset, size_t in_stride)
Definition mem_x86.inl:128

Reads the address of an instruction in memory.

Parameters
ADDRESSThe address of the instruction to read.
TYPEThe type to read.
OFFSETThe offset of the address after ADDRESS.
STRIDEThe length of the instruction that was read.
Returns
The address referenced by the instruction.

◆ READ_JUMP

#define READ_JUMP ( ADDRESS)
Value:
(hedgedev::csl::mem::read_jump(reinterpret_cast<void*>(ADDRESS)))
void * read_jump(void *in_address)
Definition mem_x86.inl:141

Reads the address of a jump instruction in memory.

Parameters
ADDRESSThe address of the jump instruction to read.
Returns
The address referenced by the jump instruction.

◆ WRITE

#define WRITE ( ADDRESS,
TYPE,
... )
Value:
(hedgedev::csl::mem::write<TYPE>(reinterpret_cast<void*>(ADDRESS), { __VA_ARGS__ }))

Writes any number of values in memory.

Parameters
ADDRESSThe address to write to.
TYPEThe type to write.
__VA_ARGS__The values to write.
Returns
true if the data was written successfully. Otherwise, false.

◆ WRITE_ARRAY

#define WRITE_ARRAY ( ADDRESS,
TYPE,
DATA )
Value:
(hedgedev::csl::mem::write<TYPE>(reinterpret_cast<void*>(ADDRESS), DATA))

Writes an array of values in memory.

Parameters
ADDRESSThe address to write to.
TYPEThe type to write.
DATAThe collection of values to write.
Returns
true if the data was written successfully. Otherwise, false.

◆ WRITE_CALL

#define WRITE_CALL ( ADDRESS,
DESTINATION )
Value:
(hedgedev::csl::mem::write_call(reinterpret_cast<void*>(ADDRESS), reinterpret_cast<void*>(DESTINATION)))
bool write_call(void *in_address, void *in_destination)
Definition mem_x86.inl:146

Writes a call instruction in memory.

Parameters
ADDRESSThe address to write to.
DESTINATIONThe address of the function to call.
Returns
true if the call was written successfully. Otherwise, false.

◆ WRITE_JUMP

#define WRITE_JUMP ( ADDRESS,
DESTINATION )
Value:
(hedgedev::csl::mem::write_jump(reinterpret_cast<void*>(ADDRESS), reinterpret_cast<void*>(DESTINATION)))
bool write_jump(void *in_address, void *in_destination, bool in_call=false)
Definition mem_x86.inl:151

Writes a jump instruction in memory.

Parameters
ADDRESSThe address to write to.
DESTINATIONThe address of the address to jump to.
Returns
true if the jump was written successfully. Otherwise, false.

◆ WRITE_NOP

#define WRITE_NOP ( ADDRESS,
COUNT )
Value:
(hedgedev::csl::mem::write_nop(reinterpret_cast<void*>(ADDRESS), COUNT))
bool write_nop(void *in_address, size_t in_count=1)
Definition mem_x86.inl:188

Writes a no-operation (NOP) instruction in memory.

Parameters
ADDRESSThe address to write to.
COUNTThe total number of no-operation (NOP) instructions to write.
Returns
true if the no-operation (NOP) instruction was written successfully. Otherwise, false.

◆ WRITE_STRING

#define WRITE_STRING ( ADDRESS,
STR )
Value:
(hedgedev::csl::mem::write_string(reinterpret_cast<void*>(ADDRESS), STR))
bool write_string(void *in_address, const T &in_str)
Definition mem.inl:147

Writes a string in memory.

Parameters
ADDRESSThe address to write to.
STRThe string to write.
Returns
true if the string was written successfully. Otherwise, false.

◆ WRITE_STRING_FIXED

#define WRITE_STRING_FIXED ( ADDRESS,
STR,
... )
Value:
(hedgedev::csl::mem::write_string_fixed_length(reinterpret_cast<void*>(ADDRESS), STR, __VA_ARGS__))
bool write_string_fixed_length(void *in_address, const T &in_str, size_t in_length=0)
Definition mem.inl:156

Writes a string of fixed length in memory.

Parameters
ADDRESSThe address to write to.
STRThe string to write.
__VA_ARGS__The length of the string to write. If zero or unspecified, the length will be determined by the length of an existing string located at ADDRESS.
Returns
true if the string was written successfully. Otherwise, false.