diff --git a/README.md b/README.md
index 6d5b40a..0e03819 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,8 @@
A multi-purpose adblocker and skip bypass for the Windows Spotify Desktop Application.
Please support Spotify by purchasing premium
- Current Version: 0.39
- Last updated: 27 December 2019
+ Current Version: 0.40
+ Last updated: 5 January 2020
Last tested version: 1.1.22.633.g1bab253a
Important Notice(s)
diff --git a/chrome_elf.zip b/chrome_elf.zip
index e2af27e..638a753 100644
Binary files a/chrome_elf.zip and b/chrome_elf.zip differ
diff --git a/src/Resource.rc b/src/Resource.rc
index 36a4e5c..c68c863 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,39,0,0
+ PRODUCTVERSION 0,40,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.39.0.0"
+ VALUE "ProductVersion", "0.40.0.0"
END
END
BLOCK "VarFileInfo"
diff --git a/src/dllmain.cpp b/src/dllmain.cpp
index 8efdda3..d488c94 100644
--- a/src/dllmain.cpp
+++ b/src/dllmain.cpp
@@ -9,10 +9,11 @@ extern bool g_WinHttpReadDataFix;
extern std::ofstream Log_DNS;
extern std::ofstream Log_GetAddr;
extern std::ofstream Log_WinHttp;
+extern std::vector blacklist;
-PIP4_ARRAY pSrvList = NULL;
+PIP4_ARRAY pSrvList = nullptr;
-void Init_config () {
+void init_config () {
if (0 == GetPrivateProfileInt ("Config", "AdGuardDNS", 1, "./config.ini"))
g_UseAdGuard = false;
if (0 < GetPrivateProfileInt ("Config", "Log", 0, "./config.ini"))
@@ -23,7 +24,7 @@ void Init_config () {
g_WinHttpReadDataFix = true;
}
-void Init_log () {
+void init_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);
@@ -32,9 +33,9 @@ void Init_log () {
Log_DNS << "AdGuard DNS Disable!\n";
}
-void Init_DNS () {
+void init_DNS () {
pSrvList = (PIP4_ARRAY)LocalAlloc (LPTR, sizeof (IP4_ARRAY));
- if (pSrvList) {
+ if (nullptr != pSrvList) {
// https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inetptonw
if (1 == InetPton (AF_INET,
"176.103.130.134", // dns server ip
@@ -42,11 +43,13 @@ void Init_DNS () {
// "Family protection"
// adguard.com/en/adguard-dns/overview.html
pSrvList->AddrCount = 1;
- return;
}
}
- //
- g_UseAdGuard = false;
+ else {
+ if (g_Log)
+ Log_DNS << "AdGuard DNS Disable - pSrvList LocalAlloc failed!\n";
+ g_UseAdGuard = false;
+ }
}
BOOL APIENTRY DllMain (HMODULE hModule,
@@ -54,29 +57,32 @@ BOOL APIENTRY DllMain (HMODULE hModule,
LPVOID lpReserved
)
{
- // only utility process and main process
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- if (strstr (GetCommandLine (), "--type=utility") || !strstr (GetCommandLine (), "--type=")) {
- Init_config ();
- if (g_UseAdGuard) Init_DNS ();
- if (g_Log) Init_log ();
+ if (strstr (GetCommandLine (), "--type=utility") ||
+ !strstr (GetCommandLine (), "--type=")) {
+
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ init_config ();
+ if (g_Log) init_log ();
+ if (g_UseAdGuard) init_DNS ();
+ // Web Proxy Auto-Discovery (WPAD)
+ if (g_Skip_wpad) blacklist.push_back ("wpad");
// block ads banner by hostname.
InstallHookApi ("ws2_32.dll", "getaddrinfo", getaddrinfohook);
// block ads by manipulate json response.
InstallHookApi ("Winhttp.dll", "WinHttpReadData", winhttpreaddatahook);
+ break;
+ case DLL_PROCESS_DETACH:
+ if (g_Log) {
+ Log_DNS.close ();
+ Log_GetAddr.close ();
+ Log_WinHttp.close ();
+ }
+ if (nullptr != pSrvList)
+ LocalFree (pSrvList);
+ break;
}
- break;
- case DLL_PROCESS_DETACH:
- if (g_Log) {
- Log_DNS.close ();
- Log_GetAddr.close ();
- Log_WinHttp.close ();
- }
- if (pSrvList)
- LocalFree (pSrvList);
- break;
}
return TRUE;
}
diff --git a/src/hosts.cpp b/src/hosts.cpp
index 62cc195..5437672 100644
--- a/src/hosts.cpp
+++ b/src/hosts.cpp
@@ -24,7 +24,7 @@ bool adguard_dnsblock (const char* nodename) {
bool isBlock = false;
static int fail_count = 0;
if (!g_UseAdGuard) return false;
-
+
if (fail_count > 5) {
if (g_Log) {
Log_DNS << "AdGuard DNS lookup disable! fail resolve > 5 times" << '\n';
@@ -33,15 +33,6 @@ bool adguard_dnsblock (const char* nodename) {
return false;
}
- for (auto block : blacklist) {
- if (0 == _stricmp (block.c_str (), nodename))
- return true;
- }
- for (auto allow : whitelist) {
- if (0 == _stricmp (allow.c_str (), nodename))
- return false;
- }
-
dnsStatus = DnsQuery (nodename,
DNS_TYPE_A,
DNS_QUERY_WIRE_ONLY,
@@ -54,16 +45,13 @@ bool adguard_dnsblock (const char* nodename) {
for (auto p = QueryResult; p; p = p->pNext) {
if (0 == p->Data.A.IpAddress) {
isBlock = true; // AdGuard Block
- blacklist.push_back (nodename); // add to blacklist
break; // no more processing
}
}
- DnsRecordListFree (QueryResult, DnsFreeRecordList);
-
- if (!isBlock)
- whitelist.push_back (nodename); // add to whitelist
+ DnsRecordListFree (QueryResult, DnsFreeRecordList);
} // QueryResult
- } else { // dnsStatus
+ }
+ else { // dnsStatus
fail_count++;
}
if (g_Log && isBlock) {
@@ -80,25 +68,36 @@ int WINAPI getaddrinfohook (DWORD RetAddr,
const struct addrinfo* hints,
struct addrinfo** res)
{
-
auto result = fngetaddrinfo (nodename,
servname,
hints,
res);
+
if (0 == result) { // GetAddrInfo return 0 on success
- if (NULL != strstr (nodename, "google"))
+
+ if (nullptr != strstr (nodename, "google"))
return WSANO_RECOVERY;
- // Web Proxy Auto-Discovery (WPAD)
- if (0 == _stricmp (nodename, "wpad"))
- return g_Skip_wpad ? WSANO_RECOVERY : result;
+ for (auto block : blacklist) {
+ if (0 == _stricmp (block.c_str (), nodename))
+ return WSANO_RECOVERY;
+ }
+
+ for (auto allow : whitelist) {
+ if (0 == _stricmp (allow.c_str (), nodename))
+ return result;
+ }
// AdGuard DNS
- if (adguard_dnsblock (nodename))
+ if (adguard_dnsblock (nodename)) {
+ blacklist.push_back (nodename); // add to blacklist
return WSANO_RECOVERY;
-
- if (g_Log) {
- Log_GetAddr << nodename << '\n';
+ }
+ else {
+ whitelist.push_back (nodename); // add to whitelist
+ if (g_Log) {
+ Log_GetAddr << nodename << '\n';
+ }
}
}
return result;
@@ -120,12 +119,12 @@ int WINAPI winhttpreaddatahook (DWORD RetAddr,
}
char* pdest = strstr ((LPSTR)lpBuffer, "{\"login_url");
- if (pdest != NULL) {
+ if (nullptr != pdest) {
return true;
}
pdest = strstr ((LPSTR)lpBuffer, "{\"credentials");
- if (pdest != NULL) {
+ if (nullptr != pdest) {
return true;
}
if (g_Log) {