mirror of
https://github.com/hyprwm/Hyprland.git
synced 2024-09-11 13:25:42 +03:00
functionhooks: throw an exception on unsupported %rip usage
ref #2479, now will actually tell you what's wrong instead of crashing
This commit is contained in:
parent
adeb20ea11
commit
1778fb77e2
@ -45,6 +45,10 @@ size_t CFunctionHook::getInstructionLenAt(void* start) {
|
|||||||
// I don't have an assembler. I don't think udis provides one. Besides, variables might be tricky.
|
// I don't have an assembler. I don't think udis provides one. Besides, variables might be tricky.
|
||||||
if (((uint8_t*)start)[0] == 0xFF && ((uint8_t*)start)[1] == 0x15)
|
if (((uint8_t*)start)[0] == 0xFF && ((uint8_t*)start)[1] == 0x15)
|
||||||
m_vTrampolineRIPUses.emplace_back(std::make_pair<>((uint64_t)start - (uint64_t)m_pSource, ins));
|
m_vTrampolineRIPUses.emplace_back(std::make_pair<>((uint64_t)start - (uint64_t)m_pSource, ins));
|
||||||
|
else {
|
||||||
|
Debug::log(ERR, "[CFunctionHook] Cannot hook: unsupported %rip usage: {}", ins);
|
||||||
|
throw std::runtime_error("unsupported %rip usage");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return insSize;
|
return insSize;
|
||||||
@ -90,7 +94,10 @@ bool CFunctionHook::hook() {
|
|||||||
static constexpr size_t CALL_WITH_RAX_ADDRESS_OFFSET = 2;
|
static constexpr size_t CALL_WITH_RAX_ADDRESS_OFFSET = 2;
|
||||||
|
|
||||||
// get minimum size to overwrite
|
// get minimum size to overwrite
|
||||||
const auto HOOKSIZE = probeMinimumJumpSize(m_pSource, sizeof(ABSOLUTE_JMP_ADDRESS) + sizeof(PUSH_RAX) + sizeof(POP_RAX));
|
size_t HOOKSIZE = 0;
|
||||||
|
try {
|
||||||
|
HOOKSIZE = probeMinimumJumpSize(m_pSource, sizeof(ABSOLUTE_JMP_ADDRESS) + sizeof(PUSH_RAX) + sizeof(POP_RAX));
|
||||||
|
} catch (std::exception& e) { return false; }
|
||||||
|
|
||||||
// alloc trampoline
|
// alloc trampoline
|
||||||
const auto TRAMPOLINE_SIZE = sizeof(ABSOLUTE_JMP_ADDRESS) + HOOKSIZE + sizeof(PUSH_RAX) + m_vTrampolineRIPUses.size() * (sizeof(CALL_WITH_RAX) - 6);
|
const auto TRAMPOLINE_SIZE = sizeof(ABSOLUTE_JMP_ADDRESS) + HOOKSIZE + sizeof(PUSH_RAX) + m_vTrampolineRIPUses.size() * (sizeof(CALL_WITH_RAX) - 6);
|
||||||
|
Loading…
Reference in New Issue
Block a user