From aba66397a3a9aff8db67940613bbf8aaa3c2c7bf Mon Sep 17 00:00:00 2001 From: ejaxh <39572540+ejaxh@users.noreply.github.com> Date: Sat, 29 Jul 2023 10:50:15 +0300 Subject: [PATCH] small changes (#475) --- install.ps1 | 61 +++++++++++++++++++--------- src/BlockTheSpot.vcxproj | 3 +- src/Debug.cpp | 85 ++++++++++++++++++++++++---------------- src/Modify.cpp | 76 +++++++++++++++++++++++------------ src/Modify.h | 10 ++--- src/assembly_code.asm | 5 ++- 6 files changed, 155 insertions(+), 85 deletions(-) diff --git a/install.ps1 b/install.ps1 index 0a7140c7..d60ead24 100644 --- a/install.ps1 +++ b/install.ps1 @@ -154,24 +154,13 @@ catch exit } -Write-Host "Downloading latest patch (chrome_elf.zip)...`n" -$elfPath = Join-Path -Path $PWD -ChildPath 'chrome_elf.zip' -try -{ - $uri = 'https://github.com/mrpond/BlockTheSpot/releases/latest/download/chrome_elf.zip' - Get-File -Uri $uri -TargetFile "$elfPath" -} -catch -{ - Write-Output $_ - Start-Sleep -} - -Expand-Archive -Force -LiteralPath "$elfPath" -DestinationPath $PWD -Remove-Item -LiteralPath "$elfPath" -Force - $spotifyInstalled = Test-Path -LiteralPath $spotifyExecutable -$unsupportedClientVersion = ($actualSpotifyClientVersion | Test-SpotifyVersion -MinimalSupportedVersion $minimalSupportedSpotifyVersion) -eq $false + +if (-not $spotifyInstalled) { + $unsupportedClientVersion = $true +} else { + $unsupportedClientVersion = ($actualSpotifyClientVersion | Test-SpotifyVersion -MinimalSupportedVersion $minimalSupportedSpotifyVersion) -eq $false +} if (-not $UpdateSpotify -and $unsupportedClientVersion) { @@ -187,7 +176,11 @@ if (-not $spotifyInstalled -or $UpdateSpotify -or $unsupportedClientVersion) $spotifySetupFilePath = Join-Path -Path $PWD -ChildPath 'SpotifyFullSetup.exe' try { - $uri = 'https://download.scdn.co/SpotifyFullSetup.exe' + if ([Environment]::Is64BitOperatingSystem) { # Check if the computer is running a 64-bit version of Windows + $uri = 'https://download.scdn.co/SpotifyFullSetupX64.exe' + } else { + $uri = 'https://download.scdn.co/SpotifyFullSetup.exe' + } Get-File -Uri $uri -TargetFile "$spotifySetupFilePath" } catch @@ -234,8 +227,38 @@ if (-not $spotifyInstalled -or $UpdateSpotify -or $unsupportedClientVersion) Stop-Process -Name Spotify Stop-Process -Name SpotifyWebHelper - Stop-Process -Name SpotifyFullSetup + if ([Environment]::Is64BitOperatingSystem) { # Check if the computer is running a 64-bit version of Windows + Stop-Process -Name SpotifyFullSetupX64 + } else { + Stop-Process -Name SpotifyFullSetup + } +} + +Write-Host "Downloading latest patch (chrome_elf.zip)...`n" +$elfPath = Join-Path -Path $PWD -ChildPath 'chrome_elf.zip' +try +{ + $bytes = [System.IO.File]::ReadAllBytes($spotifyExecutable) + $peHeader = [System.BitConverter]::ToUInt16($bytes[0x3C..0x3D], 0) + $is64Bit = $bytes[$peHeader + 4] -eq 0x64 + + if ($is64Bit) { + $uri = 'https://github.com/mrpond/BlockTheSpot/releases/latest/download/chrome_elf.zip' + } else { + Write-Host 'At the moment, the ad blocker may not work properly as the x86 architecture has not received a new update.' + $uri = 'https://github.com/mrpond/BlockTheSpot/releases/download/2023.5.20.80/chrome_elf.zip' + } + + Get-File -Uri $uri -TargetFile "$elfPath" } +catch +{ + Write-Output $_ + Start-Sleep +} + +Expand-Archive -Force -LiteralPath "$elfPath" -DestinationPath $PWD +Remove-Item -LiteralPath "$elfPath" -Force Write-Host 'Patching Spotify...' $patchFiles = (Join-Path -Path $PWD -ChildPath 'dpapi.dll'), (Join-Path -Path $PWD -ChildPath 'config.ini') diff --git a/src/BlockTheSpot.vcxproj b/src/BlockTheSpot.vcxproj index e4b2821c..5a4f10cf 100644 --- a/src/BlockTheSpot.vcxproj +++ b/src/BlockTheSpot.vcxproj @@ -53,7 +53,8 @@ Level3 _DEBUG;_CONSOLE;%(PreprocessorDefinitions) stdcpp20 - false + false + C:\cef;%(AdditionalIncludeDirectories) Console diff --git a/src/Debug.cpp b/src/Debug.cpp index 84b8b90d..e849a740 100644 --- a/src/Debug.cpp +++ b/src/Debug.cpp @@ -2,41 +2,56 @@ #ifndef NDEBUG -void print_test() { - // Example colors vector - std::vector colors = { Color::Red, Color::Green, Color::Blue }; +#include - // Example 6: Uppercase hexadecimal formatting - int hex_value = 255; - Print(colors, L"The uppercase hexadecimal value is {:X}.", hex_value); - // Output: The uppercase hexadecimal value is FF. +//void print_test() { +// // Example colors vector +// std::vector colors = { Color::Red, Color::Green, Color::Blue }; +// +// // Example 6: Uppercase hexadecimal formatting +// int hex_value = 255; +// Print(colors, L"The uppercase hexadecimal value is {:X}.", hex_value); +// // Output: The uppercase hexadecimal value is FF. +// +// // Example 7: Hexadecimal formatting with "0x" prefix +// int hex_value_with_prefix = 123; +// Print(colors, L"The hexadecimal value with prefix is {:#x}.", hex_value_with_prefix); +// // Output: The hexadecimal value with prefix is 0x7b. +// +// // Example 8: Multiple arguments with different format specifiers +// double temperature = 23.5; +// int year = 2023; +// std::wstring location = L"New York"; +// Print(colors, L"Date: {}, Temperature: {:.1f} °C, Year: {:d}, Location: {}.", L"July 22", temperature, year, location); +// // Output: Date: July 22, Temperature: 23.5 °C, Year: 2023, Location: New York. +// +// // Example 9: Handling missing arguments +// Print(colors, L"{} + {} = {}.", 2, 3); +// // Output: 2 + 3 = {}. +// +// // Example 10: Using the same argument multiple times +// int value = 7; +// Print(colors, L"{} * {} = {} and {} + {} = {}.", value, 3, value * 3, value, 5, value + 5); +// // Output: 7 * 3 = 21 and 7 + 5 = 12. +// +// // Example 11: Using non-default colors +// std::vector custom_colors = { Color::Yellow, Color::Magenta }; +// Print(custom_colors, L"Custom colors: {} and {}.", L"Yellow", L"Magenta"); +// // Output: Custom colors: Yellow and Magenta. +//} - // Example 7: Hexadecimal formatting with "0x" prefix - int hex_value_with_prefix = 123; - Print(colors, L"The hexadecimal value with prefix is {:#x}.", hex_value_with_prefix); - // Output: The hexadecimal value with prefix is 0x7b. - - // Example 8: Multiple arguments with different format specifiers - double temperature = 23.5; - int year = 2023; - std::wstring location = L"New York"; - Print(colors, L"Date: {}, Temperature: {:.1f} °C, Year: {:d}, Location: {}.", L"July 22", temperature, year, location); - // Output: Date: July 22, Temperature: 23.5 °C, Year: 2023, Location: New York. - - // Example 9: Handling missing arguments - Print(colors, L"{} + {} = {}.", 2, 3); - // Output: 2 + 3 = {}. - - // Example 10: Using the same argument multiple times - int value = 7; - Print(colors, L"{} * {} = {} and {} + {} = {}.", value, 3, value * 3, value, 5, value + 5); - // Output: 7 * 3 = 21 and 7 + 5 = 12. - - // Example 11: Using non-default colors - std::vector custom_colors = { Color::Yellow, Color::Magenta }; - Print(custom_colors, L"Custom colors: {} and {}.", L"Yellow", L"Magenta"); - // Output: Custom colors: Yellow and Magenta. -} +//typedef void(__stdcall* cef_string_utf16_clear_t)(void*); +//cef_string_utf16_clear_t cef_string_utf16_clear_orig = nullptr; +// +//void __stdcall hook_cef_string_utf16_clear(void* str) { +// std::wstring wstr(*reinterpret_cast(str)); +// if (wstr == L"xpui.js") { +// Print({ Color::Yellow }, L"[{}]: {:#x} | {}", L"cef_string_utf16_clear", _ReturnAddress(), wstr); +// _wsystem(L"pause"); +// } +// +// return cef_string_utf16_clear_orig(str); +//} DWORD WINAPI Debug(LPVOID lpParam) { @@ -46,6 +61,10 @@ DWORD WINAPI Debug(LPVOID lpParam) //Utils::PrintSymbols(L"chrome_elf.dll"); //print_test(); + //const auto cef_string_utf16_clear_func = PatternScanner::GetFunctionAddress(L"libcef.dll", L"cef_string_utf16_clear"); + //cef_string_utf16_clear_orig = (cef_string_utf16_clear_t)cef_string_utf16_clear_func.data(); + //cef_string_utf16_clear_func.hook((PVOID)hook_cef_string_utf16_clear); + }, L"DEBUG"); } catch (const std::exception& e) diff --git a/src/Modify.cpp b/src/Modify.cpp index 2873a673..4ff54379 100644 --- a/src/Modify.cpp +++ b/src/Modify.cpp @@ -18,15 +18,20 @@ static _cef_string_userfree_utf16_free cef_string_userfree_utf16_free_orig; static constexpr std::array block_list = { L"/ads/", L"/ad-logic/", L"/gabo-receiver-service/" }; -//static DWORD ret_addr = 0; -PatternScanner::ModuleInfo ZipScan; - #ifdef _WIN64 static std::wstring file_name; -std::uint64_t file_name_rcx = 0; -std::uint64_t ret_addr_file_name = 0; -std::uint64_t ret_addr_file_source = 0; +std::uintptr_t file_name_pointer; +std::uintptr_t ret_addr_file_name; +std::uintptr_t ret_addr_file_source; +PatternScanner::ModuleInfo ZipScan; #else +//static bool xpui_found = false; +static std::wstring file_name; +static std::uintptr_t file_name_pointer; +static std::uintptr_t ret_addr_file_name; +static std::uintptr_t ret_addr_file_source; +static PatternScanner::ModuleInfo ZipScan; + DWORD WINAPI get_url(DWORD pRequest) { DWORD retval = 0; @@ -68,9 +73,9 @@ void* cef_urlrequest_create_hook(void* request, void* client, void* request_cont #else #ifdef _WIN64 - auto get_url = *(std::uint64_t(__fastcall**)(std::uint64_t))((std::uint64_t)request + 48); - auto url_utf16 = get_url((std::uint64_t)request); - std::wstring url(reinterpret_cast(*reinterpret_cast(url_utf16))); + auto get_url = *(std::uintptr_t(__fastcall**)(void*))((std::uintptr_t)request + 48); + auto url_utf16 = get_url(request); + std::wstring url(*reinterpret_cast(url_utf16)); #else auto url_utf16 = get_url(reinterpret_cast(request)); std::wstring url(reinterpret_cast(get_str(url_utf16))); @@ -94,10 +99,9 @@ void* cef_urlrequest_create_hook(void* request, void* client, void* request_cont void WINAPI get_file_name() { try { - file_name = *reinterpret_cast(file_name_rcx); - //MessageBoxW(0,file_name.c_str(), 0, 0); - //Print(L"{}", zip_file_name); - //system("pause"); + file_name = *reinterpret_cast(file_name_pointer); + //Print(L"{}", file_name); + //_wsystem(L"pause"); } catch (const std::exception& e) { Print({ Color::Red }, L"[{}] {}", L"ERROR", e.what()); @@ -232,7 +236,7 @@ void WINAPI modify_source() const auto premium_free = PatternScanner::ScanFirst(ZipScan.base_address, ZipScan.image_size, L"\"free\"===e.session?.productState?.catalogue?.toLowerCase(),r=e=>null!==e.session?.productState&&1===parseInt(e.session?.productState?.ads,10),o=e=>\"premium\"===e.session?.productState?.catalogue?.toLowerCase(),"); if (premium_free.is_found()) { //Print(L"{}", premium_free.read()); - //system("pause"); + //_wsystem(L"pause"); if (Memory::Write(premium_free.data(), "\"premium\"===e.session?.productState?.catalogue?.toLowerCase(),r=e=>null!==e.session?.productState&&1===parseInt(e.session?.productState?.ads,10),o=e=>\"free\"===e.session?.productState?.catalogue?.toLowerCase(),")) { Logger::Log(L"premium patched!", Logger::LogLevel::Info); } @@ -256,11 +260,23 @@ extern "C" void hook_file_name(); extern "C" void hook_zip_buffer(); #else -// 8B45 EC | mov eax,dword ptr ss:[ebp-14] | -// 03C7 | add eax,edi | [+3] -// 50 | push eax | -// FFD2 | call edx | -// 03F8 | add edi,eax | [+5] +__declspec(naked) void hook_file_name() +{ + __asm + { + mov dword ptr ss : [ebp - 0x18] , ebx + mov byte ptr ss : [ebp - 0x14] , bl + push eax + + mov file_name_pointer, eax + + pushad + call get_file_name + popad + push ret_addr_file_name + retn + } +} __declspec(naked) void hook_zip_buffer() { @@ -271,22 +287,22 @@ __declspec(naked) void hook_zip_buffer() push eax call edx mov ZipScan.image_size, eax - cmp xpui_found, 0 - jne skip + //cmp xpui_found, 0 + //jne skip //------------ preparation -------------------- pushad //------------ function call ------------------ - call modify_buffer + call modify_source //------------ end call ------------------ popad //------------ finish ------------------------- - skip: - push ret_addr - retn + //skip: + push ret_addr_file_source + retn } } #endif @@ -382,6 +398,16 @@ DWORD WINAPI BlockBanner(LPVOID lpParam) Logger::Log(L"SourceCode - patch failed!", Logger::LogLevel::Error); } #else + const auto FileName = PatternScanner::ScanFirst(L"8B 48 24 85 C9 74 4A 50 FF D1 C7 45 ?? ?? ?? ?? ?? 89 5D E8 88 5D EC 50").offset(0x11); + ret_addr_file_name = FileName + 7; + + if (FileName.hook((PVOID)hook_file_name)) { + Logger::Log(L"FileName - patch success!", Logger::LogLevel::Info); + } + else { + Logger::Log(L"FileName - patch failed!", Logger::LogLevel::Error); + } + const auto SourceCode = PatternScanner::ScanFirst(L"8B 45 EC 03 C7 50 FF D2 03 F8").offset(3); ret_addr_file_source = SourceCode + 5; if (SourceCode.hook(hook_zip_buffer)) { diff --git a/src/Modify.h b/src/Modify.h index 891c15f8..8308f512 100644 --- a/src/Modify.h +++ b/src/Modify.h @@ -1,14 +1,14 @@ #pragma once - DWORD WINAPI EnableDeveloper(LPVOID lpParam); DWORD WINAPI BlockAds(LPVOID lpParam); DWORD WINAPI BlockBanner(LPVOID lpParam); +#ifdef _WIN64 extern "C" void WINAPI get_file_name(); extern "C" void WINAPI modify_source(); extern "C" PatternScanner::ModuleInfo ZipScan; - -extern "C" std::uint64_t file_name_rcx; -extern "C" std::uint64_t ret_addr_file_name; -extern "C" std::uint64_t ret_addr_file_source; +extern "C" std::uintptr_t file_name_pointer; +extern "C" std::uintptr_t ret_addr_file_name; +extern "C" std::uintptr_t ret_addr_file_source; +#endif diff --git a/src/assembly_code.asm b/src/assembly_code.asm index 089292fd..46f4ec76 100644 --- a/src/assembly_code.asm +++ b/src/assembly_code.asm @@ -2,8 +2,9 @@ ; External declarations EXTERN get_file_name : PROC EXTERN modify_source : PROC + EXTERN ZipScan : QWORD -EXTERN file_name_rcx : QWORD +EXTERN file_name_pointer : QWORD EXTERN ret_addr_file_name : QWORD EXTERN ret_addr_file_source : QWORD @@ -99,7 +100,7 @@ ENDM hook_file_name PROC test rcx, rcx - mov file_name_rcx, rcx + mov file_name_pointer, rcx PUSH_ALL_REGISTERS call get_file_name POP_ALL_REGISTERS