Skip to content

Commit 59eac0e

Browse files
author
mrpond
committed
v0.40 code improvement
1 parent 57d35a0 commit 59eac0e

File tree

5 files changed

+62
-57
lines changed

5 files changed

+62
-57
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<h4 align="center">A multi-purpose adblocker and skip bypass for the <strong>Windows</strong> Spotify Desktop Application.</h4>
44
<h5 align="center">Please support Spotify by purchasing premium</h5>
55
<p align="center">
6-
<strong>Current Version:</strong> 0.39 <br>
7-
<strong>Last updated:</strong> 27 December 2019 <br>
6+
<strong>Current Version:</strong> 0.40 <br>
7+
<strong>Last updated:</strong> 5 January 2020<br>
88
<strong>Last tested version:</strong> 1.1.22.633.g1bab253a
99
</p>
1010
<h4 align="center">Important Notice(s)</h4>

chrome_elf.zip

51 Bytes
Binary file not shown.

src/Resource.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
7979

8080
VS_VERSION_INFO VERSIONINFO
8181
FILEVERSION 1,0,0,1
82-
PRODUCTVERSION 0,39,0,0
82+
PRODUCTVERSION 0,40,0,0
8383
FILEFLAGSMASK 0x3fL
8484
#ifdef _DEBUG
8585
FILEFLAGS 0x1L
@@ -100,7 +100,7 @@ BEGIN
100100
VALUE "LegalCopyright", "Copyright (C) 2019"
101101
VALUE "OriginalFilename", "BlockTheSpot.dll"
102102
VALUE "ProductName", "BlockTheSpot"
103-
VALUE "ProductVersion", "0.39.0.0"
103+
VALUE "ProductVersion", "0.40.0.0"
104104
END
105105
END
106106
BLOCK "VarFileInfo"

src/dllmain.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ extern bool g_WinHttpReadDataFix;
99
extern std::ofstream Log_DNS;
1010
extern std::ofstream Log_GetAddr;
1111
extern std::ofstream Log_WinHttp;
12+
extern std::vector<std::string> blacklist;
1213

13-
PIP4_ARRAY pSrvList = NULL;
14+
PIP4_ARRAY pSrvList = nullptr;
1415

15-
void Init_config () {
16+
void init_config () {
1617
if (0 == GetPrivateProfileInt ("Config", "AdGuardDNS", 1, "./config.ini"))
1718
g_UseAdGuard = false;
1819
if (0 < GetPrivateProfileInt ("Config", "Log", 0, "./config.ini"))
@@ -23,7 +24,7 @@ void Init_config () {
2324
g_WinHttpReadDataFix = true;
2425
}
2526

26-
void Init_log () {
27+
void init_log () {
2728
Log_DNS.open ("log_dnsquery.txt", std::ios::out | std::ios::app);
2829
Log_GetAddr.open ("log_getaddrinfo.txt", std::ios::out | std::ios::app);
2930
Log_WinHttp.open ("log_winhttp.txt", std::ios::out | std::ios::app);
@@ -32,51 +33,56 @@ void Init_log () {
3233
Log_DNS << "AdGuard DNS Disable!\n";
3334
}
3435

35-
void Init_DNS () {
36+
void init_DNS () {
3637
pSrvList = (PIP4_ARRAY)LocalAlloc (LPTR, sizeof (IP4_ARRAY));
37-
if (pSrvList) {
38+
if (nullptr != pSrvList) {
3839
// https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inetptonw
3940
if (1 == InetPton (AF_INET,
4041
"176.103.130.134", // dns server ip
4142
&pSrvList->AddrArray[0])) {
4243
// "Family protection"
4344
// adguard.com/en/adguard-dns/overview.html
4445
pSrvList->AddrCount = 1;
45-
return;
4646
}
4747
}
48-
//
49-
g_UseAdGuard = false;
48+
else {
49+
if (g_Log)
50+
Log_DNS << "AdGuard DNS Disable - pSrvList LocalAlloc failed!\n";
51+
g_UseAdGuard = false;
52+
}
5053
}
5154

5255
BOOL APIENTRY DllMain (HMODULE hModule,
5356
DWORD ul_reason_for_call,
5457
LPVOID lpReserved
5558
)
5659
{
57-
// only utility process and main process
58-
switch (ul_reason_for_call)
59-
{
60-
case DLL_PROCESS_ATTACH:
61-
if (strstr (GetCommandLine (), "--type=utility") || !strstr (GetCommandLine (), "--type=")) {
62-
Init_config ();
63-
if (g_UseAdGuard) Init_DNS ();
64-
if (g_Log) Init_log ();
60+
if (strstr (GetCommandLine (), "--type=utility") ||
61+
!strstr (GetCommandLine (), "--type=")) {
62+
63+
switch (ul_reason_for_call)
64+
{
65+
case DLL_PROCESS_ATTACH:
66+
init_config ();
67+
if (g_Log) init_log ();
68+
if (g_UseAdGuard) init_DNS ();
69+
// Web Proxy Auto-Discovery (WPAD)
70+
if (g_Skip_wpad) blacklist.push_back ("wpad");
6571
// block ads banner by hostname.
6672
InstallHookApi ("ws2_32.dll", "getaddrinfo", getaddrinfohook);
6773
// block ads by manipulate json response.
6874
InstallHookApi ("Winhttp.dll", "WinHttpReadData", winhttpreaddatahook);
75+
break;
76+
case DLL_PROCESS_DETACH:
77+
if (g_Log) {
78+
Log_DNS.close ();
79+
Log_GetAddr.close ();
80+
Log_WinHttp.close ();
81+
}
82+
if (nullptr != pSrvList)
83+
LocalFree (pSrvList);
84+
break;
6985
}
70-
break;
71-
case DLL_PROCESS_DETACH:
72-
if (g_Log) {
73-
Log_DNS.close ();
74-
Log_GetAddr.close ();
75-
Log_WinHttp.close ();
76-
}
77-
if (pSrvList)
78-
LocalFree (pSrvList);
79-
break;
8086
}
8187
return TRUE;
8288
}

src/hosts.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool adguard_dnsblock (const char* nodename) {
2424
bool isBlock = false;
2525
static int fail_count = 0;
2626
if (!g_UseAdGuard) return false;
27-
27+
2828
if (fail_count > 5) {
2929
if (g_Log) {
3030
Log_DNS << "AdGuard DNS lookup disable! fail resolve > 5 times" << '\n';
@@ -33,15 +33,6 @@ bool adguard_dnsblock (const char* nodename) {
3333
return false;
3434
}
3535

36-
for (auto block : blacklist) {
37-
if (0 == _stricmp (block.c_str (), nodename))
38-
return true;
39-
}
40-
for (auto allow : whitelist) {
41-
if (0 == _stricmp (allow.c_str (), nodename))
42-
return false;
43-
}
44-
4536
dnsStatus = DnsQuery (nodename,
4637
DNS_TYPE_A,
4738
DNS_QUERY_WIRE_ONLY,
@@ -54,16 +45,13 @@ bool adguard_dnsblock (const char* nodename) {
5445
for (auto p = QueryResult; p; p = p->pNext) {
5546
if (0 == p->Data.A.IpAddress) {
5647
isBlock = true; // AdGuard Block
57-
blacklist.push_back (nodename); // add to blacklist
5848
break; // no more processing
5949
}
6050
}
61-
DnsRecordListFree (QueryResult, DnsFreeRecordList);
62-
63-
if (!isBlock)
64-
whitelist.push_back (nodename); // add to whitelist
51+
DnsRecordListFree (QueryResult, DnsFreeRecordList);
6552
} // QueryResult
66-
} else { // dnsStatus
53+
}
54+
else { // dnsStatus
6755
fail_count++;
6856
}
6957
if (g_Log && isBlock) {
@@ -80,25 +68,36 @@ int WINAPI getaddrinfohook (DWORD RetAddr,
8068
const struct addrinfo* hints,
8169
struct addrinfo** res)
8270
{
83-
8471
auto result = fngetaddrinfo (nodename,
8572
servname,
8673
hints,
8774
res);
75+
8876
if (0 == result) { // GetAddrInfo return 0 on success
89-
if (NULL != strstr (nodename, "google"))
77+
78+
if (nullptr != strstr (nodename, "google"))
9079
return WSANO_RECOVERY;
9180

92-
// Web Proxy Auto-Discovery (WPAD)
93-
if (0 == _stricmp (nodename, "wpad"))
94-
return g_Skip_wpad ? WSANO_RECOVERY : result;
81+
for (auto block : blacklist) {
82+
if (0 == _stricmp (block.c_str (), nodename))
83+
return WSANO_RECOVERY;
84+
}
85+
86+
for (auto allow : whitelist) {
87+
if (0 == _stricmp (allow.c_str (), nodename))
88+
return result;
89+
}
9590

9691
// AdGuard DNS
97-
if (adguard_dnsblock (nodename))
92+
if (adguard_dnsblock (nodename)) {
93+
blacklist.push_back (nodename); // add to blacklist
9894
return WSANO_RECOVERY;
99-
100-
if (g_Log) {
101-
Log_GetAddr << nodename << '\n';
95+
}
96+
else {
97+
whitelist.push_back (nodename); // add to whitelist
98+
if (g_Log) {
99+
Log_GetAddr << nodename << '\n';
100+
}
102101
}
103102
}
104103
return result;
@@ -120,12 +119,12 @@ int WINAPI winhttpreaddatahook (DWORD RetAddr,
120119
}
121120

122121
char* pdest = strstr ((LPSTR)lpBuffer, "{\"login_url");
123-
if (pdest != NULL) {
122+
if (nullptr != pdest) {
124123
return true;
125124
}
126125

127126
pdest = strstr ((LPSTR)lpBuffer, "{\"credentials");
128-
if (pdest != NULL) {
127+
if (nullptr != pdest) {
129128
return true;
130129
}
131130
if (g_Log) {

0 commit comments

Comments
 (0)