Skip to content

Commit

Permalink
More Py2 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
noDRM committed Aug 3, 2023
1 parent bc089ee commit d388ae7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
11 changes: 8 additions & 3 deletions DeDRM_plugin/kindlekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,14 @@ def GetUserName():

# 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')
Expand Down
11 changes: 7 additions & 4 deletions DeDRM_plugin/kindlepid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion DeDRM_plugin/mobidedrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d388ae7

Please sign in to comment.