internal.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include "../../hooking/detour.h"
  5. #include "platform/sdk.h"
  6. namespace sunrise::client::hooks::egress {
  7. /** Stable slot order shared by exports, Detours handles, and tests. */
  8. enum class HookSlot : std::size_t {
  9. connect,
  10. wsaConnect,
  11. wsaConnectByNameA,
  12. wsaConnectByNameW,
  13. wsaConnectByList,
  14. send,
  15. wsaSend,
  16. sendTo,
  17. wsaSendTo,
  18. wsaSendMsg,
  19. wsaSendDisconnect,
  20. wsaJoinLeaf,
  21. transmitFile,
  22. wsaIoctl,
  23. getAddrInfoA,
  24. getAddrInfoW,
  25. getAddrInfoExA,
  26. getAddrInfoExW,
  27. getHostByName,
  28. getHostByAddress,
  29. getNameInfoA,
  30. getNameInfoW,
  31. dnsQueryA,
  32. dnsQueryW,
  33. dnsQueryUtf8,
  34. dnsQueryEx,
  35. recv,
  36. wsaRecv,
  37. recvFrom,
  38. wsaRecvFrom,
  39. dnsQueryRaw,
  40. count,
  41. };
  42. /** Fixed handle count covers every required and OS-optional egress entry point. */
  43. inline constexpr std::size_t kHookCount = static_cast<std::size_t>(HookSlot::count);
  44. extern std::array<hooking::detour::Handle, kHookCount> g_handles;
  45. /**
  46. * Returns one typed trampoline after the atomic install publishes its handles.
  47. * @tparam Function Exact Windows SDK function pointer type.
  48. * @return Callable original entry, or null before publication.
  49. */
  50. template <typename Function> [[nodiscard]] Function original(HookSlot slot) noexcept {
  51. const auto index = static_cast<std::size_t>(slot);
  52. return reinterpret_cast<Function>(g_handles[index].original);
  53. }
  54. } // namespace sunrise::client::hooks::egress