Skip to content

Commit

Permalink
fairplay: Add basic SPC decoder and PSSH system id
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Jul 7, 2022
1 parent 28c1a94 commit 64f3e5c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dns_tcp,
elf,
ether8023_frame,
exif,
fairplay_spc,
flac,
[flac_frame](doc/formats.md#flac_frame),
flac_metadatablock,
Expand Down
1 change: 1 addition & 0 deletions doc/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
|`elf` |Executable&nbsp;and&nbsp;Linkable&nbsp;Format |<sub></sub>|
|`ether8023_frame` |Ethernet&nbsp;802.3&nbsp;frame |<sub>`inet_packet`</sub>|
|`exif` |Exchangeable&nbsp;Image&nbsp;File&nbsp;Format |<sub></sub>|
|`fairplay_spc` |FairPlay&nbsp;Server&nbsp;Playback&nbsp;Context |<sub></sub>|
|`flac` |Free&nbsp;Lossless&nbsp;Audio&nbsp;Codec&nbsp;file |<sub>`flac_metadatablocks` `flac_frame`</sub>|
|[`flac_frame`](#flac_frame) |FLAC&nbsp;frame |<sub></sub>|
|`flac_metadatablock` |FLAC&nbsp;metadatablock |<sub>`flac_streaminfo` `flac_picture` `vorbis_comment`</sub>|
Expand Down
18 changes: 12 additions & 6 deletions doc/formats.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions format/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
_ "github.com/wader/fq/format/cbor"
_ "github.com/wader/fq/format/dns"
_ "github.com/wader/fq/format/elf"
_ "github.com/wader/fq/format/fairplay"
_ "github.com/wader/fq/format/flac"
_ "github.com/wader/fq/format/gif"
_ "github.com/wader/fq/format/gzip"
Expand Down
7 changes: 7 additions & 0 deletions format/all/help.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ out # Decode file as exif
out $ fq -d exif . file
out # Decode value as exif
out ... | exif
"help(fairplay_spc)"
out fairplay_spc: FairPlay Server Playback Context decoder
out Examples:
out # Decode file as fairplay_spc
out $ fq -d fairplay_spc . file
out # Decode value as fairplay_spc
out ... | fairplay_spc
"help(flac)"
out flac: Free Lossless Audio Codec file decoder
out Examples:
Expand Down
29 changes: 29 additions & 0 deletions format/fairplay/fairplay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fairplay

// https://github.com/easonlin404/ksm/blob/master/ksm.go

import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
)

func init() {
registry.MustRegister(decode.Format{
Name: format.FAIRPLAY_SPC,
Description: "FairPlay Server Playback Context",
DecodeFn: fairPlaySPCDecode,
})
}

func fairPlaySPCDecode(d *decode.D, in any) any {
d.FieldU32("version")
d.FieldRawLen("reserved", 32)
d.FieldRawLen("iv", 16*8)
d.FieldRawLen("aes_key_oaep", 128*8)
d.FieldRawLen("certificate_hash", 20*8)
payloadLen := d.FieldU32("payload_length")
d.FieldRawLen("payload", int64(payloadLen)*8)

return nil
}
1 change: 1 addition & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
ELF = "elf"
ETHER8023_FRAME = "ether8023_frame"
EXIF = "exif"
FAIRPLAY_SPC = "fairplay_spc"
FLAC = "flac"
FLAC_FRAME = "flac_frame"
FLAC_METADATABLOCK = "flac_metadatablock"
Expand Down
2 changes: 2 additions & 0 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,13 @@ func init() {
systemIDCommon = [16]byte{0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, 0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b}
systemIDWidevine = [16]byte{0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6, 0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc, 0xd5, 0x1d, 0x21, 0xed}
systemIDPlayReady = [16]byte{0x9a, 0x04, 0xf0, 0x79, 0x98, 0x40, 0x42, 0x86, 0xab, 0x92, 0xe6, 0x5b, 0xe0, 0x88, 0x5f, 0x95}
systemIDFairPlay = [16]byte{0x94, 0xce, 0x86, 0xfb, 0x07, 0xff, 0x4f, 0x43, 0xad, 0xb8, 0x93, 0xd2, 0xfa, 0x96, 0x8c, 0xa2}
)
systemIDNames := scalar.BytesToScalar{
{Bytes: systemIDCommon[:], Scalar: scalar.S{Sym: "common"}},
{Bytes: systemIDWidevine[:], Scalar: scalar.S{Sym: "widevine"}},
{Bytes: systemIDPlayReady[:], Scalar: scalar.S{Sym: "playready"}},
{Bytes: systemIDFairPlay[:], Scalar: scalar.S{Sym: "fairplay"}},
}

version := d.FieldU8("version")
Expand Down
1 change: 1 addition & 0 deletions pkg/interp/testdata/args.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ dns_tcp DNS packet (TCP)
elf Executable and Linkable Format
ether8023_frame Ethernet 802.3 frame
exif Exchangeable Image File Format
fairplay_spc FairPlay Server Playback Context
flac Free Lossless Audio Codec file
flac_frame FLAC frame
flac_metadatablock FLAC metadatablock
Expand Down

0 comments on commit 64f3e5c

Please sign in to comment.