vanhoivo

Windows 10 Login Screen Background Changer! Updated Script

Aug 14th, 2015
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.50 KB | None | 0 0
  1. $priPath = "$env:windir\SystemResources\Windows.UI.Logon\Windows.UI.Logon.pri"
  2. $outputPath = ".\Windows.UI.Logon_new.pri"
  3. $replacementPath = "C:\Windows\Web\Wallpaper\Theme1\img1.jpg"
  4.  
  5. try
  6. {
  7.     $inputStream = [System.IO.File]::OpenRead($priPath)
  8.     $outputStream = [System.IO.File]::Create($outputPath)
  9.     $replacementStream = [System.IO.File]::OpenRead($replacementPath)
  10.  
  11.     $inputReader = New-Object System.IO.BinaryReader $inputStream
  12.     $outputWriter = New-Object System.IO.BinaryWriter $outputStream
  13.  
  14.     $inputStream.CopyTo($outputStream)
  15.  
  16.     $replacementLengthAligned = ([Math]::Ceiling($replacementStream.Length / 8) * 8)
  17.  
  18.     # header
  19.     $inputStream.Seek(0x14, "Begin") | Out-Null
  20.     $headerLength = $inputReader.ReadUInt32()
  21.     $inputStream.Seek(0xB8, "Begin") | Out-Null
  22.     $dataitemOffset = $inputReader.ReadUInt32()
  23.     $origDataitemLength = $inputReader.ReadUInt32()
  24.     $dataitemLength = $origDataitemLength + $replacementLengthAligned
  25.     $outputStream.Seek(0xBC, "Begin") | Out-Null
  26.     $outputWriter.Write([int]$dataitemLength)
  27.  
  28.     # dataitem
  29.     $outputStream.Seek($headerLength + $dataitemOffset + 0x18, "Begin") | Out-Null
  30.     $outputWriter.Write([int]$dataitemLength)
  31.     $inputStream.Seek($headerLength + $dataitemOffset + 0x24, "Begin") | Out-Null
  32.     $stringCount = $inputReader.ReadUInt16()
  33.     $blobCount = $inputReader.ReadUInt16()
  34.     $origDataLength = $inputReader.ReadUInt32()
  35.     $outputStream.Seek(0xC, "Current") | Out-Null
  36.     $outputWriter.Write([int]($origDataLength + $replacementLengthAligned))
  37.     $outputStream.Seek($stringCount * 4, "Current") | Out-Null
  38.     $blobTableOffset = $outputStream.Position
  39.     $dataOffset = $blobTableOffset + $blobCount * 8
  40.     $wallpaperBlobs = @()
  41.     for ($i = 0; $i -lt $blobCount; $i++)
  42.     {
  43.         $inputStream.Seek($blobTableOffset + $i * 8, "Begin") | Out-Null
  44.         $offset = $inputReader.ReadUInt32()
  45.         $length = $inputReader.ReadUInt32()
  46.         $inputStream.Seek($dataOffset + $offset, "Begin") | Out-Null
  47.         if ($inputReader.ReadUInt16() -eq 0xD8FF)
  48.         {
  49.             $wallpaperBlobs += $i
  50.         }
  51.     }
  52.     if ($wallpaperBlobs.Count -ne 10)
  53.     {
  54.         Write-Error "Not compatible with this PRI file."
  55.     }
  56.     foreach ($id in $wallpaperBlobs)
  57.     {
  58.         $outputStream.Seek($blobTableOffset + $id * 8, "Begin") | Out-Null
  59.         $outputWriter.Write($origDataLength)
  60.         $outputWriter.Write([int]$replacementStream.Length)
  61.     }
  62.  
  63.     # data
  64.     $outputStream.Seek($dataOffset + $origDataLength, "Begin") | Out-Null
  65.     if ($outputStream.Length - $outputStream.Position -ne 0x18)
  66.     {
  67.         Write-Error "Not compatible with this PRI file."
  68.     }
  69.     $replacementStream.CopyTo($outputStream)
  70.  
  71.     # footer
  72.     $outputStream.Seek($replacementLengthAligned - $replacementStream.Length, "Current") | Out-Null
  73.     $outputWriter.Write(0xDEF5FADE)
  74.     $outputWriter.Write([int]$dataitemLength)
  75.     $outputWriter.Write(0xDEFFFADE)
  76.     $outputWriter.Write(0x00000000)
  77.     $outputWriter.Write([char[]]"mrm_pri2")
  78.  
  79.     $outputStream.Seek(0xC, "Begin") | Out-Null
  80.     $outputWriter.Write([int]$outputStream.Length)
  81.     $outputStream.Seek(-0xC, "End") | Out-Null
  82.     $outputWriter.Write([int]$outputStream.Length)
  83. }
  84. finally
  85. {
  86.     if ($inputReader -ne $null)
  87.     {
  88.         $inputReader.Close()
  89.     }
  90.     if ($outputWriter -ne $null)
  91.     {
  92.         $outputWriter.Close()
  93.     }
  94.     if ($replacementStream -ne $null)
  95.     {
  96.         $replacementStream.Close()
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment