Skip to content

Instantly share code, notes, and snippets.

@r15ch13
Created June 9, 2019 16:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r15ch13/5b9db753315853d4a5985fe932f7c0b9 to your computer and use it in GitHub Desktop.
Save r15ch13/5b9db753315853d4a5985fe932f7c0b9 to your computer and use it in GitHub Desktop.
Extract AAX checksum from Audible Audio Book
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