Skip to content

Commit

Permalink
small changes (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejaxh authored Jul 29, 2023
1 parent 987cd4e commit aba6639
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 85 deletions.
61 changes: 42 additions & 19 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion src/BlockTheSpot.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp20</LanguageStandard>
<ExceptionHandling>false</ExceptionHandling>
<ExceptionHandling>false</ExceptionHandling>
<AdditionalIncludeDirectories>C:\cef;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
85 changes: 52 additions & 33 deletions src/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,56 @@

#ifndef NDEBUG

void print_test() {
// Example colors vector
std::vector<Color> colors = { Color::Red, Color::Green, Color::Blue };
#include <intrin.h>

// 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<Color> 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<Color> 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<Color> 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<wchar_t**>(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)
{
Expand All @@ -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)
Expand Down
76 changes: 51 additions & 25 deletions src/Modify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ static _cef_string_userfree_utf16_free cef_string_userfree_utf16_free_orig;

static constexpr std::array<std::wstring_view, 3> 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;
Expand Down Expand Up @@ -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<wchar_t*>(*reinterpret_cast<wchar_t**>(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<wchar_t**>(url_utf16));
#else
auto url_utf16 = get_url(reinterpret_cast<DWORD>(request));
std::wstring url(reinterpret_cast<wchar_t*>(get_str(url_utf16)));
Expand All @@ -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<wchar_t**>(file_name_rcx);
//MessageBoxW(0,file_name.c_str(), 0, 0);
//Print(L"{}", zip_file_name);
//system("pause");
file_name = *reinterpret_cast<wchar_t**>(file_name_pointer);
//Print(L"{}", file_name);
//_wsystem(L"pause");
}
catch (const std::exception& e) {
Print({ Color::Red }, L"[{}] {}", L"ERROR", e.what());
Expand Down Expand Up @@ -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<const char*>());
//system("pause");
//_wsystem(L"pause");
if (Memory::Write<const char*>(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);
}
Expand All @@ -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()
{
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Modify.h
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions src/assembly_code.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aba6639

Please sign in to comment.