Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $priPath = "$env:windir\SystemResources\Windows.UI.Logon\Windows.UI.Logon.pri"
- $outputPath = ".\Windows.UI.Logon_new.pri"
- $replacementPath = "C:\Windows\Web\Wallpaper\Theme1\img1.jpg"
- try
- {
- $inputStream = [System.IO.File]::OpenRead($priPath)
- $outputStream = [System.IO.File]::Create($outputPath)
- $replacementStream = [System.IO.File]::OpenRead($replacementPath)
- $inputReader = New-Object System.IO.BinaryReader $inputStream
- $outputWriter = New-Object System.IO.BinaryWriter $outputStream
- $inputStream.CopyTo($outputStream)
- $replacementLengthAligned = ([Math]::Ceiling($replacementStream.Length / 8) * 8)
- # header
- $inputStream.Seek(0x14, "Begin") | Out-Null
- $headerLength = $inputReader.ReadUInt32()
- $inputStream.Seek(0xB8, "Begin") | Out-Null
- $dataitemOffset = $inputReader.ReadUInt32()
- $origDataitemLength = $inputReader.ReadUInt32()
- $dataitemLength = $origDataitemLength + $replacementLengthAligned
- $outputStream.Seek(0xBC, "Begin") | Out-Null
- $outputWriter.Write([int]$dataitemLength)
- # dataitem
- $outputStream.Seek($headerLength + $dataitemOffset + 0x18, "Begin") | Out-Null
- $outputWriter.Write([int]$dataitemLength)
- $inputStream.Seek($headerLength + $dataitemOffset + 0x24, "Begin") | Out-Null
- $stringCount = $inputReader.ReadUInt16()
- $blobCount = $inputReader.ReadUInt16()
- $origDataLength = $inputReader.ReadUInt32()
- $outputStream.Seek(0xC, "Current") | Out-Null
- $outputWriter.Write([int]($origDataLength + $replacementLengthAligned))
- $outputStream.Seek($stringCount * 4, "Current") | Out-Null
- $blobTableOffset = $outputStream.Position
- $dataOffset = $blobTableOffset + $blobCount * 8
- $wallpaperBlobs = @()
- for ($i = 0; $i -lt $blobCount; $i++)
- {
- $inputStream.Seek($blobTableOffset + $i * 8, "Begin") | Out-Null
- $offset = $inputReader.ReadUInt32()
- $length = $inputReader.ReadUInt32()
- $inputStream.Seek($dataOffset + $offset, "Begin") | Out-Null
- if ($inputReader.ReadUInt16() -eq 0xD8FF)
- {
- $wallpaperBlobs += $i
- }
- }
- if ($wallpaperBlobs.Count -ne 10)
- {
- Write-Error "Not compatible with this PRI file."
- }
- foreach ($id in $wallpaperBlobs)
- {
- $outputStream.Seek($blobTableOffset + $id * 8, "Begin") | Out-Null
- $outputWriter.Write($origDataLength)
- $outputWriter.Write([int]$replacementStream.Length)
- }
- # data
- $outputStream.Seek($dataOffset + $origDataLength, "Begin") | Out-Null
- if ($outputStream.Length - $outputStream.Position -ne 0x18)
- {
- Write-Error "Not compatible with this PRI file."
- }
- $replacementStream.CopyTo($outputStream)
- # footer
- $outputStream.Seek($replacementLengthAligned - $replacementStream.Length, "Current") | Out-Null
- $outputWriter.Write(0xDEF5FADE)
- $outputWriter.Write([int]$dataitemLength)
- $outputWriter.Write(0xDEFFFADE)
- $outputWriter.Write(0x00000000)
- $outputWriter.Write([char[]]"mrm_pri2")
- $outputStream.Seek(0xC, "Begin") | Out-Null
- $outputWriter.Write([int]$outputStream.Length)
- $outputStream.Seek(-0xC, "End") | Out-Null
- $outputWriter.Write([int]$outputStream.Length)
- }
- finally
- {
- if ($inputReader -ne $null)
- {
- $inputReader.Close()
- }
- if ($outputWriter -ne $null)
- {
- $outputWriter.Close()
- }
- if ($replacementStream -ne $null)
- {
- $replacementStream.Close()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment