Skip to content

Commit 0dc599e

Browse files
iostreamiostream
authored andcommitted
Add fbsbx, improve logger
1 parent 5f90b1e commit 0dc599e

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

src/Logger.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
#include <string>
55
#include "Config.h"
66

7-
extern Config g_Config;
87
class Logger {
98

109
public:
11-
~Logger () {
10+
Logger (Config* config) {
11+
12+
m_isEnable = config->getConfig ("Log");
1213
if (m_isEnable) {
13-
m_log.flush ();
14-
m_log.close ();
14+
m_log.open ("blockthespot_log.txt", std::ios::out | std::ios::app);
15+
m_log << "BlockTheSpot - Build date: " << __TIMESTAMP__ << std::endl;
1516
}
1617
}
17-
void setLogfile (std::string_view logFile) {
18-
m_filename = logFile;
19-
m_isEnable = g_Config.getConfig ("Log");
18+
19+
~Logger () {
2020
if (m_isEnable) {
21-
m_log.open (m_filename, std::ios::out | std::ios::app);
22-
m_log << "BlockTheSpot - Build date: " << __TIMESTAMP__ << std::endl;
21+
m_log.flush ();
22+
m_log.close ();
2323
}
2424
}
2525

@@ -29,8 +29,7 @@ class Logger {
2929
}
3030

3131
private:
32-
std::string m_filename;
33-
bool m_isEnable;
32+
bool m_isEnable = false;
3433
std::ofstream m_log;
3534

3635
};

src/Modify.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ BYTE* FindPattern (BYTE* dwAddress, DWORD dwSize, BYTE* pbSig, char* szMask)
3131
return 0;
3232
}
3333

34-
DWORD WINAPI KillBanner (LPVOID)
34+
DWORD WINAPI KillBanner (LPVOID conf)
3535
{
36+
auto config = static_cast<Config*>(conf);
37+
auto* logger = new Logger (config);
3638
HMODULE hModule = GetModuleHandle (NULL);
3739
MODULEINFO mInfo = { 0 };
3840
if (GetModuleInformation (GetCurrentProcess (), hModule, &mInfo, sizeof (MODULEINFO))) {
39-
41+
logger->Log ("GetModuleInformation OK!");
4042
LPVOID skipPod = FindPattern ((uint8_t*)hModule, mInfo.SizeOfImage, (BYTE*)"\x83\xC4\x08\x84\xC0\x0F\x84\x00\x04\x00\x00", "xxxxxxxxxxx");
4143

4244
if (skipPod)
@@ -49,12 +51,16 @@ DWORD WINAPI KillBanner (LPVOID)
4951
VirtualProtect ((char*)skipPod + 6, 1, PAGE_EXECUTE_READWRITE, &oldProtect);
5052
memset ((char*)skipPod + 6, 0xE9, 1);
5153
VirtualProtect ((char*)skipPod + 6, 1, oldProtect, &oldProtect);
52-
g_Logger.Log ("main process - patch success!");
54+
logger->Log ("main process - patch success!");
5355
}
5456
else {
55-
g_Logger.Log ("main process - patch failed!");
57+
logger->Log ("main process - patch failed!");
5658
}
5759

60+
}
61+
else {
62+
logger->Log ("GetModuleInformation failed!");
5863
}
64+
5965
return 0;
6066
}

src/Modify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
#include "stdafx.h"
33

44

5-
DWORD WINAPI KillBanner (LPVOID);
5+
DWORD WINAPI KillBanner (LPVOID config);

src/dllmain.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
#include "Modify.h"
77

88
extern _getaddrinfo getaddrinfo_orig;
9-
Logger g_Logger;
10-
Config g_Config;
11-
12-
139

1410
BOOL APIENTRY DllMain (HMODULE hModule,
1511
DWORD ul_reason_for_call, LPVOID lpReserved)
@@ -21,22 +17,25 @@ BOOL APIENTRY DllMain (HMODULE hModule,
2117
switch (ul_reason_for_call)
2218
{
2319
case DLL_PROCESS_ATTACH:
24-
if (std::string_view::npos == procname.find ("--type=") && false == g_Config.getConfig("Block_BannerOnly")) {
20+
auto* config = new Config();
21+
if (std::string_view::npos == procname.find ("--type=") && false == config->getConfig("Block_BannerOnly")) {
2522
// block ads request - main process
26-
CreateThread (NULL, NULL, KillBanner, NULL, 0, NULL);
27-
g_Logger.setLogfile ("main_log.txt");
23+
CreateThread (NULL, NULL, KillBanner, config, 0, NULL);
24+
//g_Logger.setLogfile ("main_log.txt");
2825
}
2926
else if (std::string_view::npos != procname.find ("--type=utility")) {
3027
// block ads banner by hostname - utility process
31-
g_Logger.setLogfile ("utility_log.txt");
28+
//g_Logger.setLogfile ("utility_log.txt");
29+
auto* log = new Logger (config);
3230
getaddrinfo_orig = getaddrinfo;
3331
if (getaddrinfo_orig) {
3432
Mhook_SetHook ((PVOID*)&getaddrinfo_orig, getaddrinfo_hook);
35-
g_Logger.Log ("Mhook_SetHook - getaddrinfo success!");
33+
log->Log ("Mhook_SetHook - getaddrinfo success!");
3634
}
3735
else {
38-
g_Logger.Log ("Mhook_SetHook - getaddrinfo failed!");
36+
log->Log ("Mhook_SetHook - getaddrinfo failed!");
3937
}
38+
log->~Logger ();
4039
}
4140
break;
4241
}

src/hosts.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
#include "Config.h"
33
#include "Logger.h"
44

5-
extern Logger g_Logger;
6-
extern Config g_Config;
5+
//extern Logger g_Logger;
6+
//extern Config g_Config;
77

88
_getaddrinfo getaddrinfo_orig;
99

10-
const std::vector<std::string_view> blockList = { "google", "doubleclick", "qualaroo.com"/*, "fbsbx.com"*/ };
10+
const std::vector<std::string_view> blockList = { "google", "doubleclick", "qualaroo.com", "fbsbx.com" };
1111

1212
// check if ads hostname
13-
bool is_blockhost (std::string_view nodename) {
14-
static bool wpad = g_Config.getConfig ("Skip_wpad");
13+
bool is_blockhost (std::string_view nodename, Config* config) {
14+
15+
16+
static bool wpad = config->getConfig ("Skip_wpad");
1517
if (0 == nodename.compare ("wpad"))
1618
return wpad ? true : false;
1719
for (auto i : blockList) {
@@ -27,22 +29,25 @@ int WSAAPI getaddrinfo_hook (
2729
_In_opt_ const ADDRINFOA* hints,
2830
_Out_ PADDRINFOA* res)
2931
{
32+
static auto* config = new Config ();
33+
static auto* logger = new Logger (config);
3034
if (nodename == nullptr)
3135
return getaddrinfo_orig (nodename, servname, hints, res);
3236

3337
std::string nnodename (nodename);
34-
auto isblock = std::async (std::launch::async, is_blockhost, nnodename);
38+
39+
auto isblock = std::async (std::launch::async, is_blockhost, nnodename, config);
3540
auto result = getaddrinfo_orig (nodename, servname, hints, res);
3641
if (0 == result) {
3742
if (isblock.get ()) {
3843
for (auto ptr = *res; nullptr != ptr; ptr = ptr->ai_next) {
3944
auto ipv4 = reinterpret_cast<sockaddr_in*>(ptr->ai_addr);
4045
ipv4->sin_addr.S_un.S_addr = INADDR_ANY;
4146
}
42-
g_Logger.Log ("blocked - " + nnodename);
47+
logger->Log ("blocked - " + nnodename);
4348
}
4449
else {
45-
g_Logger.Log ("allowed - " + nnodename);
50+
logger->Log ("allowed - " + nnodename);
4651
}
4752
}
4853
return result;

0 commit comments

Comments
 (0)