Skip to content

Instantly share code, notes, and snippets.

@out0xb2
Created April 16, 2021 14:51
Show Gist options
  • Save out0xb2/9bcfece795d2bb1696fa6d7df666d1e6 to your computer and use it in GitHub Desktop.
Save out0xb2/9bcfece795d2bb1696fa6d7df666d1e6 to your computer and use it in GitHub Desktop.
Splitting a signed dbx (or other Auth variable *data) into content and signature blobs
$file = Get-Content -Encoding Byte $args[0]
$chop = $file[40..($file.Length - 1)]
if (($chop[0] -ne 0x30) -or ($chop[1] -ne 0x82 )) {
Write-Error "Cannot find signature"
exit 1
}
Write-Host "Found signature magic"
$sig_length = ($chop[2] * 256) + $chop[3] + 4 # ASN size plus header of 4 bytes
$sig = $chop[0..($sig_length - 1)]
"Signature Length: " + $sig.Length
if ($sig_length -gt ($file.Length + 40)) {
Write-Error "Signature longer than file size!"
exit 1
}
[System.Byte[]] $sigbytes = @()
foreach ($i in $sig) {$sigbytes += $i}
Set-Content -Encoding Byte -Path ".\signature.p7" -Value $sigbytes
$content = $chop[$sig_length..($chop.Length - 1)]
[System.Byte[]] $bytes = @()
foreach ($i in $content) {$bytes += $i}
Set-Content -Encoding Byte -Path ".\content.bin" -Value $bytes
Write-Host "Files written successfully!"
Write-Host 'Try: Set-SecureBootUefi -Name dbx -ContentFilePath .\content.bin -SignedFilePath .\signature.p7 -Time 2010-03-06T19:17:21Z -AppendWrite'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment