2020-09-27 16:54:49 +06:00
|
|
|
#!/usr/bin/env python3
|
2015-03-17 13:07:12 +06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# androidkindlekey.py
|
2020-09-27 16:54:49 +06:00
|
|
|
# Copyright © 2010-20 by Thom, Apprentice et al.
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
# Revision history:
|
2015-03-26 13:31:45 +06:00
|
|
|
# 1.0 - AmazonSecureStorage.xml decryption to serial number
|
|
|
|
# 1.1 - map_data_storage.db decryption to serial number
|
2015-04-13 12:45:43 +06:00
|
|
|
# 1.2 - Changed to be callable from AppleScript by returning only serial number
|
|
|
|
# - and changed name to androidkindlekey.py
|
|
|
|
# - and added in unicode command line support
|
2015-07-29 23:11:19 +06:00
|
|
|
# 1.3 - added in TkInter interface, output to a file
|
|
|
|
# 1.4 - Fix some problems identified by Aldo Bleeker
|
2015-09-03 12:51:10 +06:00
|
|
|
# 1.5 - Fix another problem identified by Aldo Bleeker
|
2020-09-27 16:54:49 +06:00
|
|
|
# 2.0 - Python 3 compatibility
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
"""
|
|
|
|
Retrieve Kindle for Android Serial Number.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__license__ = 'GPL v3'
|
2020-09-27 02:22:47 +06:00
|
|
|
__version__ = '2.0'
|
2013-10-03 00:59:40 +06:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2015-09-03 12:51:10 +06:00
|
|
|
import traceback
|
2015-03-17 13:07:12 +06:00
|
|
|
import getopt
|
|
|
|
import tempfile
|
2013-10-03 00:59:40 +06:00
|
|
|
import zlib
|
|
|
|
import tarfile
|
|
|
|
from hashlib import md5
|
2020-09-27 02:22:47 +06:00
|
|
|
try:
|
|
|
|
from cStringIO import StringIO
|
|
|
|
except ImportError:
|
|
|
|
from io import BytesIO as StringIO
|
2013-10-03 00:59:40 +06:00
|
|
|
from binascii import a2b_hex, b2a_hex
|
|
|
|
|
2015-03-17 13:07:12 +06:00
|
|
|
# Routines common to Mac and PC
|
|
|
|
|
|
|
|
# Wrap a stream so that output gets flushed immediately
|
|
|
|
# and also make sure that any unicode strings get
|
|
|
|
# encoded using "replace" before writing them.
|
|
|
|
class SafeUnbuffered:
|
|
|
|
def __init__(self, stream):
|
|
|
|
self.stream = stream
|
|
|
|
self.encoding = stream.encoding
|
|
|
|
if self.encoding == None:
|
|
|
|
self.encoding = "utf-8"
|
|
|
|
def write(self, data):
|
2020-09-27 16:54:49 +06:00
|
|
|
if isinstance(data,str):
|
2015-03-17 13:07:12 +06:00
|
|
|
data = data.encode(self.encoding,"replace")
|
2020-09-27 16:54:49 +06:00
|
|
|
self.stream.buffer.write(data)
|
|
|
|
self.stream.buffer.flush()
|
|
|
|
|
2015-03-17 13:07:12 +06:00
|
|
|
def __getattr__(self, attr):
|
|
|
|
return getattr(self.stream, attr)
|
|
|
|
|
|
|
|
try:
|
|
|
|
from calibre.constants import iswindows, isosx
|
|
|
|
except:
|
|
|
|
iswindows = sys.platform.startswith('win')
|
|
|
|
isosx = sys.platform.startswith('darwin')
|
|
|
|
|
|
|
|
def unicode_argv():
|
|
|
|
if iswindows:
|
|
|
|
# Uses shell32.GetCommandLineArgvW to get sys.argv as a list of Unicode
|
|
|
|
# strings.
|
|
|
|
|
|
|
|
# Versions 2.x of Python don't support Unicode in sys.argv on
|
|
|
|
# Windows, with the underlying Windows API instead replacing multi-byte
|
|
|
|
# characters with '?'. So use shell32.GetCommandLineArgvW to get sys.argv
|
|
|
|
# as a list of Unicode strings and encode them as utf-8
|
|
|
|
|
|
|
|
from ctypes import POINTER, byref, cdll, c_int, windll
|
|
|
|
from ctypes.wintypes import LPCWSTR, LPWSTR
|
|
|
|
|
|
|
|
GetCommandLineW = cdll.kernel32.GetCommandLineW
|
|
|
|
GetCommandLineW.argtypes = []
|
|
|
|
GetCommandLineW.restype = LPCWSTR
|
|
|
|
|
|
|
|
CommandLineToArgvW = windll.shell32.CommandLineToArgvW
|
|
|
|
CommandLineToArgvW.argtypes = [LPCWSTR, POINTER(c_int)]
|
|
|
|
CommandLineToArgvW.restype = POINTER(LPWSTR)
|
|
|
|
|
|
|
|
cmd = GetCommandLineW()
|
|
|
|
argc = c_int(0)
|
|
|
|
argv = CommandLineToArgvW(cmd, byref(argc))
|
|
|
|
if argc.value > 0:
|
|
|
|
# Remove Python executable and commands if present
|
|
|
|
start = argc.value - len(sys.argv)
|
|
|
|
return [argv[i] for i in
|
2020-09-27 02:22:47 +06:00
|
|
|
range(start, argc.value)]
|
2015-03-17 13:07:12 +06:00
|
|
|
# if we don't have any arguments at all, just pass back script name
|
|
|
|
# this should never happen
|
2020-09-27 16:54:49 +06:00
|
|
|
return ["kindlekey.py"]
|
2015-03-17 13:07:12 +06:00
|
|
|
else:
|
2020-10-05 01:36:12 +06:00
|
|
|
argvencoding = sys.stdin.encoding or "utf-8"
|
|
|
|
return [arg if isinstance(arg, str) else str(arg, argvencoding) for arg in sys.argv]
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
class DrmException(Exception):
|
|
|
|
pass
|
|
|
|
|
2020-09-27 16:54:49 +06:00
|
|
|
STORAGE = "backup.ab"
|
|
|
|
STORAGE1 = "AmazonSecureStorage.xml"
|
|
|
|
STORAGE2 = "map_data_storage.db"
|
2013-10-03 00:59:40 +06:00
|
|
|
|
|
|
|
class AndroidObfuscation(object):
|
|
|
|
'''AndroidObfuscation
|
|
|
|
For the key, it's written in java, and run in android dalvikvm
|
|
|
|
'''
|
|
|
|
|
|
|
|
key = a2b_hex('0176e04c9408b1702d90be333fd53523')
|
|
|
|
|
|
|
|
def encrypt(self, plaintext):
|
|
|
|
cipher = self._get_cipher()
|
|
|
|
padding = len(self.key) - len(plaintext) % len(self.key)
|
|
|
|
plaintext += chr(padding) * padding
|
|
|
|
return b2a_hex(cipher.encrypt(plaintext))
|
|
|
|
|
|
|
|
def decrypt(self, ciphertext):
|
|
|
|
cipher = self._get_cipher()
|
|
|
|
plaintext = cipher.decrypt(a2b_hex(ciphertext))
|
|
|
|
return plaintext[:-ord(plaintext[-1])]
|
|
|
|
|
|
|
|
def _get_cipher(self):
|
|
|
|
try:
|
|
|
|
from Crypto.Cipher import AES
|
|
|
|
return AES.new(self.key)
|
|
|
|
except ImportError:
|
|
|
|
from aescbc import AES, noPadding
|
|
|
|
return AES(self.key, padding=noPadding())
|
|
|
|
|
|
|
|
class AndroidObfuscationV2(AndroidObfuscation):
|
|
|
|
'''AndroidObfuscationV2
|
|
|
|
'''
|
|
|
|
|
|
|
|
count = 503
|
|
|
|
password = 'Thomsun was here!'
|
|
|
|
|
|
|
|
def __init__(self, salt):
|
|
|
|
key = self.password + salt
|
|
|
|
for _ in range(self.count):
|
|
|
|
key = md5(key).digest()
|
|
|
|
self.key = key[:8]
|
|
|
|
self.iv = key[8:16]
|
|
|
|
|
|
|
|
def _get_cipher(self):
|
|
|
|
try :
|
|
|
|
from Crypto.Cipher import DES
|
|
|
|
return DES.new(self.key, DES.MODE_CBC, self.iv)
|
|
|
|
except ImportError:
|
|
|
|
from python_des import Des, CBC
|
|
|
|
return Des(self.key, CBC, self.iv)
|
|
|
|
|
|
|
|
def parse_preference(path):
|
|
|
|
''' parse android's shared preference xml '''
|
|
|
|
storage = {}
|
|
|
|
read = open(path)
|
|
|
|
for line in read:
|
|
|
|
line = line.strip()
|
|
|
|
# <string name="key">value</string>
|
|
|
|
if line.startswith('<string name="'):
|
|
|
|
index = line.find('"', 14)
|
|
|
|
key = line[14:index]
|
|
|
|
value = line[index+2:-9]
|
|
|
|
storage[key] = value
|
|
|
|
read.close()
|
|
|
|
return storage
|
|
|
|
|
2015-03-17 13:07:12 +06:00
|
|
|
def get_serials1(path=STORAGE1):
|
2013-10-03 00:59:40 +06:00
|
|
|
''' get serials from android's shared preference xml '''
|
|
|
|
|
|
|
|
if not os.path.isfile(path):
|
|
|
|
return []
|
|
|
|
|
|
|
|
storage = parse_preference(path)
|
|
|
|
salt = storage.get('AmazonSaltKey')
|
|
|
|
if salt and len(salt) == 16:
|
|
|
|
obfuscation = AndroidObfuscationV2(a2b_hex(salt))
|
|
|
|
else:
|
|
|
|
obfuscation = AndroidObfuscation()
|
|
|
|
|
|
|
|
def get_value(key):
|
|
|
|
encrypted_key = obfuscation.encrypt(key)
|
|
|
|
encrypted_value = storage.get(encrypted_key)
|
|
|
|
if encrypted_value:
|
|
|
|
return obfuscation.decrypt(encrypted_value)
|
|
|
|
return ''
|
|
|
|
|
|
|
|
# also see getK4Pids in kgenpids.py
|
|
|
|
try:
|
|
|
|
dsnid = get_value('DsnId')
|
|
|
|
except:
|
|
|
|
sys.stderr.write('cannot get DsnId\n')
|
|
|
|
return []
|
|
|
|
|
|
|
|
try:
|
|
|
|
tokens = set(get_value('kindle.account.tokens').split(','))
|
|
|
|
except:
|
2015-03-09 13:38:31 +06:00
|
|
|
return []
|
2013-10-03 00:59:40 +06:00
|
|
|
|
|
|
|
serials = []
|
2015-07-29 23:11:19 +06:00
|
|
|
if dsnid:
|
|
|
|
serials.append(dsnid)
|
2013-10-03 00:59:40 +06:00
|
|
|
for token in tokens:
|
|
|
|
if token:
|
|
|
|
serials.append('%s%s' % (dsnid, token))
|
2015-07-29 23:11:19 +06:00
|
|
|
serials.append(token)
|
2015-03-09 13:38:31 +06:00
|
|
|
return serials
|
|
|
|
|
|
|
|
def get_serials2(path=STORAGE2):
|
2015-07-29 23:11:19 +06:00
|
|
|
''' get serials from android's sql database '''
|
2015-03-17 13:07:12 +06:00
|
|
|
if not os.path.isfile(path):
|
|
|
|
return []
|
|
|
|
|
2015-03-09 13:38:31 +06:00
|
|
|
import sqlite3
|
|
|
|
connection = sqlite3.connect(path)
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute('''select userdata_value from userdata where userdata_key like '%/%token.device.deviceserialname%' ''')
|
2015-07-29 23:11:19 +06:00
|
|
|
userdata_keys = cursor.fetchall()
|
|
|
|
dsns = []
|
|
|
|
for userdata_row in userdata_keys:
|
2015-09-03 12:51:10 +06:00
|
|
|
try:
|
|
|
|
if userdata_row and userdata_row[0]:
|
|
|
|
userdata_utf8 = userdata_row[0].encode('utf8')
|
|
|
|
if len(userdata_utf8) > 0:
|
|
|
|
dsns.append(userdata_utf8)
|
|
|
|
except:
|
2019-06-24 22:49:38 +06:00
|
|
|
print("Error getting one of the device serial name keys")
|
2015-09-03 12:51:10 +06:00
|
|
|
traceback.print_exc()
|
|
|
|
pass
|
2015-07-29 23:11:19 +06:00
|
|
|
dsns = list(set(dsns))
|
2015-03-09 13:38:31 +06:00
|
|
|
|
|
|
|
cursor.execute('''select userdata_value from userdata where userdata_key like '%/%kindle.account.tokens%' ''')
|
2015-07-29 23:11:19 +06:00
|
|
|
userdata_keys = cursor.fetchall()
|
|
|
|
tokens = []
|
|
|
|
for userdata_row in userdata_keys:
|
2015-09-03 12:51:10 +06:00
|
|
|
try:
|
|
|
|
if userdata_row and userdata_row[0]:
|
|
|
|
userdata_utf8 = userdata_row[0].encode('utf8')
|
|
|
|
if len(userdata_utf8) > 0:
|
|
|
|
tokens.append(userdata_utf8)
|
|
|
|
except:
|
2019-06-24 22:49:38 +06:00
|
|
|
print("Error getting one of the account token keys")
|
2015-09-03 12:51:10 +06:00
|
|
|
traceback.print_exc()
|
|
|
|
pass
|
2015-07-29 23:11:19 +06:00
|
|
|
tokens = list(set(tokens))
|
2020-09-27 02:22:47 +06:00
|
|
|
|
2015-03-09 13:38:31 +06:00
|
|
|
serials = []
|
|
|
|
for x in dsns:
|
2015-07-29 23:11:19 +06:00
|
|
|
serials.append(x)
|
2015-03-09 13:38:31 +06:00
|
|
|
for y in tokens:
|
|
|
|
serials.append('%s%s' % (x, y))
|
2015-07-29 23:11:19 +06:00
|
|
|
for y in tokens:
|
|
|
|
serials.append(y)
|
2013-10-03 00:59:40 +06:00
|
|
|
return serials
|
|
|
|
|
2015-03-17 13:07:12 +06:00
|
|
|
def get_serials(path=STORAGE):
|
|
|
|
'''get serials from files in from android backup.ab
|
2013-10-03 00:59:40 +06:00
|
|
|
backup.ab can be get using adb command:
|
|
|
|
shell> adb backup com.amazon.kindle
|
2015-03-17 13:07:12 +06:00
|
|
|
or from individual files if they're passed.
|
2013-10-03 00:59:40 +06:00
|
|
|
'''
|
2015-03-09 13:38:31 +06:00
|
|
|
if not os.path.isfile(path):
|
2015-03-17 13:07:12 +06:00
|
|
|
return []
|
|
|
|
|
|
|
|
basename = os.path.basename(path)
|
|
|
|
if basename == STORAGE1:
|
|
|
|
return get_serials1(path)
|
|
|
|
elif basename == STORAGE2:
|
|
|
|
return get_serials2(path)
|
|
|
|
|
2013-10-03 00:59:40 +06:00
|
|
|
output = None
|
2015-03-17 13:07:12 +06:00
|
|
|
try :
|
|
|
|
read = open(path, 'rb')
|
|
|
|
head = read.read(24)
|
|
|
|
if head[:14] == 'ANDROID BACKUP':
|
|
|
|
output = StringIO(zlib.decompress(read.read()))
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
read.close()
|
2013-10-03 00:59:40 +06:00
|
|
|
|
|
|
|
if not output:
|
2015-03-09 13:38:31 +06:00
|
|
|
return []
|
2013-10-03 00:59:40 +06:00
|
|
|
|
2015-03-09 13:38:31 +06:00
|
|
|
serials = []
|
2013-10-03 00:59:40 +06:00
|
|
|
tar = tarfile.open(fileobj=output)
|
|
|
|
for member in tar.getmembers():
|
2015-03-17 13:07:12 +06:00
|
|
|
if member.name.strip().endswith(STORAGE1):
|
2015-03-19 01:12:01 +06:00
|
|
|
write = tempfile.NamedTemporaryFile(mode='wb', delete=False)
|
2015-03-09 13:38:31 +06:00
|
|
|
write.write(tar.extractfile(member).read())
|
|
|
|
write.close()
|
2015-03-17 13:07:12 +06:00
|
|
|
write_path = os.path.abspath(write.name)
|
|
|
|
serials.extend(get_serials1(write_path))
|
|
|
|
os.remove(write_path)
|
|
|
|
elif member.name.strip().endswith(STORAGE2):
|
2015-03-19 01:12:01 +06:00
|
|
|
write = tempfile.NamedTemporaryFile(mode='wb', delete=False)
|
2013-10-03 00:59:40 +06:00
|
|
|
write.write(tar.extractfile(member).read())
|
|
|
|
write.close()
|
2015-03-17 13:07:12 +06:00
|
|
|
write_path = os.path.abspath(write.name)
|
|
|
|
serials.extend(get_serials2(write_path))
|
|
|
|
os.remove(write_path)
|
2015-07-29 23:11:19 +06:00
|
|
|
return list(set(serials))
|
2013-10-03 00:59:40 +06:00
|
|
|
|
2015-03-24 13:04:06 +06:00
|
|
|
__all__ = [ 'get_serials', 'getkey']
|
|
|
|
|
2015-07-29 23:11:19 +06:00
|
|
|
# procedure for CLI and GUI interfaces
|
|
|
|
# returns single or multiple keys (one per line) in the specified file
|
|
|
|
def getkey(outfile, inpath):
|
2015-03-24 13:04:06 +06:00
|
|
|
keys = get_serials(inpath)
|
|
|
|
if len(keys) > 0:
|
2020-09-27 02:22:47 +06:00
|
|
|
with open(outfile, 'w') as keyfileout:
|
2015-03-24 13:04:06 +06:00
|
|
|
for key in keys:
|
2015-07-29 23:11:19 +06:00
|
|
|
keyfileout.write(key)
|
|
|
|
keyfileout.write("\n")
|
2015-03-24 13:04:06 +06:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
def usage(progname):
|
2020-09-27 16:54:49 +06:00
|
|
|
print("Decrypts the serial number(s) of Kindle For Android from Android backup or file")
|
|
|
|
print("Get backup.ab file using adb backup com.amazon.kindle for Android 4.0+.")
|
|
|
|
print("Otherwise extract AmazonSecureStorage.xml from /data/data/com.amazon.kindle/shared_prefs/AmazonSecureStorage.xml")
|
|
|
|
print("Or map_data_storage.db from /data/data/com.amazon.kindle/databases/map_data_storage.db")
|
2019-06-24 22:49:38 +06:00
|
|
|
print(u"")
|
2020-09-27 16:54:49 +06:00
|
|
|
print("Usage:")
|
|
|
|
print(" {0:s} [-h] [-b <backup.ab>] [<outfile.k4a>]".format(progname))
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
|
|
|
|
def cli_main():
|
|
|
|
sys.stdout=SafeUnbuffered(sys.stdout)
|
|
|
|
sys.stderr=SafeUnbuffered(sys.stderr)
|
|
|
|
argv=unicode_argv()
|
|
|
|
progname = os.path.basename(argv[0])
|
2020-10-05 01:36:12 +06:00
|
|
|
print("{0} v{1}\nCopyright © 2010-2020 Thom, Apprentice Harper et al.".format(progname,__version__))
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
try:
|
2015-03-24 13:04:06 +06:00
|
|
|
opts, args = getopt.getopt(argv[1:], "hb:")
|
2020-09-27 02:22:47 +06:00
|
|
|
except getopt.GetoptError as err:
|
2015-03-17 13:07:12 +06:00
|
|
|
usage(progname)
|
2020-09-27 16:54:49 +06:00
|
|
|
print("\nError in options or arguments: {0}".format(err.args[0]))
|
2015-03-17 13:07:12 +06:00
|
|
|
return 2
|
|
|
|
|
2015-03-24 13:04:06 +06:00
|
|
|
inpath = ""
|
2015-03-17 13:07:12 +06:00
|
|
|
for o, a in opts:
|
|
|
|
if o == "-h":
|
|
|
|
usage(progname)
|
|
|
|
return 0
|
2015-03-24 13:04:06 +06:00
|
|
|
if o == "-b":
|
|
|
|
inpath = a
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
if len(args) > 1:
|
|
|
|
usage(progname)
|
|
|
|
return 2
|
|
|
|
|
2015-03-24 13:04:06 +06:00
|
|
|
if len(args) == 1:
|
|
|
|
# save to the specified file or directory
|
2015-07-29 23:11:19 +06:00
|
|
|
outfile = args[0]
|
|
|
|
if not os.path.isabs(outfile):
|
|
|
|
outfile = os.path.join(os.path.dirname(argv[0]),outfile)
|
|
|
|
outfile = os.path.abspath(outfile)
|
|
|
|
if os.path.isdir(outfile):
|
|
|
|
outfile = os.path.join(os.path.dirname(argv[0]),"androidkindlekey.k4a")
|
2015-03-24 13:04:06 +06:00
|
|
|
else:
|
|
|
|
# save to the same directory as the script
|
2015-07-29 23:11:19 +06:00
|
|
|
outfile = os.path.join(os.path.dirname(argv[0]),"androidkindlekey.k4a")
|
2015-03-17 13:07:12 +06:00
|
|
|
|
2015-03-24 13:04:06 +06:00
|
|
|
# make sure the outpath is OK
|
2015-07-29 23:11:19 +06:00
|
|
|
outfile = os.path.realpath(os.path.normpath(outfile))
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
if not os.path.isfile(inpath):
|
|
|
|
usage(progname)
|
2020-09-27 16:54:49 +06:00
|
|
|
print("\n{0:s} file not found".format(inpath))
|
2015-03-17 13:07:12 +06:00
|
|
|
return 2
|
|
|
|
|
2015-07-29 23:11:19 +06:00
|
|
|
if getkey(outfile, inpath):
|
2020-09-27 16:54:49 +06:00
|
|
|
print("\nSaved Kindle for Android key to {0}".format(outfile))
|
2015-07-29 23:11:19 +06:00
|
|
|
else:
|
2020-09-27 16:54:49 +06:00
|
|
|
print("\nCould not retrieve Kindle for Android key.")
|
2015-03-24 13:04:06 +06:00
|
|
|
return 0
|
2015-03-17 13:07:12 +06:00
|
|
|
|
|
|
|
|
2015-03-24 13:04:06 +06:00
|
|
|
def gui_main():
|
|
|
|
try:
|
2020-10-05 01:36:12 +06:00
|
|
|
import tkinter
|
|
|
|
import tkinter.constants
|
|
|
|
import tkinter.messagebox
|
|
|
|
import tkinter.filedialog
|
2015-03-24 13:04:06 +06:00
|
|
|
except:
|
2020-10-05 01:36:12 +06:00
|
|
|
print("tkinter not installed")
|
2015-03-24 13:04:06 +06:00
|
|
|
return cli_main()
|
|
|
|
|
2020-10-05 01:36:12 +06:00
|
|
|
class DecryptionDialog(tkinter.Frame):
|
2015-03-24 13:04:06 +06:00
|
|
|
def __init__(self, root):
|
2020-10-05 01:36:12 +06:00
|
|
|
tkinter.Frame.__init__(self, root, border=5)
|
|
|
|
self.status = tkinter.Label(self, text="Select backup.ab file")
|
|
|
|
self.status.pack(fill=tkinter.constants.X, expand=1)
|
|
|
|
body = tkinter.Frame(self)
|
|
|
|
body.pack(fill=tkinter.constants.X, expand=1)
|
|
|
|
sticky = tkinter.constants.E + tkinter.constants.W
|
2015-03-24 13:04:06 +06:00
|
|
|
body.grid_columnconfigure(1, weight=2)
|
2020-10-05 01:36:12 +06:00
|
|
|
tkinter.Label(body, text="Backup file").grid(row=0, column=0)
|
|
|
|
self.keypath = tkinter.Entry(body, width=40)
|
2015-03-24 13:04:06 +06:00
|
|
|
self.keypath.grid(row=0, column=1, sticky=sticky)
|
2020-09-27 16:54:49 +06:00
|
|
|
self.keypath.insert(2, "backup.ab")
|
2020-10-05 01:36:12 +06:00
|
|
|
button = tkinter.Button(body, text="...", command=self.get_keypath)
|
2015-03-24 13:04:06 +06:00
|
|
|
button.grid(row=0, column=2)
|
2020-10-05 01:36:12 +06:00
|
|
|
buttons = tkinter.Frame(self)
|
2015-03-24 13:04:06 +06:00
|
|
|
buttons.pack()
|
2020-10-05 01:36:12 +06:00
|
|
|
button2 = tkinter.Button(
|
2020-09-27 16:54:49 +06:00
|
|
|
buttons, text="Extract", width=10, command=self.generate)
|
2020-10-05 01:36:12 +06:00
|
|
|
button2.pack(side=tkinter.constants.LEFT)
|
|
|
|
tkinter.Frame(buttons, width=10).pack(side=tkinter.constants.LEFT)
|
|
|
|
button3 = tkinter.Button(
|
2020-09-27 16:54:49 +06:00
|
|
|
buttons, text="Quit", width=10, command=self.quit)
|
2020-10-05 01:36:12 +06:00
|
|
|
button3.pack(side=tkinter.constants.RIGHT)
|
2015-03-24 13:04:06 +06:00
|
|
|
|
|
|
|
def get_keypath(self):
|
2020-10-05 01:36:12 +06:00
|
|
|
keypath = tkinter.filedialog.askopenfilename(
|
2020-09-27 16:54:49 +06:00
|
|
|
parent=None, title="Select backup.ab file",
|
|
|
|
defaultextension=".ab",
|
2015-03-24 13:04:06 +06:00
|
|
|
filetypes=[('adb backup com.amazon.kindle', '.ab'),
|
|
|
|
('All Files', '.*')])
|
|
|
|
if keypath:
|
|
|
|
keypath = os.path.normpath(keypath)
|
2020-10-05 01:36:12 +06:00
|
|
|
self.keypath.delete(0, tkinter.constants.END)
|
2015-03-24 13:04:06 +06:00
|
|
|
self.keypath.insert(0, keypath)
|
|
|
|
return
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
inpath = self.keypath.get()
|
2020-09-27 16:54:49 +06:00
|
|
|
self.status['text'] = "Getting key..."
|
2015-03-24 13:04:06 +06:00
|
|
|
try:
|
|
|
|
keys = get_serials(inpath)
|
|
|
|
keycount = 0
|
|
|
|
for key in keys:
|
|
|
|
while True:
|
|
|
|
keycount += 1
|
2020-09-27 16:54:49 +06:00
|
|
|
outfile = os.path.join(progpath,"kindlekey{0:d}.k4a".format(keycount))
|
2015-03-24 13:04:06 +06:00
|
|
|
if not os.path.exists(outfile):
|
|
|
|
break
|
|
|
|
|
2020-09-27 02:22:47 +06:00
|
|
|
with open(outfile, 'w') as keyfileout:
|
2015-03-24 13:04:06 +06:00
|
|
|
keyfileout.write(key)
|
|
|
|
success = True
|
2020-10-05 01:36:12 +06:00
|
|
|
tkinter.messagebox.showinfo(progname, "Key successfully retrieved to {0}".format(outfile))
|
2020-09-27 02:22:47 +06:00
|
|
|
except Exception as e:
|
2020-09-27 16:54:49 +06:00
|
|
|
self.status['text'] = "Error: {0}".format(e.args[0])
|
2015-03-24 13:04:06 +06:00
|
|
|
return
|
2020-09-27 16:54:49 +06:00
|
|
|
self.status['text'] = "Select backup.ab file"
|
2015-03-24 13:04:06 +06:00
|
|
|
|
|
|
|
argv=unicode_argv()
|
|
|
|
progpath, progname = os.path.split(argv[0])
|
2020-10-05 01:36:12 +06:00
|
|
|
root = tkinter.Tk()
|
2020-09-27 16:54:49 +06:00
|
|
|
root.title("Kindle for Android Key Extraction v.{0}".format(__version__))
|
2015-03-24 13:04:06 +06:00
|
|
|
root.resizable(True, False)
|
|
|
|
root.minsize(300, 0)
|
2020-10-05 01:36:12 +06:00
|
|
|
DecryptionDialog(root).pack(fill=tkinter.constants.X, expand=1)
|
2015-03-24 13:04:06 +06:00
|
|
|
root.mainloop()
|
2015-03-17 13:07:12 +06:00
|
|
|
return 0
|
2013-10-03 00:59:40 +06:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-03-17 13:07:12 +06:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
sys.exit(cli_main())
|
2015-03-24 13:04:06 +06:00
|
|
|
sys.exit(gui_main())
|