Created
April 8, 2017 18:39
-
-
Save autch/10d0d4dff33de362fcee60049f709652 to your computer and use it in GitHub Desktop.
Decrypt AES-encoded HLS streams
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
| #!/usr/bin/env python3 | |
| from __future__ import print_function | |
| import argparse | |
| from Crypto.Cipher import AES | |
| READ_AT_ONCE = 1 << 16 | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('-k', '--keyfile', required=True, help='use key file') | |
| ap.add_argument('-o', '--output', required=True, help='set output') | |
| ap.add_argument('-c', '--cipher', help='set cipher type') | |
| ap.add_argument('FILES', help='files to decode', nargs='+') | |
| args = ap.parse_args() | |
| with open(args.keyfile, 'rb') as keyfile: | |
| secret_key = keyfile.read() | |
| IV = "\0" * 16 | |
| aes = AES.new(secret_key, AES.MODE_CBC, IV) | |
| with open(args.output, 'wb') as outfile: | |
| print('OUTFILE: {}'.format(args.output)) | |
| for filename in args.FILES: | |
| with open(filename, 'rb') as infile: | |
| print('INFILE: {} '.format(filename), end='') | |
| while True: | |
| inbuf = infile.read(READ_AT_ONCE) | |
| outbuf = aes.decrypt(inbuf) | |
| outfile.write(outbuf) | |
| print('.', end='') | |
| if len(inbuf) < READ_AT_ONCE: | |
| break | |
| print() |
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
| $ cat files | |
| segment1_2000000_av.ts | |
| segment2_2000000_av.ts | |
| segment3_2000000_av.ts | |
| segment4_2000000_av.ts | |
| segment5_2000000_av.ts | |
| segment6_2000000_av.ts | |
| segment7_2000000_av.ts | |
| segment8_2000000_av.ts | |
| segment9_2000000_av.ts | |
| segment10_2000000_av.ts | |
| $ cat files | xargs ./dec_hls.py -k crypt.key -o output.ts | |
| OUTFILE: output.ts | |
| INFILE: segment1_2000000_av.ts ............................................ | |
| INFILE: segment2_2000000_av.ts ............................................ | |
| INFILE: segment3_2000000_av.ts ........................................... | |
| INFILE: segment4_2000000_av.ts ...................................... | |
| INFILE: segment5_2000000_av.ts .......................................... | |
| INFILE: segment6_2000000_av.ts ............................... | |
| INFILE: segment7_2000000_av.ts .................................................... | |
| INFILE: segment8_2000000_av.ts ....................................... | |
| INFILE: segment9_2000000_av.ts ...................................... | |
| INFILE: segment10_2000000_av.ts . | |
| $ ffmpeg -y -i output.ts -c:v copy -c:a copy -movflags +faststart -bsf:a aac_adtstoasc output.m4v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment