Skip to content

Commit b567fd5

Browse files
author
mrpond
committed
performance improve, it should working smooth on wooden pc.
1 parent 53900ba commit b567fd5

File tree

5 files changed

+46
-49
lines changed

5 files changed

+46
-49
lines changed

README.md

Lines changed: 6 additions & 4 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.41 <br>
7-
<strong>Last updated:</strong> 6 January 2020<br>
6+
<strong>Current Version:</strong> 0.42 <br>
7+
<strong>Last updated:</strong> 7 January 2020<br>
88
<strong>Last tested version:</strong> 1.1.22.633.g1bab253a
99
</p>
1010
<h4 align="center">Important Notice(s)</h4>
@@ -34,14 +34,16 @@
3434
3. Rename your backup dll to chrome_elf.dll
3535

3636
#### Note:
37+
* Starting from v0.42, AdGuardDNS look up in config.ini are disable by default.
3738
* Built-in AdGuard DNS lookup, paranoid people may see additional DNS traffic UDP(53)
3839
going out to Adguard DNS Server.
3940
* if you can't reach AdGuard DNS for some reason, things still working as expected.
4041

4142
#### Known Issues and Caveats:
42-
* Ads Blocking may not work if you had proxy use in network.
43+
* Ads banner maybe appear if you network use 'Web Proxy Auto-Discovery Protocol'
44+
https://en.wikipedia.org/wiki/Web_Proxy_Auto-Discovery_Protocol
4345
set Skip_wpad in config.ini to 1 may help.
44-
* Ads Blocking on system may not work e.g.(windows 7)
46+
* On windows 7, Ads Blocking may not work
4547
set WinHttpReadDataFix in config.ini to 1 may help.
4648
* Built-in AdGuard DNS lookup, maybe cause application slowdown,
4749
set AdGuardDNS in config.ini to 0 to turn this feature off.

chrome_elf.zip

-154 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,41,0,0
82+
PRODUCTVERSION 0,42,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.41.0.0"
103+
VALUE "ProductVersion", "0.42.0.0"
104104
END
105105
END
106106
BLOCK "VarFileInfo"

src/dllmain.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ 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;
1312

1413
PIP4_ARRAY pSrvList = nullptr;
1514

@@ -68,8 +67,7 @@ BOOL APIENTRY DllMain (HMODULE hModule,
6867
if (g_Log)
6968
Log_DNS << "AdGuard DNS Disable - pSrvList LocalAlloc failed!\n";
7069
}
71-
// Web Proxy Auto-Discovery (WPAD)
72-
if (g_Skip_wpad) blacklist.push_back ("wpad");
70+
7371
// block ads banner by hostname.
7472
InstallHookApi ("ws2_32.dll", "getaddrinfo", getaddrinfohook);
7573
// block ads by manipulate json response.

src/hosts.cpp

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,10 @@ std::vector<std::string> whitelist;
1818
// blogs.msdn.microsoft.com/winsdk/2014/12/17/
1919
// dnsquery-sample-to-loop-through-multiple-ip-addresses/
2020

21-
bool adguard_dnsblock (const char* nodename) {
21+
int adguard_dnsblock (const char* nodename) {
2222
DNS_STATUS dnsStatus;
2323
PDNS_RECORD QueryResult;
2424
bool isBlock = false;
25-
static int fail_count = 0;
26-
if (!g_UseAdGuard) return false;
27-
28-
if (fail_count > 5) {
29-
if (g_Log) {
30-
Log_DNS << "AdGuard DNS lookup disable! fail resolve > 5 times" << std::endl;
31-
}
32-
g_UseAdGuard = false;
33-
return false;
34-
}
3525

3626
dnsStatus = DnsQuery (nodename,
3727
DNS_TYPE_A,
@@ -40,70 +30,77 @@ bool adguard_dnsblock (const char* nodename) {
4030
&QueryResult,
4131
NULL); // Reserved
4232

33+
if (0 != dnsStatus) return -1;
34+
4335
if (0 == dnsStatus) {
4436
if (QueryResult) {
4537
for (auto p = QueryResult; p; p = p->pNext) {
46-
if (0 == p->Data.A.IpAddress) {
38+
if (INADDR_ANY == p->Data.A.IpAddress) {
4739
isBlock = true; // AdGuard Block
4840
break; // no more processing
4941
}
5042
}
5143
DnsRecordListFree (QueryResult, DnsFreeRecordList);
5244
} // QueryResult
5345
}
54-
else { // dnsStatus
55-
fail_count++;
56-
}
57-
if (g_Log && isBlock) {
58-
Log_DNS << nodename << " blocked" << std::endl;
59-
}
46+
6047
if (isBlock) {
61-
blacklist.push_back (nodename); // add to blacklist
62-
}
63-
else {
64-
whitelist.push_back (nodename); // add to whitelist
48+
return 1;
6549
}
66-
return isBlock;
50+
return 0;
6751
}
6852

6953
bool checkBlock (const char* nodename) {
7054

7155
if (nullptr != strstr (nodename, "google"))
7256
return true;
7357

74-
for (auto allow : whitelist) {
75-
if (0 == _stricmp (allow.c_str (), nodename))
76-
return false;
77-
}
58+
// AdGuard DNS
59+
if (g_UseAdGuard) {
60+
for (auto allow : whitelist) {
61+
if (0 == _stricmp (allow.c_str (), nodename))
62+
return false;
63+
}
7864

79-
for (auto block : blacklist) {
80-
if (0 == _stricmp (block.c_str (), nodename))
81-
return true;
82-
}
65+
for (auto block : blacklist) {
66+
if (0 == _stricmp (block.c_str (), nodename))
67+
return true;
68+
}
8369

84-
// AdGuard DNS
85-
if (adguard_dnsblock (nodename)) {
86-
return true;
70+
int result = adguard_dnsblock (nodename);
71+
if (1 == result) {
72+
blacklist.push_back (nodename); // add to blacklist
73+
return true;
74+
}
75+
else if (0 == result) {
76+
whitelist.push_back (nodename); // add to whitelist
77+
}
8778
}
88-
8979
return false;
9080
}
81+
9182
int WINAPI getaddrinfohook (DWORD RetAddr,
9283
pfngetaddrinfo fngetaddrinfo,
9384
const char* nodename,
9485
const char* servname,
9586
const struct addrinfo* hints,
9687
struct addrinfo** res)
9788
{
89+
9890
auto result = fngetaddrinfo (nodename,
9991
servname,
10092
hints,
10193
res);
102-
addrinfo* p = *res;
103-
if (0 == result && nullptr != p) { // GetAddrInfo return 0 on success
104-
if (p->ai_family == AF_INET && checkBlock (nodename)) {
105-
struct sockaddr_in* ipv4 = (struct sockaddr_in*)p->ai_addr;
106-
InetPton (AF_INET, "0.0.0.0", &(ipv4->sin_addr));
94+
95+
if (0 == result) { // GetAddrInfo return 0 on success
96+
// Web Proxy Auto-Discovery (WPAD)
97+
if (g_Skip_wpad && 0 == _stricmp (nodename, "wpad"))
98+
return WSAHOST_NOT_FOUND;
99+
if (checkBlock (nodename)) {
100+
for (auto ptr = *res; nullptr != ptr; ptr = ptr->ai_next) {
101+
auto ipv4 = (struct sockaddr_in*)ptr->ai_addr;
102+
ipv4->sin_addr.S_un.S_addr = INADDR_ANY;
103+
}
107104
if (g_Log) {
108105
Log_GetAddr << nodename << " blocked" << std::endl;
109106
}

0 commit comments

Comments
 (0)