From d388ae72fd797efcef3da2b4ff8694cfaa4431cb Mon Sep 17 00:00:00 2001 From: NoDRM Date: Thu, 3 Aug 2023 20:14:33 +0200 Subject: [PATCH] More Py2 fixes --- DeDRM_plugin/kindlekey.py | 11 ++++++++--- DeDRM_plugin/kindlepid.py | 11 +++++++---- DeDRM_plugin/mobidedrm.py | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/DeDRM_plugin/kindlekey.py b/DeDRM_plugin/kindlekey.py index 6297959..4e128c9 100644 --- a/DeDRM_plugin/kindlekey.py +++ b/DeDRM_plugin/kindlekey.py @@ -243,9 +243,14 @@ if iswindows: # replace any non-ASCII values with 0xfffd for i in range(0,len(buffer)): - if buffer[i]>"\u007f": - #print "swapping char "+str(i)+" ("+buffer[i]+")" - buffer[i] = "\ufffd" + if sys.version_info[0] == 2: + if buffer[i]>u"\u007f": + #print "swapping char "+str(i)+" ("+buffer[i]+")" + buffer[i] = u"\ufffd" + else: + if buffer[i]>"\u007f": + #print "swapping char "+str(i)+" ("+buffer[i]+")" + buffer[i] = "\ufffd" # return utf-8 encoding of modified username #print "modified username:"+buffer.value return buffer.value.encode('utf-8') diff --git a/DeDRM_plugin/kindlepid.py b/DeDRM_plugin/kindlepid.py index 24e0fe8..a034e40 100644 --- a/DeDRM_plugin/kindlepid.py +++ b/DeDRM_plugin/kindlepid.py @@ -33,7 +33,7 @@ def checksumPid(s): for i in (0,1): b = crc & 0xff pos = (b // l) ^ (b % l) - res += letters[pos%l] + res += bytes(bytearray([letters[pos%l]])) crc >>= 8 return res @@ -43,16 +43,19 @@ def pidFromSerial(s, l): arr1 = [0]*l for i in range(len(s)): - arr1[i%l] ^= s[i] + if sys.version_info[0] == 2: + arr1[i%l] ^= ord(s[i]) + else: + arr1[i%l] ^= s[i] crc_bytes = [crc >> 24 & 0xff, crc >> 16 & 0xff, crc >> 8 & 0xff, crc & 0xff] for i in range(l): arr1[i] ^= crc_bytes[i&3] - pid = '' + pid = b"" for i in range(l): b = arr1[i] & 0xff - pid+=letters[(b >> 7) + ((b >> 5 & 3) ^ (b & 0x1f))] + pid+=bytes(bytearray([letters[(b >> 7) + ((b >> 5 & 3) ^ (b & 0x1f))]])) return pid diff --git a/DeDRM_plugin/mobidedrm.py b/DeDRM_plugin/mobidedrm.py index 36d30c4..5989e8b 100755 --- a/DeDRM_plugin/mobidedrm.py +++ b/DeDRM_plugin/mobidedrm.py @@ -113,7 +113,7 @@ def checksumPid(s): for i in (0,1): b = crc & 0xff pos = (b // l) ^ (b % l) - res += letters[pos%l] + res += bytes(bytearray([letters[pos%l]])) crc >>= 8 return res