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

Classes

struct  BranchInfo

Enumerations

enum class  PageProtection {
  NoAccess = 0 << 0 , Read = 1 << 0 , Write = 1 << 1 , Execute = 1 << 2 ,
  ReadWrite = Read | Write , ReadExecute = Read | Execute , ReadWriteExecute = Read | Write | Execute , R = Read ,
  W = Write , X = Execute , RW = ReadWrite , RX = ReadExecute ,
  RWX = ReadWriteExecute
}
enum class  BranchType { Conditional , Jump , Call }
enum class  BranchDistance { Short , Near , Far }
enum class  BranchCondition {
  Overflow , NotOverflow , Below , NotBelow ,
  Equal , NotEqual , BelowOrEqual , Above ,
  Sign , NotSign , Parity , NotParity ,
  Less , NotLess , NotGreater , Greater
}

Functions

void * GetOriginalModuleBase ()
uint32_t GetProtectionFlags (PageProtection in_protection)
bool Protect (void *in_pAddress, size_t in_length, uint32_t in_newProtectionFlags, uint32_t *out_pOldProtectionFlags=nullptr)
void * ToASLR (void *in_pAddress, void *in_pBaseAddress=nullptr)
void * FromASLR (void *in_pAddress, void *in_pBaseAddress=nullptr)
bool IsNop (void *in_pAddress)
template<typename T>
Read (void *in_pAddress)
template<typename T, size_t Count>
std::array< T, Count > Read (void *in_pAddress)
BranchInfo GetBranchInfo (void *in_pAddress)
template<typename T>
void * ReadInstructionAddress (void *in_pAddress, size_t in_offset, size_t in_stride)
void * ReadCall (void *in_pAddress)
void * ReadJump (void *in_pAddress)
template<typename T>
bool Write (void *in_pAddress, const T &in_rData, size_t in_count=1)
template<typename T>
bool Write (void *in_pAddress, const std::vector< T > &in_rData)
bool WriteCall (void *in_pAddress, void *in_pDestination)
bool WriteJump (void *in_pAddress, void *in_pDestination, bool in_isCall=false)
bool WriteNop (void *in_pAddress, size_t in_count=1)
template<hedgedev::csl::ut::expr::AnyString T>
bool WriteString (void *in_pAddress, const T &in_rStr)
template<hedgedev::csl::ut::expr::AnyString T>
bool WriteStringFixedLength (void *in_pAddress, const T &in_rStr, size_t in_length=0)

Enumeration Type Documentation

◆ BranchCondition

Enumerator
Overflow 
NotOverflow 
Below 
NotBelow 
Equal 
NotEqual 
BelowOrEqual 
Above 
Sign 
NotSign 
Parity 
NotParity 
Less 
NotLess 
NotGreater 
Greater 

◆ BranchDistance

Enumerator
Short 
Near 
Far 

◆ BranchType

enum class hedgedev::csl::mem::BranchType
strong
Enumerator
Conditional 
Jump 
Call 

◆ PageProtection

Enumerator
NoAccess 0 << 0 
Read 1 << 0 
Write 1 << 1 
Execute 1 << 2 
ReadWrite Read | Write 
ReadExecute Read | Execute 
ReadWriteExecute Read | Write | Execute 
Read 
Write 
Execute 
RW ReadWrite 
RX ReadExecute 
RWX ReadWriteExecute 

Function Documentation

◆ FromASLR()

void * hedgedev::csl::mem::FromASLR ( void * in_pAddress,
void * in_pBaseAddress = nullptr )
inline

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

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

◆ GetBranchInfo()

BranchInfo hedgedev::csl::mem::GetBranchInfo ( void * in_pAddress)
inline

Gets information about a branch instruction in memory.

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

◆ GetOriginalModuleBase()

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

Gets the original base address of the current module.

◆ GetProtectionFlags()

uint32_t hedgedev::csl::mem::GetProtectionFlags ( PageProtection in_protection)
inline

Gets the system flags for the specified page protection.

◆ IsNop()

bool hedgedev::csl::mem::IsNop ( void * in_pAddress)
inline

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

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

◆ Protect()

bool hedgedev::csl::mem::Protect ( void * in_pAddress,
size_t in_length,
uint32_t in_newProtectionFlags,
uint32_t * out_pOldProtectionFlags = 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_pAddress)
inline

Reads an array of values in memory.

Template Parameters
TThe type to read.
CountThe total number of values to read.
Parameters
in_pAddressThe 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_pAddress)
inline

Reads a value in memory.

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

◆ ReadCall()

void * hedgedev::csl::mem::ReadCall ( void * in_pAddress)
inline

Reads the address of a call instruction in memory.

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

◆ ReadInstructionAddress()

template<typename T>
void * hedgedev::csl::mem::ReadInstructionAddress ( void * in_pAddress,
size_t in_offset,
size_t in_stride )
inline

Reads the address of an instruction in memory.

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

◆ ReadJump()

void * hedgedev::csl::mem::ReadJump ( void * in_pAddress)
inline

Reads the address of a jump instruction in memory.

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

◆ ToASLR()

void * hedgedev::csl::mem::ToASLR ( void * in_pAddress,
void * in_pBaseAddress = nullptr )
inline

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

Parameters
in_pAddressThe address to transform.
in_pBaseAddressThe 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_pAddress,
const std::vector< T > & in_rData )
inline

Writes an array of values in memory.

Template Parameters
TThe type to write.
Parameters
in_pAddressThe address to write to.
in_rDataThe collection of values to write.

◆ Write() [2/2]

template<typename T>
bool hedgedev::csl::mem::Write ( void * in_pAddress,
const T & in_rData,
size_t in_count = 1 )
inline

Writes a value in memory.

Template Parameters
TThe type to write.
Parameters
in_pAddressThe address to write to.
in_rDataThe data to write.
in_countThe total number of values to write.

◆ WriteCall()

bool hedgedev::csl::mem::WriteCall ( void * in_pAddress,
void * in_pDestination )
inline

Writes a call instruction in memory.

Parameters
in_pAddressThe address to write to.
in_pDestinationThe address of the function to call.

◆ WriteJump()

bool hedgedev::csl::mem::WriteJump ( void * in_pAddress,
void * in_pDestination,
bool in_isCall = false )
inline

Writes a jump instruction in memory.

Parameters
in_pAddressThe address to write to.
in_pDestinationThe address of the address to jump to.
in_isCallDetermines whether the jump should be encoded as a call instruction.

◆ WriteNop()

bool hedgedev::csl::mem::WriteNop ( void * in_pAddress,
size_t in_count = 1 )
inline

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

Parameters
in_pAddressThe address to write to.
in_countThe total number of no-operation (NOP) instructions to write.

◆ WriteString()

bool hedgedev::csl::mem::WriteString ( void * in_pAddress,
const T & in_rStr )
inline

Writes a string in memory.

Parameters
in_pAddressThe address to write to.
in_rStrThe string to write.

◆ WriteStringFixedLength()

bool hedgedev::csl::mem::WriteStringFixedLength ( void * in_pAddress,
const T & in_rStr,
size_t in_length = 0 )
inline

Writes a string of fixed length in memory.

Parameters
in_pAddressThe address to write to.
in_rStrThe 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_pAddress.