Skip to content

Commit

Permalink
Fix for Kindle problem in Mac app and non-ascii username problem in W…
Browse files Browse the repository at this point in the history
…indows (plugin and app).
  • Loading branch information
apprenticealf committed Mar 25, 2015
1 parent 9d9c879 commit e729ae8
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 683 deletions.
4 changes: 2 additions & 2 deletions DeDRM_Macintosh_Application/DeDRM.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<key>CFBundleExecutable</key>
<string>droplet</string>
<key>CFBundleGetInfoString</key>
<string>DeDRM AppleScript 6.2.0. Written 2010–2015 by Apprentice Alf et al.</string>
<string>DeDRM AppleScript 6.2.1 Written 2010–2015 by Apprentice Alf et al.</string>
<key>CFBundleIconFile</key>
<string>DeDRM</string>
<key>CFBundleIdentifier</key>
Expand All @@ -36,7 +36,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>6.2.0</string>
<string>6.2.1</string>
<key>CFBundleSignature</key>
<string>dplt</string>
<key>LSRequiresCarbon</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<body>

<h1>DeDRM Plugin <span class="version">(v6.1.0)</span></h1>
<h1>DeDRM Plugin <span class="version">(v6.2.1)</span></h1>

<p>This plugin removes DRM from ebooks when they are imported into calibre. If you already have DRMed ebooks in your calibre library, you will need to remove them and import them again.</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
# 6.1.0 - Fixed multiple books import problem and PDF import with no key problem
# 6.2.0 - Support for getting B&N key from nook Study log. Fix for UTF-8 filenames in Adobe ePubs.
# Fix for not copying needed files. Fix for getting default Adobe key for PDFs
# 6.2.1 - Fix for non-ascii Windows user names

"""
Decrypt DRMed ebooks.
"""

PLUGIN_NAME = u"DeDRM"
PLUGIN_VERSION_TUPLE = (6, 2, 0)
PLUGIN_VERSION_TUPLE = (6, 2, 1)
PLUGIN_VERSION = u".".join([unicode(str(x)) for x in PLUGIN_VERSION_TUPLE])
# Include an html helpfile in the plugin's zipfile with the following name.
RESOURCE_NAME = PLUGIN_NAME + '_Help.htm'
Expand Down Expand Up @@ -89,7 +90,7 @@ class DeDRM(FileTypePlugin):
author = u"DiapDealer, Apprentice Alf, The Dark Reverser and i♥cabbages"
version = PLUGIN_VERSION_TUPLE
minimum_calibre_version = (0, 7, 55) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['epub','pdf','pdb','prc','mobi','azw','azw1','azw3','azw4','tpz'])
file_types = set(['epub','pdf','pdb','prc','mobi','pobi','azw','azw1','azw3','azw4','tpz'])
on_import = True
priority = 600

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#!/usr/bin/env python
#fileencoding: utf-8

# android.py
# Copyright © 2013-2015 by Thom and Apprentice Harper

# Revision history:
# 1.0 - AmazonSecureStorage.xml decryption to serial number
# 1.1 - map_data_storage.db decryption to serial number
# 1.2 - BugFix

import os
import sys
import zlib
Expand Down Expand Up @@ -80,7 +88,7 @@ def get_serials(path=None):
if path is None and os.path.isfile("backup.ab"):
return get_storage()

if not os.path.isfile(path):
if path is None or not os.path.isfile(path):
return []

storage = parse_preference(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# -*- coding: utf-8 -*-

from __future__ import with_statement

# kgenpids.py
# Copyright © 2010-2015 by some_updates, Apprentice Alf and Apprentice Harper

# Revision history:
# 2.0 - Fix for non-ascii Windows user names

import sys
import os, csv
import binascii
Expand Down Expand Up @@ -164,7 +171,7 @@ def getKindlePids(rec209, token, serialnum):
pids=[]

if isinstance(serialnum,unicode):
serialnum = serialnum.encode('ascii')
serialnum = serialnum.encode('utf-8')

# Compute book PID
pidHash = SHA1(serialnum+rec209+token)
Expand All @@ -190,16 +197,16 @@ def getK4Pids(rec209, token, kindleDatabase):

try:
# Get the Mazama Random number
MazamaRandomNumber = (kindleDatabase[1])['MazamaRandomNumber'].decode('hex').encode('ascii')
MazamaRandomNumber = (kindleDatabase[1])['MazamaRandomNumber'].decode('hex')

# Get the kindle account token
kindleAccountToken = (kindleDatabase[1])['kindle.account.tokens'].decode('hex').encode('ascii')
kindleAccountToken = (kindleDatabase[1])['kindle.account.tokens'].decode('hex')

# Get the IDString used to decode the Kindle Info file
IDString = (kindleDatabase[1])['IDString'].decode('hex').encode('ascii')
IDString = (kindleDatabase[1])['IDString'].decode('hex')

# Get the UserName stored when the Kindle Info file was decoded
UserName = (kindleDatabase[1])['UserName'].decode('hex').encode('ascii')
UserName = (kindleDatabase[1])['UserName'].decode('hex')

except KeyError:
print u"Keys not found in the database {0}.".format(kindleDatabase[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from __future__ import with_statement

# kindlekey.py
# Copyright © 2010-2013 by some_updates and Apprentice Alf
#
# Currently requires alfcrypto.py which requires the alfcrypto library
# Copyright © 2010-2015 by some_updates, Apprentice Alf and Apprentice Harper

# Revision history:
# 1.0 - Kindle info file decryption, extracted from k4mobidedrm, etc.
Expand All @@ -20,6 +18,7 @@
# 1.7 - Work if TkInter is missing
# 1.8 - Fixes for Kindle for Mac, and non-ascii in Windows user names
# 1.9 - Fixes for Unicode in Windows user names
# 2.0 - Added comments and extra fix for non-ascii Windows user names


"""
Expand Down Expand Up @@ -885,6 +884,7 @@ def GetUserName():
return "AlternateUserName"
buffer = create_unicode_buffer(len(buffer) * 2)
size.value = len(buffer)
# return low byte of the unicode value of each character of the username
return buffer.value.encode('utf-16-le')[::2]
return GetUserName
GetUserName = GetUserName()
Expand Down Expand Up @@ -1161,10 +1161,10 @@ def getDBfromFile(kInfoFile):
DB[keyname] = cleartext

if 'kindle.account.tokens' in DB:
print u"Decrypted key file using IDString '{0:s}' and UserName '{1:s}'".format(GetIDString(), GetUserName().decode("latin-1"))
# store values used in decryption
DB['IDString'] = GetIDString()
DB['UserName'] = GetUserName()
print u"Decrypted key file using IDString '{0:s}' and UserName '{1:s}'".format(GetIDString(), GetUserName().encode('hex'))
else:
DB = {}
return DB
Expand Down
Loading

0 comments on commit e729ae8

Please sign in to comment.