mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-23 12:28:07 +01:00
Whitelist custom broadcasts in non LAN ip blocking.
This commit is contained in:
parent
f6b8068883
commit
d215070876
3 changed files with 18 additions and 12 deletions
20
dll/base.cpp
20
dll/base.cpp
|
@ -519,11 +519,11 @@ struct ips_test {
|
|||
uint32_t ip_to;
|
||||
};
|
||||
|
||||
static std::vector<struct ips_test> adapter_ips;
|
||||
static std::vector<struct ips_test> whitelist_ips;
|
||||
|
||||
void set_adapter_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
|
||||
void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
|
||||
{
|
||||
adapter_ips.clear();
|
||||
whitelist_ips.clear();
|
||||
for (unsigned i = 0; i < num_ips; ++i) {
|
||||
struct ips_test ip_a;
|
||||
PRINT_DEBUG("from: %hhu.%hhu.%hhu.%hhu\n", ((unsigned char *)&from[i])[0], ((unsigned char *)&from[i])[1], ((unsigned char *)&from[i])[2], ((unsigned char *)&from[i])[3]);
|
||||
|
@ -533,19 +533,19 @@ void set_adapter_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
|
|||
if (ip_a.ip_to < ip_a.ip_from) continue;
|
||||
if ((ip_a.ip_to - ip_a.ip_from) > (1 << 25)) continue;
|
||||
PRINT_DEBUG("added\n");
|
||||
adapter_ips.push_back(ip_a);
|
||||
whitelist_ips.push_back(ip_a);
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_adapter_ip(unsigned char *ip)
|
||||
static bool is_whitelist_ip(unsigned char *ip)
|
||||
{
|
||||
uint32_t ip_temp = 0;
|
||||
memcpy(&ip_temp, ip, sizeof(ip_temp));
|
||||
ip_temp = ntohl(ip_temp);
|
||||
|
||||
for (auto &i : adapter_ips) {
|
||||
for (auto &i : whitelist_ips) {
|
||||
if (i.ip_from <= ip_temp && ip_temp <= i.ip_to) {
|
||||
PRINT_DEBUG("ADAPTER IP %hhu.%hhu.%hhu.%hhu\n", ip[0], ip[1], ip[2], ip[3]);
|
||||
PRINT_DEBUG("WHITELISTED IP %hhu.%hhu.%hhu.%hhu\n", ip[0], ip[1], ip[2], ip[3]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -562,7 +562,7 @@ static bool is_lan_ip(const sockaddr *addr, int namelen)
|
|||
unsigned char ip[4];
|
||||
memcpy(ip, &addr_in->sin_addr, sizeof(ip));
|
||||
PRINT_DEBUG("CHECK LAN IP %hhu.%hhu.%hhu.%hhu:%u\n", ip[0], ip[1], ip[2], ip[3], ntohs(addr_in->sin_port));
|
||||
if (is_adapter_ip(ip)) return true;
|
||||
if (is_whitelist_ip(ip)) return true;
|
||||
if (ip[0] == 127) return true;
|
||||
if (ip[0] == 10) return true;
|
||||
if (ip[0] == 192 && ip[1] == 168) return true;
|
||||
|
@ -838,13 +838,13 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD dwReason, LPVOID ) {
|
|||
return TRUE;
|
||||
}
|
||||
#else
|
||||
void set_adapter_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
|
||||
void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
void set_adapter_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
|
||||
void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -456,7 +456,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
void set_adapter_ips(uint32_t *from, uint32_t *to, unsigned num_ips);
|
||||
void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips);
|
||||
#ifdef EMU_EXPERIMENTAL_BUILD
|
||||
bool crack_SteamAPI_RestartAppIfNecessary(uint32 unOwnAppID);
|
||||
bool crack_SteamAPI_Init();
|
||||
|
|
|
@ -314,7 +314,13 @@ static bool send_broadcasts(sock_t sock, uint16 port, char *data, unsigned long
|
|||
if (number_broadcasts < 0 || check_timedout(last_get_broadcast_info, 60.0)) {
|
||||
PRINT_DEBUG("get_broadcast_info\n");
|
||||
get_broadcast_info(port);
|
||||
set_adapter_ips(lower_range_ips, upper_range_ips, number_broadcasts);
|
||||
std::vector<uint32_t> lower_range(lower_range_ips, lower_range_ips + number_broadcasts), upper_range(upper_range_ips, upper_range_ips + number_broadcasts);
|
||||
for(auto &addr : *custom_broadcasts) {
|
||||
lower_range.push_back(addr.ip);
|
||||
upper_range.push_back(addr.ip);
|
||||
}
|
||||
|
||||
set_whitelist_ips(lower_range.data(), upper_range.data(), lower_range.size());
|
||||
last_get_broadcast_info = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue