mirror of
https://github.com/SpotX-Official/SpotX.git
synced 2026-04-11 17:37:21 +10:00
fixed patching for DLL files in 1.2.70+
- added a patch to disable signature protection ( Thanks @Ingan121 👏) - added a function for removing signatures from files - added support for the new Spotify.dll file Co-Authored-By: Ingan121 <ingan121@ingan121.com>
This commit is contained in:
192
run.ps1
192
run.ps1
@@ -286,7 +286,9 @@ function Format-LanguageCode {
|
||||
$spotifyDirectory = Join-Path $env:APPDATA 'Spotify'
|
||||
$spotifyDirectory2 = Join-Path $env:LOCALAPPDATA 'Spotify'
|
||||
$spotifyExecutable = Join-Path $spotifyDirectory 'Spotify.exe'
|
||||
$spotifyDll = Join-Path $spotifyDirectory 'Spotify.dll'
|
||||
$exe_bak = Join-Path $spotifyDirectory 'Spotify.bak'
|
||||
$dll_bak = Join-Path $spotifyDirectory 'Spotify.dll.bak'
|
||||
$spotifyUninstall = Join-Path ([System.IO.Path]::GetTempPath()) 'SpotifyUninstall.exe'
|
||||
$start_menu = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\Spotify.lnk'
|
||||
|
||||
@@ -1518,9 +1520,9 @@ function extract ($counts, $method, $name, $helper, $add, $patch) {
|
||||
}
|
||||
"exe" {
|
||||
$ANSI = [Text.Encoding]::GetEncoding(1251)
|
||||
$xpui = [IO.File]::ReadAllText($spotifyExecutable, $ANSI)
|
||||
$xpui = [IO.File]::ReadAllText($spotify_binary, $ANSI)
|
||||
$xpui = Helper -paramname $helper
|
||||
[IO.File]::WriteAllText($spotifyExecutable, $xpui, $ANSI)
|
||||
[IO.File]::WriteAllText($spotify_binary, $xpui, $ANSI)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1703,6 +1705,154 @@ function Extract-WebpackModules {
|
||||
return $decodedString
|
||||
}
|
||||
|
||||
function Reset-Dll-Sign {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$FilePath
|
||||
)
|
||||
|
||||
$searchPattern = [byte[]](
|
||||
0x30, 0x01, 0x00, 0x00, 0x5B, 0xC3, 0xCC, 0xCC, 0x48, 0x89, 0x5C, 0x24, 0x18, 0x55
|
||||
)
|
||||
$replacePattern = [byte[]](
|
||||
0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3
|
||||
)
|
||||
$bytesToReplaceCount = 6
|
||||
|
||||
if (-not (Test-Path $FilePath -PathType Leaf)) {
|
||||
Write-Error "File not found at path: $FilePath"
|
||||
Write-Host ($lang).StopScript
|
||||
Pause
|
||||
Exit
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Verbose "Reading file..."
|
||||
$fileBytes = [System.IO.File]::ReadAllBytes($FilePath)
|
||||
Write-Verbose "File read. Size: $($fileBytes.Length) bytes."
|
||||
|
||||
$offset = -1
|
||||
$searchLimit = $fileBytes.Length - $searchPattern.Length
|
||||
|
||||
Write-Verbose "Searching for byte sequence..."
|
||||
for ($i = 0; $i -le $searchLimit; $i++) {
|
||||
$match = $true
|
||||
for ($j = 0; $j -lt $searchPattern.Length; $j++) {
|
||||
if ($fileBytes[$i + $j] -ne $searchPattern[$j]) {
|
||||
$match = $false
|
||||
break
|
||||
}
|
||||
}
|
||||
if ($match) {
|
||||
$offset = $i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ($offset -eq -1) {
|
||||
Write-Warning "Required byte sequence not found for the signature reset patch"
|
||||
Write-Host ($lang).StopScript
|
||||
Pause
|
||||
Exit
|
||||
}
|
||||
|
||||
Write-Verbose "Sequence found at offset: 0x$($offset.ToString('X'))"
|
||||
|
||||
$patchOffset = $offset + ($searchPattern.Length - $bytesToReplaceCount)
|
||||
|
||||
Write-Verbose "Applying patch at offset: 0x$($patchOffset.ToString('X'))"
|
||||
|
||||
for ($i = 0; $i -lt $replacePattern.Length; $i++) {
|
||||
$fileBytes[$patchOffset + $i] = $replacePattern[$i]
|
||||
}
|
||||
|
||||
Write-Verbose "Writing patched file..."
|
||||
[System.IO.File]::WriteAllBytes($FilePath, $fileBytes)
|
||||
|
||||
}
|
||||
catch {
|
||||
Write-Error "An error occurred: $_"
|
||||
Write-Host ($lang).StopScript
|
||||
Pause
|
||||
Exit
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-Sign([string]$filePath) {
|
||||
try {
|
||||
$bytes = [System.IO.File]::ReadAllBytes($filePath)
|
||||
$peHeaderOffset = [System.BitConverter]::ToUInt32($bytes, 0x3C)
|
||||
if ($bytes[$peHeaderOffset] -ne 0x50 -or $bytes[$peHeaderOffset + 1] -ne 0x45) {
|
||||
Write-Warning "File '$(Split-Path $filePath -Leaf)' is not a valid PE file."
|
||||
return $false
|
||||
}
|
||||
$fileHeaderOffset = $peHeaderOffset + 4
|
||||
$optionalHeaderOffset = $fileHeaderOffset + 20
|
||||
$machineType = [System.BitConverter]::ToUInt16($bytes, $fileHeaderOffset)
|
||||
$dataDirectoryOffsetWithinOptionalHeader = 0
|
||||
if (($machineType -eq 0x8664) -or ($machineType -eq 0xAA64)) {
|
||||
$dataDirectoryOffsetWithinOptionalHeader = 112
|
||||
}
|
||||
elseif ($machineType -eq 0x014c) {
|
||||
$dataDirectoryOffsetWithinOptionalHeader = 96
|
||||
}
|
||||
else {
|
||||
Write-Warning "Unsupported architecture type ($($machineType.ToString('X'))) in file '$(Split-Path $filePath -Leaf)'."
|
||||
return $false
|
||||
}
|
||||
$securityDirectoryIndex = 4
|
||||
$certificateTableEntryOffset = $optionalHeaderOffset + $dataDirectoryOffsetWithinOptionalHeader + ($securityDirectoryIndex * 8)
|
||||
if ($certificateTableEntryOffset + 8 -gt $bytes.Length) {
|
||||
Write-Warning "Could not find Data Directory in file '$(Split-Path $filePath -Leaf)'. Header is corrupted or has non-standard format."
|
||||
return $false
|
||||
}
|
||||
$rva = [System.BitConverter]::ToUInt32($bytes, $certificateTableEntryOffset)
|
||||
$size = [System.BitConverter]::ToUInt32($bytes, $certificateTableEntryOffset + 4)
|
||||
if ($rva -eq 0 -and $size -eq 0) {
|
||||
Write-Host "Signature in file '$(Split-Path $filePath -Leaf)' is already absent." -ForegroundColor Yellow
|
||||
return $true
|
||||
}
|
||||
for ($i = 0; $i -lt 8; $i++) {
|
||||
$bytes[$certificateTableEntryOffset + $i] = 0
|
||||
}
|
||||
[System.IO.File]::WriteAllBytes($filePath, $bytes)
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Error "Error processing file '$filePath': $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-Signature-FromFiles([string[]]$fileNames) {
|
||||
foreach ($fileName in $fileNames) {
|
||||
$fullPath = Join-Path -Path $spotifyDirectory -ChildPath $fileName
|
||||
if (-not (Test-Path $fullPath)) {
|
||||
Write-Error "File not found: $fullPath"
|
||||
Write-Host ($lang).StopScript
|
||||
Pause
|
||||
Exit
|
||||
}
|
||||
try {
|
||||
Write-Verbose "Processing file: $fileName"
|
||||
if ($fileName -ne "Spotify.dll") {
|
||||
$backupPath = $fullPath + ".bak"
|
||||
Copy-Item -Path $fullPath -Destination $backupPath -Force
|
||||
Write-Verbose " -> Backup created: $backupPath"
|
||||
}
|
||||
if (Remove-Sign -filePath $fullPath) {
|
||||
Write-Verbose " -> Signature entry successfully zeroed."
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to process file '$fileName': $_"
|
||||
Write-Host ($lang).StopScript
|
||||
Pause
|
||||
Exit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Update-ZipEntry {
|
||||
[CmdletBinding()]
|
||||
@@ -1771,8 +1921,6 @@ $xpui_spa_patch = Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'xpui.spa'
|
||||
$xpui_js_patch = Join-Path (Join-Path (Join-Path $env:APPDATA 'Spotify\Apps') 'xpui') 'xpui.js'
|
||||
$test_spa = Test-Path -Path $xpui_spa_patch
|
||||
$test_js = Test-Path -Path $xpui_js_patch
|
||||
$spotify_exe_bak_patch = Join-Path $env:APPDATA 'Spotify\Spotify.bak'
|
||||
|
||||
|
||||
if ($test_spa -and $test_js) {
|
||||
Write-Host ($lang).Error -ForegroundColor Red
|
||||
@@ -1875,6 +2023,21 @@ if ($test_spa) {
|
||||
$patched_by_spotx = $reader.ReadToEnd()
|
||||
$reader.Close()
|
||||
|
||||
|
||||
if ($offline -ge [version]'1.2.70.404') {
|
||||
Reset-Dll-Sign -FilePath $spotifyDll
|
||||
|
||||
$files = @("Spotify.dll", "Spotify.exe", "chrome_elf.dll")
|
||||
Remove-Signature-FromFiles $files
|
||||
|
||||
$spotify_binary_bak = $dll_bak
|
||||
$spotify_binary = $spotifyDll
|
||||
}
|
||||
else {
|
||||
$spotify_binary_bak = $exe_bak
|
||||
$spotify_binary = $spotifyExecutable
|
||||
}
|
||||
|
||||
If ($patched_by_spotx -match 'patched by spotx') {
|
||||
$zip.Dispose()
|
||||
|
||||
@@ -1882,11 +2045,9 @@ if ($test_spa) {
|
||||
Remove-Item $xpui_spa_patch -Recurse -Force
|
||||
Rename-Item $bak_spa $xpui_spa_patch
|
||||
|
||||
$spotify_exe_bak_patch = Join-Path $env:APPDATA 'Spotify\Spotify.bak'
|
||||
$test_spotify_exe_bak = Test-Path -Path $spotify_exe_bak_patch
|
||||
if ($test_spotify_exe_bak) {
|
||||
Remove-Item $spotifyExecutable -Recurse -Force
|
||||
Rename-Item $spotify_exe_bak_patch $spotifyExecutable
|
||||
if (Test-Path -Path $spotify_binary_bak) {
|
||||
Remove-Item $spotify_binary -Recurse -Force
|
||||
Rename-Item $spotify_binary_bak $spotify_binary
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1894,12 +2055,7 @@ if ($test_spa) {
|
||||
Pause
|
||||
Exit
|
||||
}
|
||||
$spotify_exe_bak_patch = Join-Path $env:APPDATA 'Spotify\Spotify.bak'
|
||||
$test_spotify_exe_bak = Test-Path -Path $spotify_exe_bak_patch
|
||||
if ($test_spotify_exe_bak) {
|
||||
Remove-Item $spotifyExecutable -Recurse -Force
|
||||
Rename-Item $spotify_exe_bak_patch $spotifyExecutable
|
||||
}
|
||||
|
||||
}
|
||||
$zip.Dispose()
|
||||
Copy-Item $xpui_spa_patch $env:APPDATA\Spotify\Apps\xpui.bak
|
||||
@@ -2095,11 +2251,11 @@ $regex5 = $old -notmatch $webjson.others.binary.block_gabo.add
|
||||
|
||||
if ($regex1 -and $regex2 -and $regex3 -and $regex4 -and $regex5) {
|
||||
|
||||
if (Test-Path -LiteralPath $exe_bak) {
|
||||
Remove-Item $exe_bak -Recurse -Force
|
||||
if (Test-Path -LiteralPath $spotify_binary_bak) {
|
||||
Remove-Item $spotify_binary_bak -Recurse -Force
|
||||
Start-Sleep -Milliseconds 150
|
||||
}
|
||||
copy-Item $spotifyExecutable $exe_bak
|
||||
copy-Item $spotify_binary $spotify_binary_bak
|
||||
}
|
||||
|
||||
# Binary patch
|
||||
|
||||
Reference in New Issue
Block a user