-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpatch-dark-mode.ps1
44 lines (38 loc) · 1.28 KB
/
patch-dark-mode.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Terminate Spotify processes
Get-Process -Name Spotify, SpotifyWebHelper -ErrorAction SilentlyContinue | Stop-Process -Force
# Backup Spotify executable
$sp = spicetify config spotify_path
$sp += "\Spotify.exe"
Copy-Item $sp ($sp + ".backup")
# Byte operations
$bytes = [System.IO.File]::ReadAllBytes($sp)
$toRemove = [System.Text.Encoding]::UTF8.GetBytes("force-dark-mode")
# Progress setup
$sw = [System.Diagnostics.Stopwatch]::StartNew()
for ($i = 0; $i -lt $bytes.Length; $i++) {
if ($i -eq 0 -or $sw.Elapsed.TotalMilliseconds -ge 2000) {
Write-Progress -Activity "Enabling dark mode in Spotify.exe" -status "Patching binary file $i" -percentComplete ($i / $bytes.Length*100);
$sw.Restart();
}
$found = $true
for ($j = 0; $j -lt $toRemove.Length; $j++) {
if ($bytes[$i + $j] -ne $toRemove[$j]) {
$found = $false;
break;
}
}
if ($found -eq $true) {
for ($j = 0; $j -lt $toRemove.Length; $j++) {
$bytes[$i + $j] = [byte]65;
}
break;
}
}
# Write patched bytes back
[System.IO.File]::WriteAllBytes($sp, $bytes)
# Display result
if ($found) {
Write-Host "The patch is complete." -ForegroundColor "Green"
} else {
Write-Host "Failed to patch the file." -ForegroundColor "Red"
}