fix: restore x64 crossfade patch compatibility with Spotify 1.3.13

This commit is contained in:
amd64fox committed 2026-12-04 20:54:08 +03:00
1 parent a090081910
commit b9106c77d0
2 files changed
+57 -10

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
AGENTS.md
/spotify-exp-diff/
/exp-testing.json
/tests/
+56 -10
View File
@@ -5295,7 +5295,7 @@ function Get-InlineSettingPatterns {
}
# Each capture starts at the instruction or stack displacement used by the caller
$default = if ($Crossfade) { '41B101' } else { '4533C9' }
$default = if ($Crossfade) { '41B101' } else { '45 (?:31|33) C9' }
$keyLen = '(?<KeyLen>E8 .{8})'
$ownerLen = '(?<OwnerLen>E8 .{8})'
$rcx = '488D0D .{8}'
@@ -5309,20 +5309,65 @@ function Get-InlineSettingPatterns {
"4889$cx (?<OwnerSlot>..) 4889$ax (?<OwnerSize>..) $default " +
"4C8D$ax \k<KeySlot> 488D$dx \k<OwnerSlot> $resolver"
}
$key = '4C8D35 .{8}'
$keyStore = '4C897424 (?<KeySlot>..)'
$keySize = '48895C24 (?<KeySize>..)'
$ownerSize = '48894424 (?<OwnerSize>..)'
"^$key (?:.{6} 498BCE|498BCE .{12}) $keyLen (?<Owner>488D2D .{8}) 488BD8 488BCD $ownerLen " +
"$default $keyStore 4C8D4424 \k<KeySlot> $keySize 488D5424 (?<OwnerSlot>..) 48896C24 \k<OwnerSlot> $resolver $ownerSize"
"^$key 498BCE $keyLen 488BD8 (?<Owner>488D35 .{8}) 488BCE $ownerLen $keyStore $keySize " +
"48897424 (?<OwnerSlot>..) $ownerSize $default 4C8D4424 \k<KeySlot> 488D5424 \k<OwnerSlot> $resolver"
$ripLoad = '4[8C]8D [0-3][5D] .{8}'
$toRcx = '4[89]8B C[8-F]'
$optionalSave = '(?<SaveLength>4[8C]8B [C-F][08])?'
$setup = '(?<Setup>4[89CD]8B (?:[C-F] .|[0-3][01236789ABEF]))'
# Match four disp8 stores outside the 32-byte shadow space and four argument loads in any order
$store = '(?<Store>4[8C]89 [4-7][4C] 24 [2-7].)'
$argument = "(?:$store | (?<KeyView>4C8D4424 ..) | (?<OwnerView>488D5424 ..) | (?<Resolver>$resolver) | (?<Default>$default))"
"^$ripLoad ${setup}* (?<KeyToRcx>$toRcx) ${setup}* $keyLen " +
"$optionalSave (?<Owner>$ripLoad) $optionalSave (?<OwnerToRcx>$toRcx) $optionalSave $ownerLen ${argument}{8}"
}
function Get-X64ModRmRegister {
param([byte[]]$Bytes, [int]$Offset, [switch]$Rm)
if ($Rm) { return (($Bytes[$Offset] -band 1) -shl 3) -bor ($Bytes[$Offset + 2] -band 7) }
return (($Bytes[$Offset] -band 4) -shl 1) -bor (($Bytes[$Offset + 2] -shr 3) -band 7)
}
function Test-X64InlineSettingArguments {
param([byte[]]$Bytes, [int]$Start, $Match, $At)
$nonvolatile = 3, 5, 6, 7, 12, 13, 14, 15
if ($Match.Groups['SaveLength'].Captures.Count -ne 1 -or
-not ($At.KeyView -and $At.OwnerView -and $At.Resolver -and $At.Default)) { return $false }
$key = Get-X64ModRmRegister $Bytes $Start
$owner = Get-X64ModRmRegister $Bytes $At.Owner
$keyLength = Get-X64ModRmRegister $Bytes $At.SaveLength
if ((Get-X64ModRmRegister $Bytes $At.KeyToRcx -Rm) -ne $key -or
(Get-X64ModRmRegister $Bytes $At.OwnerToRcx -Rm) -ne $owner) { return $false }
foreach ($capture in $Match.Groups['Setup'].Captures) {
$dest = Get-X64ModRmRegister $Bytes ($Start + $capture.Index / 2)
if ($dest -notin $nonvolatile -or $dest -eq $key) { return $false }
}
$base = Get-X64ModRmRegister $Bytes $At.Resolver -Rm
if ($base -in $key, $owner, $keyLength -or
($base -notin $nonvolatile -and ($base -ne 4 -or $Bytes[$At.Resolver + 2] -ge 0xC0))) { return $false }
# R8 and RDX must point to separate pointer-length pairs at the call
$slots = @{}
foreach ($capture in $Match.Groups['Store'].Captures) {
$offset = [int]($Start + $capture.Index / 2)
$register = Get-X64ModRmRegister $Bytes $offset
if ($register -ne 0 -and $register -notin $nonvolatile) { return $false }
$slots[$register] = $Bytes[$offset + 4]
}
$keySlot = $Bytes[$At.KeyView + 4]
$ownerSlot = $Bytes[$At.OwnerView + 4]
return $slots[$key] -eq $keySlot -and $slots[$keyLength] -eq ($keySlot + 8) -and
$slots[$owner] -eq $ownerSlot -and $slots[0] -eq ($ownerSlot + 8) -and
[Math]::Abs($keySlot - $ownerSlot) -ge 16
}
function Find-InlineSettingCalls {
param([byte[]]$Bytes, $PeInfo, $Context, [string]$Key, [string]$Owner, [int64]$WithinFunction = -1)
$arch = $PeInfo.Architecture
$windowSize = if ($arch -eq 'x64') { 128 } else { 96 }
$refs = @(Get-SettingKeyReferences $Bytes $PeInfo $Context $Key -IncludeReusedPages:($Key -eq 'enable_list_player'))
$ownerBytes = [Text.Encoding]::ASCII.GetBytes("$Owner`0")
$enabled = $Key -eq 'crossfade_enabled'
@@ -5337,7 +5382,7 @@ function Find-InlineSettingCalls {
if ($range.Length -ne 2) { throw "Missing function range for $Key" }
if ($WithinFunction -ge 0 -and $WithinFunction -ne $range[0]) { continue }
$bias = $rva - $ref
$length = [Math]::Min(0x60, $range[1] - $rva)
$length = [Math]::Min($windowSize, $range[1] - $rva)
$hex = [BitConverter]::ToString($Bytes, $ref, $length).Replace('-', '')
foreach ($pattern in $patterns) {
$match = $pattern.Match($hex)
@@ -5347,6 +5392,7 @@ function Find-InlineSettingCalls {
foreach ($name in $pattern.GetGroupNames()) {
if ($match.Groups[$name].Success) { $at[$name] = [int]($ref + $match.Groups[$name].Index / 2) }
}
if ($at.KeyToRcx -and -not (Test-X64InlineSettingArguments $Bytes $ref $match $at)) { continue }
$call = [int]($ref + $match.Length / 2)
if ($call + $bias + $patchedBytes.Length -gt $range[1]) { continue }
$ownerPage = $at.Owner