Python 3 fixes for Android kindle key retrieval
This commit is contained in:
parent
e0c7d7d382
commit
5ec9c98a0b
|
@ -2,7 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# androidkindlekey.py
|
# androidkindlekey.py
|
||||||
# Copyright © 2010-20 by Thom, Apprentice et al.
|
# Copyright © 2010-20 by Thom, Apprentice Harper et al.
|
||||||
|
|
||||||
# Revision history:
|
# Revision history:
|
||||||
# 1.0 - AmazonSecureStorage.xml decryption to serial number
|
# 1.0 - AmazonSecureStorage.xml decryption to serial number
|
||||||
|
@ -30,10 +30,7 @@ import tempfile
|
||||||
import zlib
|
import zlib
|
||||||
import tarfile
|
import tarfile
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
try:
|
from io import BytesIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import BytesIO as StringIO
|
|
||||||
from binascii import a2b_hex, b2a_hex
|
from binascii import a2b_hex, b2a_hex
|
||||||
|
|
||||||
# Routines common to Mac and PC
|
# Routines common to Mac and PC
|
||||||
|
@ -116,7 +113,7 @@ class AndroidObfuscation(object):
|
||||||
cipher = self._get_cipher()
|
cipher = self._get_cipher()
|
||||||
padding = len(self.key) - len(plaintext) % len(self.key)
|
padding = len(self.key) - len(plaintext) % len(self.key)
|
||||||
plaintext += chr(padding) * padding
|
plaintext += chr(padding) * padding
|
||||||
return b2a_hex(cipher.encrypt(plaintext))
|
return b2a_hex(cipher.encrypt(plaintext.encode('utf-8')))
|
||||||
|
|
||||||
def decrypt(self, ciphertext):
|
def decrypt(self, ciphertext):
|
||||||
cipher = self._get_cipher()
|
cipher = self._get_cipher()
|
||||||
|
@ -182,7 +179,7 @@ def get_serials1(path=STORAGE1):
|
||||||
obfuscation = AndroidObfuscation()
|
obfuscation = AndroidObfuscation()
|
||||||
|
|
||||||
def get_value(key):
|
def get_value(key):
|
||||||
encrypted_key = obfuscation.encrypt(a2b_hex(key))
|
encrypted_key = obfuscation.encrypt(key)
|
||||||
encrypted_value = storage.get(encrypted_key)
|
encrypted_value = storage.get(encrypted_key)
|
||||||
if encrypted_value:
|
if encrypted_value:
|
||||||
return obfuscation.decrypt(encrypted_value)
|
return obfuscation.decrypt(encrypted_value)
|
||||||
|
@ -198,6 +195,7 @@ def get_serials1(path=STORAGE1):
|
||||||
try:
|
try:
|
||||||
tokens = set(get_value('kindle.account.tokens').split(','))
|
tokens = set(get_value('kindle.account.tokens').split(','))
|
||||||
except:
|
except:
|
||||||
|
sys.stderr.write('cannot get kindle account tokens\n')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
serials = []
|
serials = []
|
||||||
|
@ -251,8 +249,8 @@ def get_serials2(path=STORAGE2):
|
||||||
|
|
||||||
serials = []
|
serials = []
|
||||||
for x in dsns:
|
for x in dsns:
|
||||||
for y in tokens:
|
|
||||||
serials.append(x)
|
serials.append(x)
|
||||||
|
for y in tokens:
|
||||||
serials.append(y)
|
serials.append(y)
|
||||||
serials.append(x+y)
|
serials.append(x+y)
|
||||||
return serials
|
return serials
|
||||||
|
@ -277,7 +275,7 @@ def get_serials(path=STORAGE):
|
||||||
read = open(path, 'rb')
|
read = open(path, 'rb')
|
||||||
head = read.read(24)
|
head = read.read(24)
|
||||||
if head[:14] == b'ANDROID BACKUP':
|
if head[:14] == b'ANDROID BACKUP':
|
||||||
output = StringIO(zlib.decompress(read.read()))
|
output = BytesIO(zlib.decompress(read.read()))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
|
@ -314,7 +312,7 @@ def getkey(outfile, inpath):
|
||||||
if len(keys) > 0:
|
if len(keys) > 0:
|
||||||
with open(outfile, 'w') as keyfileout:
|
with open(outfile, 'w') as keyfileout:
|
||||||
for key in keys:
|
for key in keys:
|
||||||
keyfileout.write(b2a_hex(key))
|
keyfileout.write(key)
|
||||||
keyfileout.write("\n")
|
keyfileout.write("\n")
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -391,7 +389,7 @@ def gui_main():
|
||||||
import tkinter.filedialog
|
import tkinter.filedialog
|
||||||
except:
|
except:
|
||||||
print("tkinter not installed")
|
print("tkinter not installed")
|
||||||
return cli_main()
|
return 0
|
||||||
|
|
||||||
class DecryptionDialog(tkinter.Frame):
|
class DecryptionDialog(tkinter.Frame):
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
|
|
Loading…
Reference in New Issue