Merge pull request #473 from cemeyer/kfxzip_efficiency

kfxdrm: Traipse through the kfx-zip more efficiently
This commit is contained in:
Apprentice Harper 2018-05-05 18:34:17 +01:00 committed by GitHub
commit 75acbe5536
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -36,8 +36,11 @@ class KFXZipBook:
def processBook(self, totalpids): def processBook(self, totalpids):
with zipfile.ZipFile(self.infile, 'r') as zf: with zipfile.ZipFile(self.infile, 'r') as zf:
for filename in zf.namelist(): for filename in zf.namelist():
data = zf.read(filename) with zf.open(filename) as fh:
if data.startswith('\xeaDRMION\xee'): data = fh.read(8)
if data != '\xeaDRMION\xee':
continue
data += fh.read()
if self.voucher is None: if self.voucher is None:
self.decrypt_voucher(totalpids) self.decrypt_voucher(totalpids)
print u'Decrypting KFX DRMION: {0}'.format(filename) print u'Decrypting KFX DRMION: {0}'.format(filename)
@ -51,9 +54,13 @@ class KFXZipBook:
def decrypt_voucher(self, totalpids): def decrypt_voucher(self, totalpids):
with zipfile.ZipFile(self.infile, 'r') as zf: with zipfile.ZipFile(self.infile, 'r') as zf:
for info in zf.infolist(): for info in zf.infolist():
if info.file_size < 0x10000: with zf.open(info.filename) as fh:
data = zf.read(info.filename) data = fh.read(4)
if data.startswith('\xe0\x01\x00\xea') and 'ProtectedData' in data: if data != '\xe0\x01\x00\xea':
continue
data += fh.read()
if 'ProtectedData' in data:
break # found DRM voucher break # found DRM voucher
else: else:
raise Exception(u'The .kfx-zip archive contains an encrypted DRMION file without a DRM voucher') raise Exception(u'The .kfx-zip archive contains an encrypted DRMION file without a DRM voucher')