diff options
author | Vaxry <[email protected]> | 2023-12-09 16:16:46 +0000 |
---|---|---|
committer | Vaxry <[email protected]> | 2023-12-09 16:16:46 +0000 |
commit | 9132660768668e1e14d95b8e8b3b02c4b000f137 (patch) | |
tree | 0b1bc64703a5a028d7e86bea22ebb2284116570f /src/plugins | |
parent | dd0714c22a7f588c1c80f83b45f66f034f83a884 (diff) | |
download | Hyprland-9132660768668e1e14d95b8e8b3b02c4b000f137.tar.gz Hyprland-9132660768668e1e14d95b8e8b3b02c4b000f137.zip |
functionHooks: fix incorrect protlen calcs
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/HookSystem.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/plugins/HookSystem.cpp b/src/plugins/HookSystem.cpp index d7a366f3..04b12134 100644 --- a/src/plugins/HookSystem.cpp +++ b/src/plugins/HookSystem.cpp @@ -128,8 +128,11 @@ bool CFunctionHook::hook() { (uint64_t)((uint8_t*)m_pSource + sizeof(ABSOLUTE_JMP_ADDRESS)); // make jump to hk - mprotect((uint8_t*)m_pSource - ((uint64_t)m_pSource) % sysconf(_SC_PAGE_SIZE), sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE | PROT_EXEC); - memcpy(m_pSource, ABSOLUTE_JMP_ADDRESS, sizeof(ABSOLUTE_JMP_ADDRESS)); + const auto PAGESIZE = sysconf(_SC_PAGE_SIZE); + const uint8_t* PROTSTART = (uint8_t*)m_pSource - ((uint64_t)m_pSource % PAGESIZE); + const size_t PROTLEN = std::ceil((float)(HOOKSIZE + ((uint64_t)m_pSource - (uint64_t)PROTSTART)) / (float)PAGESIZE) * PAGESIZE; + mprotect((uint8_t*)PROTSTART, PROTLEN, PROT_READ | PROT_WRITE | PROT_EXEC); + memcpy((uint8_t*)m_pSource, ABSOLUTE_JMP_ADDRESS, sizeof(ABSOLUTE_JMP_ADDRESS)); // make popq %rax and NOP all remaining memcpy((uint8_t*)m_pSource + sizeof(ABSOLUTE_JMP_ADDRESS), POP_RAX, sizeof(POP_RAX)); @@ -140,7 +143,7 @@ bool CFunctionHook::hook() { *(uint64_t*)((uint8_t*)m_pSource + ABSOLUTE_JMP_ADDRESS_OFFSET) = (uint64_t)(m_pDestination); // revert mprot - mprotect((uint8_t*)m_pSource - ((uint64_t)m_pSource) % sysconf(_SC_PAGE_SIZE), sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_EXEC); + mprotect((uint8_t*)PROTSTART, PROTLEN, PROT_READ | PROT_EXEC); // set original addr to trampo addr m_pOriginal = m_pTrampolineAddr; |