logic: Add ability to skip mprotect with StoreToAddress (#1523)

* Implement StoreToAddress param to optionally set memory page permissions

* Update comment
This commit is contained in:
nosoop 2021-07-10 12:45:00 -07:00 committed by GitHub
parent 823b55c22a
commit 387b85406e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

View File

@ -747,18 +747,34 @@ static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params)
NumberType size = static_cast<NumberType>(params[3]);
// new parameter added after SM 1.10; defaults to true for backwards compatibility
bool updateMemAccess = true;
if (params[0] >= 4)
{
updateMemAccess = params[4];
}
switch(size)
{
case NumberType_Int8:
SourceHook::SetMemAccess(addr, sizeof(uint8_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
if (updateMemAccess)
{
SourceHook::SetMemAccess(addr, sizeof(uint8_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
}
*reinterpret_cast<uint8_t*>(addr) = data;
break;
case NumberType_Int16:
SourceHook::SetMemAccess(addr, sizeof(uint16_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
if (updateMemAccess)
{
SourceHook::SetMemAccess(addr, sizeof(uint16_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
}
*reinterpret_cast<uint16_t*>(addr) = data;
break;
case NumberType_Int32:
SourceHook::SetMemAccess(addr, sizeof(uint32_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
if (updateMemAccess)
{
SourceHook::SetMemAccess(addr, sizeof(uint32_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
}
*reinterpret_cast<uint32_t*>(addr) = data;
break;
default:

View File

@ -698,13 +698,15 @@ native any LoadFromAddress(Address addr, NumberType size);
/**
* Store up to 4 bytes to a memory address.
*
* @param addr Address to a memory location.
* @param data Value to store at the address.
* @param size How many bytes should be written.
* If storing a floating-point value, use NumberType_Int32.
* @error Address is null or pointing to reserved memory.
* @param addr Address to a memory location.
* @param data Value to store at the address.
* @param size How many bytes should be written.
* If storing a floating-point value, use NumberType_Int32.
* @param updateMemAccess If true, SourceMod will set read / write / exec permissions
* on the memory page being written to.
* @error Address is null or pointing to reserved memory.
*/
native void StoreToAddress(Address addr, any data, NumberType size);
native void StoreToAddress(Address addr, any data, NumberType size, bool updateMemAccess = true);
methodmap FrameIterator < Handle {
// Creates a stack frame iterator to build your own stack traces.