diff --git a/README.md b/README.md index 45bb234..9e5f574 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@

A multi-purpose adblocker and skip bypass for the Windows Spotify Desktop Application.

Please support Spotify by purchasing premium

- Current Version: 0.45
- Last updated: 14 February 2020
- Last tested version: 1.1.25.559.g85cf5e4c + Current Version: 0.46
+ Last updated: 20 February 2020
+ Last tested version: 1.1.26.501.gbe11e53b

Important Notice(s)

diff --git a/chrome_elf.zip b/chrome_elf.zip index ca14bb6..7cfb644 100644 Binary files a/chrome_elf.zip and b/chrome_elf.zip differ diff --git a/src/Adblock.cpp b/src/Adblock.cpp index 74d1390..d90abdd 100644 --- a/src/Adblock.cpp +++ b/src/Adblock.cpp @@ -1,73 +1,66 @@ #include "stdafx.h" extern bool g_Log; +extern bool g_Skip_wpad; + std::ofstream Log_DNS; -Adblock g_Adsblock; +Adsblock g_Adsblock; -Adblock::Adblock () { - SecureZeroMemory (dns_ipaddr, sizeof (dns_ipaddr)); - pSrvList = nullptr; - enable = false; +Adsblock::Adsblock () { + isActive = false; + pSrvList = (PIP4_ARRAY)LocalAlloc (LPTR, sizeof (IP4_ARRAY)); } -void Adblock::activate () { - enable = true; -} -void Adblock::deactivate () { - enable = false; -} +void Adsblock::setDNSIP (const char* ip) { -bool Adblock::init (const char* configFile) { - if (!isEnable ()) { - return false; - } - pSrvList = (PIP4_ARRAY)LocalAlloc (LPTR, sizeof (IP4_ARRAY)); if (nullptr != pSrvList) { - GetPrivateProfileString ("Config", - "AdGuardDNS_IP", - "176.103.130.134", - dns_ipaddr, - INET_ADDRSTRLEN, - configFile); + // https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inetptonw if (1 == InetPton (AF_INET, - dns_ipaddr, // dns server ip + ip, // dns server ip &pSrvList->AddrArray[0])) { pSrvList->AddrCount = 1; if (g_Log) - Log_DNS << "AdGuard DNS Server - " << dns_ipaddr << std::endl; - return true; + Log_DNS << "AdGuard DNS Server - " << ip << std::endl; + isActive = true; } else { if (g_Log) Log_DNS << "AdGuard DNS Disable - InetPton " - << dns_ipaddr << " failed!" << std::endl; + << ip << " failed!" << std::endl; } } else { if (g_Log) - Log_DNS << "AdGuard DNS Disable - " - << "pSrvList LocalAlloc failed!" << std::endl; + Log_DNS << __FUNCTION__ + << " pSrvList LocalAlloc failed!" << std::endl; } - return false; } -bool Adblock::isblock (const char* nodename) { +bool Adsblock::isblock (const char* nodename) { + + // Web Proxy Auto-Discovery (WPAD) + if (0 == _stricmp (nodename, "wpad")) + return g_Skip_wpad ? true : false; + + if (nullptr != strstr (nodename, "google")) + return true; + + if (nullptr != strstr (nodename, "doubleclick.")) + return true; // AdGuard DNS - if (isEnable ()) { + if (isActive) { for (auto allow : whitelist) { if (0 == _stricmp (allow.c_str (), nodename)) return false; } - for (auto block : blacklist) { if (0 == _stricmp (block.c_str (), nodename)) return true; } - - int result = adguardlookup (nodename); + int result = lookup (nodename); if (1 == result) { // return 1 block blacklist.push_back (nodename); // add to blacklist return true; @@ -80,7 +73,7 @@ bool Adblock::isblock (const char* nodename) { return false; } -int Adblock::adguardlookup (const char* nodename) { +int Adsblock::lookup (const char* nodename) { bool isBlock = false; DNS_STATUS dnsStatus = 0; @@ -89,7 +82,7 @@ int Adblock::adguardlookup (const char* nodename) { dnsStatus = DnsQuery (nodename, DNS_TYPE_A, DNS_QUERY_WIRE_ONLY, - pSrvList, + Adsblock::pSrvList, &QueryResult, NULL); // Reserved @@ -106,7 +99,7 @@ int Adblock::adguardlookup (const char* nodename) { } else { if (g_Log) - Log_DNS << "AdGuard DNS Error: " << dnsStatus + Log_DNS << __FUNCTION__ << " host:" << nodename << " status:" << dnsStatus << " GLE: " << GetLastError () << std::endl; return -1; } @@ -117,10 +110,12 @@ int Adblock::adguardlookup (const char* nodename) { return 0; } -void Adblock::destroy () { - if (nullptr != pSrvList) +void Adsblock::destroy () { + if (nullptr != pSrvList) { LocalFree (pSrvList); + pSrvList = nullptr; + } } -Adblock::~Adblock () { +Adsblock::~Adsblock () { } \ No newline at end of file diff --git a/src/Adblock.h b/src/Adblock.h index fd1119c..70fd57b 100644 --- a/src/Adblock.h +++ b/src/Adblock.h @@ -5,22 +5,18 @@ // blogs.msdn.microsoft.com/winsdk/2014/12/17/ // dnsquery-sample-to-loop-through-multiple-ip-addresses/ -class Adblock { +class Adsblock { public: - Adblock::Adblock (); - Adblock::~Adblock (); - bool init (const char* configFile); + Adsblock::Adsblock (); + Adsblock::~Adsblock (); + void setDNSIP (const char* ip); bool isblock (const char* nodename); - bool isEnable () { return enable; }; void destroy (); - void activate (); - void deactivate (); private: - bool enable; PIP4_ARRAY pSrvList; - char dns_ipaddr[INET_ADDRSTRLEN]; + bool isActive; std::vector blacklist; std::vector whitelist; - int adguardlookup (const char* nodename); + int lookup (const char* nodename); }; \ No newline at end of file diff --git a/src/Resource.rc b/src/Resource.rc index ed17330..61546d1 100644 --- a/src/Resource.rc +++ b/src/Resource.rc @@ -79,7 +79,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,1 - PRODUCTVERSION 0,44,0,0 + PRODUCTVERSION 0,46,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -100,7 +100,7 @@ BEGIN VALUE "LegalCopyright", "Copyright (C) 2019" VALUE "OriginalFilename", "BlockTheSpot.dll" VALUE "ProductName", "BlockTheSpot" - VALUE "ProductVersion", "0.44.0.0" + VALUE "ProductVersion", "0.46.0.0" END END BLOCK "VarFileInfo" diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 458c818..c713a2e 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -6,35 +6,39 @@ extern bool g_Skip_wpad; extern bool g_WinHttpReadDataFix; extern std::ofstream Log_DNS; -extern std::ofstream Log_GetAddr; extern std::ofstream Log_WinHttp; -extern Adblock g_Adsblock; +extern Adsblock g_Adsblock; -const char* configFile = "./config.ini"; +void init_log () { + Log_DNS.open ("log_dnsquery.txt", + std::ios::out | std::ios::app); + Log_WinHttp.open ("log_winhttp.txt", + std::ios::out | std::ios::app); +} void init_config () { - if (0 == GetPrivateProfileInt ("Config", "AdGuardDNS", 1, configFile)) - g_Adsblock.deactivate (); - else - g_Adsblock.activate (); + const char* configFile = "./config.ini"; + char IP[INET_ADDRSTRLEN]; - if (1 == GetPrivateProfileInt ("Config", "Log", 0, configFile)) + if (1 == GetPrivateProfileInt ("Config", "Log", 0, configFile)) { g_Log = true; + init_log (); + } if (1 == GetPrivateProfileInt ("Config", "Skip_wpad", 0, configFile)) g_Skip_wpad = true; if (1 == GetPrivateProfileInt ("Config", "WinHttpReadDataFix", 0, configFile)) g_WinHttpReadDataFix = true; -} -void init_log () { - if (g_Log) { - Log_DNS.open ("log_dnsquery.txt", - std::ios::out | std::ios::app); - Log_GetAddr.open ("log_getaddrinfo.txt", - std::ios::out | std::ios::app); - Log_WinHttp.open ("log_winhttp.txt", - std::ios::out | std::ios::app); + if (1 == GetPrivateProfileInt ("Config", "AdGuardDNS", 1, configFile)) { + GetPrivateProfileString ("Config", + "AdGuardDNS_IP", + "176.103.130.134", + IP, + INET_ADDRSTRLEN, + configFile); + g_Adsblock.setDNSIP (IP); } + } BOOL APIENTRY DllMain (HMODULE hModule, @@ -50,12 +54,6 @@ BOOL APIENTRY DllMain (HMODULE hModule, { case DLL_PROCESS_ATTACH: init_config (); - init_log (); - - if (false == g_Adsblock.init (configFile)) { - if (g_Log) Log_DNS << "AdGuard DNS Disable!" << std::endl; - g_Adsblock.deactivate (); - } // block ads banner by hostname. InstallHookApi ("ws2_32.dll", "getaddrinfo", getaddrinfohook); @@ -65,7 +63,6 @@ BOOL APIENTRY DllMain (HMODULE hModule, case DLL_PROCESS_DETACH: if (g_Log) { Log_DNS.close (); - Log_GetAddr.close (); Log_WinHttp.close (); } g_Adsblock.destroy (); diff --git a/src/hosts.cpp b/src/hosts.cpp index e37168f..19a5643 100644 --- a/src/hosts.cpp +++ b/src/hosts.cpp @@ -4,10 +4,10 @@ bool g_Log = false; bool g_Skip_wpad = false; bool g_WinHttpReadDataFix = false; -std::ofstream Log_GetAddr; std::ofstream Log_WinHttp; +extern std::ofstream Log_DNS; -extern Adblock g_Adsblock; +extern Adsblock g_Adsblock; int WINAPI getaddrinfohook (DWORD RetAddr, pfngetaddrinfo fngetaddrinfo, @@ -16,34 +16,23 @@ int WINAPI getaddrinfohook (DWORD RetAddr, const struct addrinfo* hints, struct addrinfo** res) { - auto adguardlookup = std::async (std::launch::async, &Adblock::isblock, g_Adsblock, nodename); - + auto lookup = std::async (std::launch::async, &Adsblock::isblock, g_Adsblock, nodename); + // future/async auto result = fngetaddrinfo (nodename, servname, hints, res); - bool isBlock = adguardlookup.get (); - - if (0 == result) { // GetAddrInfo return 0 on success - // Web Proxy Auto-Discovery (WPAD) - if (g_Skip_wpad && 0 == _stricmp (nodename, "wpad")) - return WSAHOST_NOT_FOUND; - - if (nullptr != strstr (nodename, "google")) - return true; + bool isBlock = lookup.get (); + if (0 == result && isBlock) { // GetAddrInfo return 0 on success - if (nullptr != strstr (nodename, "doubleclick.")) - return true; - - if (isBlock) { - for (auto ptr = *res; nullptr != ptr; ptr = ptr->ai_next) { - auto ipv4 = (struct sockaddr_in*)ptr->ai_addr; - ipv4->sin_addr.S_un.S_addr = INADDR_ANY; - } - if (g_Log) { - Log_GetAddr << nodename << " blocked" << std::endl; - } + for (auto ptr = *res; nullptr != ptr; ptr = ptr->ai_next) { + auto ipv4 = (struct sockaddr_in*)ptr->ai_addr; + //memset (&ipv4->sin_addr.S_un.S_addr, 0x0, sizeof ULONG); + ipv4->sin_addr.S_un.S_addr = INADDR_ANY; + } + if (g_Log) { + Log_DNS << nodename << " blocked" << std::endl; } } return result; @@ -79,7 +68,8 @@ int WINAPI winhttpreaddatahook (DWORD RetAddr, Log_WinHttp << data << std::endl; } if (g_WinHttpReadDataFix) return false; - memset (lpBuffer, 0x20, dwNumberOfBytesToRead); + memset (lpBuffer, 0x0, dwNumberOfBytesToRead); + //SecureZeroMemory (lpBuffer, dwNumberOfBytesToRead); return true; }