CommonLib
Loading...
Searching...
No Matches
hedgedev::csl::mem Namespace Reference

Classes

struct  branch_info

Enumerations

enum class  page_protection {
  no_access = 0 << 0 , read = 1 << 0 , write = 1 << 1 , execute = 1 << 2 ,
  read_write = read | write , read_execute = read | execute , read_write_execute = read | write | execute , r = read ,
  w = write , x = execute , rw = read_write , rx = read_execute ,
  rwx = read_write_execute
}
enum class  branch_type {
  conditional , jump , call , conditional ,
  jump , call
}
enum class  branch_distance {
  short_branch , near_branch , far_branch , short_branch ,
  near_branch , far_branch
}
enum class  branch_condition {
  overflow , not_overflow , below , not_below ,
  equal , not_equal , below_or_equal , above ,
  sign , not_sign , parity , not_parity ,
  less , not_less , not_greater , greater ,
  overflow , not_overflow , below , not_below ,
  equal , not_equal , below_or_equal , above ,
  sign , not_sign , parity , not_parity ,
  less , not_less , not_greater , greater
}
enum class  branch_type {
  conditional , jump , call , conditional ,
  jump , call
}
enum class  branch_distance {
  short_branch , near_branch , far_branch , short_branch ,
  near_branch , far_branch
}
enum class  branch_condition {
  overflow , not_overflow , below , not_below ,
  equal , not_equal , below_or_equal , above ,
  sign , not_sign , parity , not_parity ,
  less , not_less , not_greater , greater ,
  overflow , not_overflow , below , not_below ,
  equal , not_equal , below_or_equal , above ,
  sign , not_sign , parity , not_parity ,
  less , not_less , not_greater , greater
}

Functions

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

Enumeration Type Documentation

◆ branch_condition [1/2]

Enumerator
overflow 
not_overflow 
below 
not_below 
equal 
not_equal 
below_or_equal 
above 
sign 
not_sign 
parity 
not_parity 
less 
not_less 
not_greater 
greater 
overflow 
not_overflow 
below 
not_below 
equal 
not_equal 
below_or_equal 
above 
sign 
not_sign 
parity 
not_parity 
less 
not_less 
not_greater 
greater 

◆ branch_condition [2/2]

Enumerator
overflow 
not_overflow 
below 
not_below 
equal 
not_equal 
below_or_equal 
above 
sign 
not_sign 
parity 
not_parity 
less 
not_less 
not_greater 
greater 
overflow 
not_overflow 
below 
not_below 
equal 
not_equal 
below_or_equal 
above 
sign 
not_sign 
parity 
not_parity 
less 
not_less 
not_greater 
greater 

◆ branch_distance [1/2]

Enumerator
short_branch 
near_branch 
far_branch 
short_branch 
near_branch 
far_branch 

◆ branch_distance [2/2]

Enumerator
short_branch 
near_branch 
far_branch 
short_branch 
near_branch 
far_branch 

◆ branch_type [1/2]

Enumerator
conditional 
jump 
call 
conditional 
jump 
call 

◆ branch_type [2/2]

Enumerator
conditional 
jump 
call 
conditional 
jump 
call 

◆ page_protection

Enumerator
no_access 0 << 0 
read 1 << 0 
write 1 << 1 
execute 1 << 2 
read_write read | write 
read_execute read | execute 
read_write_execute read | write | execute 
r read 
w write 
x execute 
rw read_write 
rx read_execute 
rwx read_write_execute 

Function Documentation

◆ align() [1/2]

template<typename T>
requires (std::is_integral_v<T>)
T hedgedev::csl::mem::align ( T in_address,
T in_alignment )
inlineconstexpr

Aligns a memory address.

Template Parameters
TThe integral type of the address and alignment.
Parameters
in_addressThe address to align.
in_alignmentThe alignment to use.
Returns
The aligned memory address.

◆ align() [2/2]

void * hedgedev::csl::mem::align ( void * in_address,
uintptr_t in_alignment )
inline

Aligns a memory address.

Parameters
in_addressThe address to align.
in_alignmentThe alignment to use.
Returns
The aligned memory address.

◆ byteswap()

template<typename T>
T hedgedev::csl::mem::byteswap ( T in_value)
inlineconstexpr

Swaps the complete order of bytes for any type.

Parameters
in_valueThe value to swap.
Returns
The swapped value.

◆ byteswap_inplace()

template<typename T>
void hedgedev::csl::mem::byteswap_inplace ( T & io_value)
inlineconstexpr

Swaps the complete order of bytes for any type by reference.

Parameters
io_valueThe value to swap.

◆ from_aslr()

void * hedgedev::csl::mem::from_aslr ( void * in_address,
void * in_base_address = nullptr )
inline

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

Parameters
in_addressThe address to transform.
in_base_addressThe original base address of the module containing the address (optional).
Returns
The input address transformed from the ASLR base.

◆ get_branch_info()

branch_info hedgedev::csl::mem::get_branch_info ( void * in_address)
inline

Gets information about a branch instruction in memory.

Parameters
in_addressThe address of the branch instruction.
Returns
A structure containing information about the branch.

◆ get_original_module_base()

void * hedgedev::csl::mem::get_original_module_base ( )
inline

Gets the original base address of the current module.

◆ get_protect_flags()

uint32_t hedgedev::csl::mem::get_protect_flags ( page_protection in_protection)
inline

Gets the system flags for the specified page protection.

◆ is_nop()

bool hedgedev::csl::mem::is_nop ( void * in_address)
inline

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

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

◆ protect()

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 )
inline

Sets the protection of a page of memory.

◆ read() [1/2]

template<typename T, size_t count>
std::array< T, count > hedgedev::csl::mem::read ( void * in_address)
inline

Reads an array of values in memory.

Template Parameters
TThe type to read.
countThe total number of values to read.
Parameters
in_addressThe address to read from.
Returns
An array of instances of the type read from memory.

◆ read() [2/2]

template<typename T>
T hedgedev::csl::mem::read ( void * in_address)
inline

Reads a value in memory.

Template Parameters
TThe type to read.
Parameters
in_addressThe address to read from.
Returns
An instance of the type read from memory.

◆ read_call()

void * hedgedev::csl::mem::read_call ( void * in_address)
inline

Reads the address of a call instruction in memory.

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

◆ read_instr_address()

template<typename T>
void * hedgedev::csl::mem::read_instr_address ( void * in_address,
ptrdiff_t in_offset,
size_t in_stride )
inline

Reads the address of an instruction in memory.

Template Parameters
TThe type to read.
Parameters
in_addressThe address of the instruction to read.
in_offsetThe offset of the address after in_address.
in_strideThe length of the instruction that was read.
Returns
The address referenced by the instruction.

◆ read_jump()

void * hedgedev::csl::mem::read_jump ( void * in_address)
inline

Reads the address of a jump instruction in memory.

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

◆ to_aslr()

void * hedgedev::csl::mem::to_aslr ( void * in_address,
void * in_base_address = nullptr )
inline

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

Parameters
in_addressThe address to transform.
in_base_addressThe original base address of the module containing the address (optional).
Returns
The input address transformed into the ASLR base.

◆ write() [1/2]

template<typename T>
bool hedgedev::csl::mem::write ( void * in_address,
const std::vector< T > & in_data )
inline

Writes an array of values in memory.

Template Parameters
TThe type to write.
Parameters
in_addressThe address to write to.
in_dataThe collection of values to write.
Returns
true if the data was written successfully. Otherwise, false.

◆ write() [2/2]

template<typename T>
bool hedgedev::csl::mem::write ( void * in_address,
const T & in_data,
size_t in_count = 1 )
inline

Writes a value in memory.

Template Parameters
TThe type to write.
Parameters
in_addressThe address to write to.
in_dataThe data to write.
in_countThe total number of values to write.
Returns
true if the data was written successfully. Otherwise, false.

◆ write_call()

bool hedgedev::csl::mem::write_call ( void * in_address,
void * in_destination )
inline

Writes a call instruction in memory.

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

◆ write_jump()

bool hedgedev::csl::mem::write_jump ( void * in_address,
void * in_destination,
bool in_call = false )
inline

Writes a jump instruction in memory.

Parameters
in_addressThe address to write to.
in_destinationThe address of the address to jump to.
in_callDetermines whether the jump should be encoded as a call instruction.
Returns
true if the jump was written successfully. Otherwise, false.

◆ write_nop()

bool hedgedev::csl::mem::write_nop ( void * in_address,
size_t in_count = 1 )
inline

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

Parameters
in_addressThe address to write to.
in_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()

template<ut::expr::any_string T>
bool hedgedev::csl::mem::write_string ( void * in_address,
const T & in_str )
inline

Writes a string in memory.

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

◆ write_string_fixed_length()

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 )
inline

Writes a string of fixed length in memory.

Parameters
in_addressThe address to write to.
in_strThe string to write.
in_lengthThe length of the string to write. If zero, the length will be determined by the length of an existing string located at in_address.
Returns
true if the string was written successfully. Otherwise, false.