From ad5cb056f052e6dcc0fcb96021b21c80b0def731 Mon Sep 17 00:00:00 2001 From: penenkel <7736404+penenkel@users.noreply.github.com> Date: Mon, 30 Nov 2020 23:25:01 +0100 Subject: [PATCH 1/3] Add conversion from bytearray to bytes so that pids are hashable --- DeDRM_plugin/k4mobidedrm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DeDRM_plugin/k4mobidedrm.py b/DeDRM_plugin/k4mobidedrm.py index 43392ee..6f49dbb 100644 --- a/DeDRM_plugin/k4mobidedrm.py +++ b/DeDRM_plugin/k4mobidedrm.py @@ -228,7 +228,10 @@ def GetDecryptedBook(infile, kDatabases, androidFiles, serials, pids, starttime serials.extend(androidkindlekey.get_serials(aFile)) # extend PID list with book-specific PIDs from seriala and kDatabases md1, md2 = mb.getPIDMetaInfo() - totalpids.extend(kgenpids.getPidList(md1, md2, serials, kDatabases)) + bookspecific = kgenpids.getPidList(md1, md2, serials, kDatabases) + # kgenpids.getPidList returns each pid as a (mutable) bytearray + # conversion to (immutable) bytes is nessesary as otherwise the set() function below will fail + totalpids.extend((bytes(pid) for pid in bookspecific)) # remove any duplicates totalpids = list(set(totalpids)) print("Found {1:d} keys to try after {0:.1f} seconds".format(time.time()-starttime, len(totalpids))) From 6732be1434d16d675b3ac76f3713fabf4d8950a8 Mon Sep 17 00:00:00 2001 From: penenkel <7736404+penenkel@users.noreply.github.com> Date: Wed, 2 Dec 2020 22:34:29 +0100 Subject: [PATCH 2/3] `getPidList()` now returns pids as bytes instead of bytearrays --- DeDRM_plugin/kgenpids.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DeDRM_plugin/kgenpids.py b/DeDRM_plugin/kgenpids.py index 86ffab7..9800254 100644 --- a/DeDRM_plugin/kgenpids.py +++ b/DeDRM_plugin/kgenpids.py @@ -296,14 +296,14 @@ def getPidList(md1, md2, serials=[], kDatabases=[]): for kDatabase in kDatabases: try: - pidlst.extend(getK4Pids(md1, md2, kDatabase)) + pidlst.extend(map(bytes,getK4Pids(md1, md2, kDatabase))) except Exception as e: print("Error getting PIDs from database {0}: {1}".format(kDatabase[0],e.args[0])) traceback.print_exc() for serialnum in serials: try: - pidlst.extend(getKindlePids(md1, md2, serialnum)) + pidlst.extend(map(bytes,getKindlePids(md1, md2, serialnum))) except Exception as e: print("Error getting PIDs from serial number {0}: {1}".format(serialnum ,e.args[0])) traceback.print_exc() From a3cc22193251b1825e80248c88039b43f207feec Mon Sep 17 00:00:00 2001 From: penenkel <7736404+penenkel@users.noreply.github.com> Date: Wed, 2 Dec 2020 22:36:29 +0100 Subject: [PATCH 3/3] Revert changes to k4mobidedrm.py --- DeDRM_plugin/k4mobidedrm.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/DeDRM_plugin/k4mobidedrm.py b/DeDRM_plugin/k4mobidedrm.py index 6f49dbb..43392ee 100644 --- a/DeDRM_plugin/k4mobidedrm.py +++ b/DeDRM_plugin/k4mobidedrm.py @@ -228,10 +228,7 @@ def GetDecryptedBook(infile, kDatabases, androidFiles, serials, pids, starttime serials.extend(androidkindlekey.get_serials(aFile)) # extend PID list with book-specific PIDs from seriala and kDatabases md1, md2 = mb.getPIDMetaInfo() - bookspecific = kgenpids.getPidList(md1, md2, serials, kDatabases) - # kgenpids.getPidList returns each pid as a (mutable) bytearray - # conversion to (immutable) bytes is nessesary as otherwise the set() function below will fail - totalpids.extend((bytes(pid) for pid in bookspecific)) + totalpids.extend(kgenpids.getPidList(md1, md2, serials, kDatabases)) # remove any duplicates totalpids = list(set(totalpids)) print("Found {1:d} keys to try after {0:.1f} seconds".format(time.time()-starttime, len(totalpids)))