(kInfoFile)
| 1017 | # determine type of kindle info provided and return a |
| 1018 | # database of keynames and values |
| 1019 | def getDBfromFile(kInfoFile): |
| 1020 | names = [\ |
| 1021 | b'kindle.account.tokens',\ |
| 1022 | b'kindle.cookie.item',\ |
| 1023 | b'eulaVersionAccepted',\ |
| 1024 | b'login_date',\ |
| 1025 | b'kindle.token.item',\ |
| 1026 | b'login',\ |
| 1027 | b'kindle.key.item',\ |
| 1028 | b'kindle.name.info',\ |
| 1029 | b'kindle.device.info',\ |
| 1030 | b'MazamaRandomNumber',\ |
| 1031 | b'max_date',\ |
| 1032 | b'SIGVERIF',\ |
| 1033 | b'build_version',\ |
| 1034 | b'SerialNumber',\ |
| 1035 | b'UsernameHash',\ |
| 1036 | b'kindle.directedid.info',\ |
| 1037 | b'DSN',\ |
| 1038 | b'kindle.accounttype.info',\ |
| 1039 | b'krx.flashcardsplugin.data.encryption_key',\ |
| 1040 | b'krx.notebookexportplugin.data.encryption_key',\ |
| 1041 | b'proxy.http.password',\ |
| 1042 | b'proxy.http.username' |
| 1043 | ] |
| 1044 | namehashmap = {encodeHash(n,testMap8):n for n in names} |
| 1045 | # print(namehashmap) |
| 1046 | DB = {} |
| 1047 | with open(kInfoFile, 'rb') as infoReader: |
| 1048 | data = infoReader.read() |
| 1049 | # assume .kinf2011 or .kinf2018 style .kinf file |
| 1050 | # the .kinf file uses "/" to separate it into records |
| 1051 | # so remove the trailing "/" to make it easy to use split |
| 1052 | data = data[:-1] |
| 1053 | items = data.split(b'/') |
| 1054 | |
| 1055 | # starts with an encoded and encrypted header blob |
| 1056 | headerblob = items.pop(0) |
| 1057 | encryptedValue = decode(headerblob, testMap1) |
| 1058 | cleartext = UnprotectHeaderData(encryptedValue) |
| 1059 | #print "header cleartext:",cleartext |
| 1060 | # now extract the pieces that form the added entropy |
| 1061 | pattern = re.compile(br'''\[Version:(\d+)\]\[Build:(\d+)\]\[Cksum:([^\]]+)\]\[Guid:([\{\}a-z0-9\-]+)\]''', re.IGNORECASE) |
| 1062 | for m in re.finditer(pattern, cleartext): |
| 1063 | version = int(m.group(1)) |
| 1064 | build = m.group(2) |
| 1065 | guid = m.group(4) |
| 1066 | |
| 1067 | if version == 5: # .kinf2011 |
| 1068 | added_entropy = build + guid |
| 1069 | elif version == 6: # .kinf2018 |
| 1070 | salt = str(0x6d8 * int(build)).encode('utf-8') + guid |
| 1071 | sp = GetUserName() + b'+@#$%+' + GetIDString().encode('utf-8') |
| 1072 | passwd = encode(SHA256(sp), charMap5) |
| 1073 | key = KeyIVGen().pbkdf2(passwd, salt, 10000, 0x400)[:32] # this is very slow |
| 1074 | |
| 1075 | # loop through the item records until all are processed |
| 1076 | while len(items) > 0: |
no test coverage detected