Created
June 9, 2019 16:34
-
-
Save r15ch13/5b9db753315853d4a5985fe932f7c0b9 to your computer and use it in GitHub Desktop.
Extract AAX checksum from Audible Audio Book
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Read-AudioBookChecksum { | |
param( | |
[Parameter(Mandatory=$true, | |
Position=0, | |
ParameterSetName="Path", | |
ValueFromPipeline=$true, | |
ValueFromPipelineByPropertyName=$true)] | |
[ValidateNotNullOrEmpty()] | |
[ValidateScript({ Test-Path $_ -Type Leaf })] | |
[string] | |
$Path | |
) | |
Process { | |
try { | |
$buffer = New-Object Byte[] 20 | |
$fs = [IO.File]::OpenRead($Path) | |
$fs.Seek(581, [System.IO.SeekOrigin]::Begin) | Out-Null | |
$fs.Read($buffer, 0, 4) | Out-Null | |
if([System.Text.Encoding]::UTF8.GetString($buffer) -eq 'adrm') { | |
$fs.Seek(653, [System.IO.SeekOrigin]::Begin) | Out-Null | |
$fs.Read($buffer, 0, 20) | Out-Null | |
return ($buffer | ForEach-Object ToString x2) -join '' | |
} | |
return $null | |
} | |
finally { | |
$fs.Close(); | |
} | |
} | |
} | |
Get-ChildItem "*.aax" | Read-AudioBookChecksum $_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment