-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.h
More file actions
53 lines (43 loc) · 1.98 KB
/
hooks.h
File metadata and controls
53 lines (43 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef HOOKS_H
#define HOOKS_H
#include "hostname.h"
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <winsock2.h>
#include <windows.h>
#include <cstdint>
#include <string>
#include <iostream>
#include <array>
#include <cstddef>
typedef INT (WSAAPI* connect_t)(SOCKET s, const sockaddr *name, int namelen);
typedef INT (WSAAPI* recv_t)(SOCKET s, char *buf, int len, int flags);
typedef INT (WSAAPI* send_t)(SOCKET s, const char *buf, int len, int flags);
typedef INT (WSAAPI* getaddrinfo_t)(PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA* pHints, PADDRINFOA* ppResult);
typedef INT (WSAAPI* GetAddrInfoW_t)(PCWSTR pNodeName, PCWSTR pServiceName, const ADDRINFOW* pHints, PADDRINFOW* ppResult);
namespace hooks {
inline connect_t connect_og = nullptr;
INT WSAAPI connect_detour(SOCKET s, const sockaddr *name, int namelen) {
const auto* addr = reinterpret_cast<sockaddr_in*>(const_cast<sockaddr*>(name));
const auto ip = inet_ntoa(addr->sin_addr);
const auto port = ntohs(addr->sin_port);
SetConsoleTitleA((std::string(ip) + ":" + std::to_string(port)).c_str());
return connect_og(s, name, namelen);
}
inline recv_t recv_og = nullptr;
INT WSAAPI recv_hook(SOCKET s, char *buf, int len, int flags) {
return recv_og(s, buf, len, flags);
}
inline send_t send_og = nullptr;
INT WSAAPI send_hook(SOCKET s, const char *buf, int len, int flags) {
return send_og(s, buf, len, flags);
}
inline getaddrinfo_t getaddrinfo_og = nullptr;
INT WSAAPI getaddrinfo_detour(PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA* pHints, PADDRINFOA* ppResult) {
return getaddrinfo_og(redirect_hostname, pServiceName, pHints, ppResult);
}
inline GetAddrInfoW_t GetAddrInfoW_og = nullptr;
INT WSAAPI GetAddrInfoW_detour(PCWSTR pNodeName, PCWSTR pServiceName, const ADDRINFOW* pHints, PADDRINFOW* ppResult) {
return GetAddrInfoW_og(wide_redirect_hostname, pServiceName, pHints, ppResult);
}
}
#endif