mirror of
https://github.com/noDRM/DeDRM_tools.git
synced 2024-12-29 04:37:39 +06:00
Enhance parsing DrmIon files
Adding support for parsing plaintext in DrmIon files. This is needed by my kindle project. When downloading an ebook with my package it gives me a metadata file wich is DrmIon encoded. This file containes plaintext instead of encrypted pages.
This commit is contained in:
parent
76a47e0dd0
commit
fd51422a36
@ -993,6 +993,7 @@ class DrmIon(object):
|
|||||||
|
|
||||||
elif self.ion.gettypename() in ["com.amazon.drm.EncryptedPage@1.0", "com.amazon.drm.EncryptedPage@2.0"]:
|
elif self.ion.gettypename() in ["com.amazon.drm.EncryptedPage@1.0", "com.amazon.drm.EncryptedPage@2.0"]:
|
||||||
decompress = False
|
decompress = False
|
||||||
|
decrypt = True
|
||||||
ct = None
|
ct = None
|
||||||
civ = None
|
civ = None
|
||||||
self.ion.stepin()
|
self.ion.stepin()
|
||||||
@ -1006,7 +1007,23 @@ class DrmIon(object):
|
|||||||
civ = self.ion.lobvalue()
|
civ = self.ion.lobvalue()
|
||||||
|
|
||||||
if ct is not None and civ is not None:
|
if ct is not None and civ is not None:
|
||||||
self.processpage(ct, civ, outpages, decompress)
|
self.processpage(ct, civ, outpages, decompress, decrypt)
|
||||||
|
self.ion.stepout()
|
||||||
|
|
||||||
|
elif self.ion.gettypename() in ["com.amazon.drm.PlainText@1.0", "com.amazon.drm.PlainText@2.0"]:
|
||||||
|
decompress = False
|
||||||
|
decrypt = False
|
||||||
|
plaintext = None
|
||||||
|
self.ion.stepin()
|
||||||
|
while self.ion.hasnext():
|
||||||
|
self.ion.next()
|
||||||
|
if self.ion.gettypename() == "com.amazon.drm.Compressed@1.0":
|
||||||
|
decompress = True
|
||||||
|
if self.ion.getfieldname() == "data":
|
||||||
|
plaintext = self.ion.lobvalue()
|
||||||
|
|
||||||
|
if plaintext is not None:
|
||||||
|
self.processpage(plaintext, None, outpages, decompress, decrypt)
|
||||||
self.ion.stepout()
|
self.ion.stepout()
|
||||||
|
|
||||||
self.ion.stepout()
|
self.ion.stepout()
|
||||||
@ -1017,9 +1034,12 @@ class DrmIon(object):
|
|||||||
def print_(self, lst):
|
def print_(self, lst):
|
||||||
self.ion.print_(lst)
|
self.ion.print_(lst)
|
||||||
|
|
||||||
def processpage(self, ct, civ, outpages, decompress):
|
def processpage(self, ct, civ, outpages, decompress, decrypt):
|
||||||
aes = AES.new(self.key[:16], AES.MODE_CBC, civ[:16])
|
if decrypt:
|
||||||
msg = pkcs7unpad(aes.decrypt(ct), 16)
|
aes = AES.new(self.key[:16], AES.MODE_CBC, civ[:16])
|
||||||
|
msg = pkcs7unpad(aes.decrypt(ct), 16)
|
||||||
|
else:
|
||||||
|
msg = ct
|
||||||
|
|
||||||
if not decompress:
|
if not decompress:
|
||||||
outpages.write(msg)
|
outpages.write(msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user