Skip to content

Commit

Permalink
Fix LoadLibraryExW hooking crash (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Burnt-o authored Feb 10, 2025
1 parent 85155dd commit afab976
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/os.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ void trap_threads(uint8_t* from, uint8_t* to, size_t len, const std::function<vo
new_protect = PAGE_EXECUTE_READWRITE;
}

auto si = system_info();
auto *from_page_start = align_down(from, si.page_size);
auto *from_page_end = align_up(from + len, si.page_size);
auto *vp_start = reinterpret_cast<uint8_t*>(&VirtualProtect);
auto *vp_end = vp_start + 0x20;

if (!(from_page_end < vp_start || vp_end < from_page_start)){
new_protect = PAGE_EXECUTE_READWRITE;
}

std::scoped_lock lock{TrapManager::mutex};

if (TrapManager::instance == nullptr) {
Expand Down Expand Up @@ -314,4 +324,4 @@ void fix_ip(ThreadContext thread_ctx, uint8_t* old_ip, uint8_t* new_ip) {

} // namespace safetyhook

#endif
#endif

0 comments on commit afab976

Please sign in to comment.