Skip to content

Commit

Permalink
tools v5.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
apprenticealf committed Mar 7, 2015
1 parent c23b903 commit 490ee4e
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 129 deletions.
4 changes: 2 additions & 2 deletions Calibre_Plugins/K4MobiDeDRM_ReadMe.txt
@@ -1,4 +1,4 @@
Kindle and Mobipocket Plugin - K4MobiDeDRM_v04.18_plugin.zip
Kindle and Mobipocket Plugin - K4MobiDeDRM_v04.19_plugin.zip
============================================================

Credit given to The Dark Reverser for the original standalone script. Credit also to the many people who have updated and expanded that script since then.
Expand All @@ -13,7 +13,7 @@ This plugin is meant to remove the DRM from .prc, .mobi, .azw, .azw1, .azw3, .az
Installation
------------

Do **NOT** select "Get plugins to enhance calibre" as this is reserved for "official" calibre plugins, instead select "Change calibre behavior" to go to Calibre's Preferences page. Under "Advanced" click on the Plugins button. Use the "Load plugin from file" button to select the plugin's zip file (K4MobiDeDRM_v04.18_plugin.zip) and click the 'Add' button. Click 'Yes' in the the "Are you sure?" dialog. Click OK in the "Success" dialog.
Do **NOT** select "Get plugins to enhance calibre" as this is reserved for "official" calibre plugins, instead select "Change calibre behavior" to go to Calibre's Preferences page. Under "Advanced" click on the Plugins button. Use the "Load plugin from file" button to select the plugin's zip file (K4MobiDeDRM_v04.19_plugin.zip) and click the 'Add' button. Click 'Yes' in the the "Are you sure?" dialog. Click OK in the "Success" dialog.

Make sure that you delete any old versions of the plugin. They might interfere with the operation of the new one.

Expand Down
3 changes: 2 additions & 1 deletion Calibre_Plugins/K4MobiDeDRM_plugin/__init__.py
Expand Up @@ -27,13 +27,14 @@
# 0.4.16 - Yet another Topaz fix
# 0.4.17 - Manage to include the actual fix.
# 0.4.18 - More Topaz fixes
# 0.4.19 - MobiDeDRM PalmDoc fix

"""
Decrypt Amazon Kindle and Mobipocket encrypted ebooks.
"""

PLUGIN_NAME = u"Kindle and Mobipocket DeDRM"
PLUGIN_VERSION_TUPLE = (0, 4, 18)
PLUGIN_VERSION_TUPLE = (0, 4, 19)
PLUGIN_VERSION = '.'.join([str(x) for x in PLUGIN_VERSION_TUPLE])

import sys, os, re
Expand Down
8 changes: 6 additions & 2 deletions Calibre_Plugins/K4MobiDeDRM_plugin/alfcrypto.py
Expand Up @@ -34,10 +34,14 @@ def _load_libalfcrypto():
else:
name_of_lib = 'libalfcrypto64.so'

# hard code to local location for libalfcrypto
libalfcrypto = os.path.join(sys.path[0],name_of_lib)

if not os.path.isfile(libalfcrypto):
raise Exception('libalfcrypto not found')
libalfcrypto = os.path.join(sys.path[0], 'lib', name_of_lib)
if not os.path.isfile(libalfcrypto):
libalfcrypto = os.path.join('.',name_of_lib)
if not os.path.isfile(libalfcrypto):
raise Exception('libalfcrypto not found at %s' % libalfcrypto)

libalfcrypto = CDLL(libalfcrypto)

Expand Down
1 change: 1 addition & 0 deletions Calibre_Plugins/K4MobiDeDRM_plugin/k4mobidedrm.py
Expand Up @@ -248,6 +248,7 @@ def decryptBook(infile, outdir, kInfoFiles, serials, pids):

# remove internal temporary directory of Topaz pieces
book.cleanup()
return 0


def usage(progname):
Expand Down
16 changes: 8 additions & 8 deletions Calibre_Plugins/K4MobiDeDRM_plugin/kindlepid.py
Expand Up @@ -8,6 +8,7 @@
# 0.2 Added support for generating PID for iPhone (thanks to mbp)
# 0.3 changed to autoflush stdout, fixed return code usage
# 0.3 updated for unicode
# 0.4 Added support for serial numbers starting with '9', fixed unicode bugs.

import sys
import binascii
Expand Down Expand Up @@ -63,7 +64,7 @@ def unicode_argv():
xrange(start, argc.value)]
# if we don't have any arguments at all, just pass back script name
# this should never happen
return [u"mobidedrm.py"]
return [u"kindlepid.py"]
else:
argvencoding = sys.stdin.encoding
if argvencoding == None:
Expand Down Expand Up @@ -92,7 +93,6 @@ def checksumPid(s):

return res


def pidFromSerial(s, l):
crc = crc32(s)

Expand All @@ -113,27 +113,27 @@ def pidFromSerial(s, l):

def cli_main(argv=unicode_argv()):
print u"Mobipocket PID calculator for Amazon Kindle. Copyright © 2007, 2009 Igor Skochinsky"
if len(sys.argv)==2:
serial = sys.argv[1]
if len(argv)==2:
serial = argv[1]
else:
print u"Usage: kindlepid.py <Kindle Serial Number>/<iPhone/iPod Touch UDID>"
return 1
if len(serial)==16:
if serial.startswith("B"):
if serial.startswith("B") or serial.startswith("9"):
print u"Kindle serial number detected"
else:
print u"Warning: unrecognized serial number. Please recheck input."
return 1
pid = pidFromSerial(serial.encode("utf-8"),7)+'*'
print u"Mobipocket PID for Kindle serial#{0} is {1} ".format(serial,checksumPid(pid))
print u"Mobipocket PID for Kindle serial#{0} is {1}".format(serial,checksumPid(pid))
return 0
elif len(serial)==40:
print u"iPhone serial number (UDID) detected"
pid = pidFromSerial(serial.encode("utf-8"),8)
print u"Mobipocket PID for iPhone serial#{0} is {1} ".format(serial,checksumPid(pid))
print u"Mobipocket PID for iPhone serial#{0} is {1}".format(serial,checksumPid(pid))
return 0
print u"Warning: unrecognized serial number. Please recheck input."
return 1
return 1


if __name__ == "__main__":
Expand Down
Binary file modified Calibre_Plugins/k4mobidedrm_plugin.zip
Binary file not shown.
20 changes: 10 additions & 10 deletions Calibre_Plugins/k4mobidedrm_plugin/k4pcutils.py
Expand Up @@ -208,7 +208,7 @@ def CryptUnprotectData(indata, entropy, flags):
def getKindleInfoFiles():
kInfoFiles = []
# some 64 bit machines do not have the proper registry key for some reason
# or the pythonn interface to the 32 vs 64 bit registry is broken
# or the python interface to the 32 vs 64 bit registry is broken
path = ""
if 'LOCALAPPDATA' in os.environ.keys():
path = os.environ['LOCALAPPDATA']
Expand All @@ -217,17 +217,17 @@ def getKindleInfoFiles():
try:
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\")
path = winreg.QueryValueEx(regkey, 'Local AppData')[0]
except WindowsError:
pass
if not os.path.isdir(path):
path = ""
try:
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\")
path = winreg.QueryValueEx(regkey, 'Local AppData')[0]
except WindowsError:
pass
if not os.path.isdir(path):
path = ""
try:
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\")
path = winreg.QueryValueEx(regkey, 'Local AppData')[0]
if not os.path.isdir(path):
path = ""
except RegError:
pass
except RegError:
pass

found = False
if path == "":
Expand Down
25 changes: 14 additions & 11 deletions Calibre_Plugins/k4mobidedrm_plugin/mobidedrm.py
Expand Up @@ -66,9 +66,10 @@
# 0.36 - fixed problem with TEXtREAd and getBookTitle interface
# 0.37 - Fixed double announcement for stand-alone operation
# 0.38 - Unicode used wherever possible, cope with absent alfcrypto
# 0.39 - Fixed problem with TEXtREAd and getBookType interface


__version__ = u"0.38"
__version__ = u"0.39"

import sys
import os
Expand Down Expand Up @@ -268,19 +269,22 @@ def __init__(self, infile):
self.records, = struct.unpack('>H', self.sect[0x8:0x8+2])
self.compression, = struct.unpack('>H', self.sect[0x0:0x0+2])

# det default values before PalmDoc test
self.print_replica = False
self.extra_data_flags = 0
self.meta_array = {}
self.mobi_length = 0
self.mobi_codepage = 1252
self.mobi_version = -1

if self.magic == 'TEXtREAd':
print u"PalmDoc format book detected."
self.extra_data_flags = 0
self.mobi_length = 0
self.mobi_codepage = 1252
self.mobi_version = -1
self.meta_array = {}
return

self.mobi_length, = struct.unpack('>L',self.sect[0x14:0x18])
self.mobi_codepage, = struct.unpack('>L',self.sect[0x1c:0x20])
self.mobi_version, = struct.unpack('>L',self.sect[0x68:0x6C])
print u"MOBI header version {0:d}, header length {1:d}".format(self.mobi_version, self.mobi_length)
self.extra_data_flags = 0
if (self.mobi_length >= 0xE4) and (self.mobi_version >= 5):
self.extra_data_flags, = struct.unpack('>H', self.sect[0xF2:0xF4])
print u"Extra Data Flags: {0:d}".format(self.extra_data_flags)
Expand All @@ -290,7 +294,6 @@ def __init__(self, infile):
self.extra_data_flags &= 0xFFFE

# if exth region exists parse it for metadata array
self.meta_array = {}
try:
exth_flag, = struct.unpack('>L', self.sect[0x80:0x84])
exth = ''
Expand All @@ -313,9 +316,7 @@ def __init__(self, infile):
# print type, size, content, content.encode('hex')
pos += size
except:
self.meta_array = {}
pass
self.print_replica = False

def getBookTitle(self):
codec_map = {
Expand Down Expand Up @@ -406,7 +407,9 @@ def getBookType(self):
return u"Print Replica"
if self.mobi_version >= 8:
return u"Kindle Format 8"
return u"Mobipocket"
if self.mobi_version >= 0:
return u"Mobipocket {0:d}".format(self.mobi_version)
return u"PalmDoc"

def getBookExtension(self):
if self.print_replica:
Expand Down
2 changes: 1 addition & 1 deletion DeDRM_Macintosh_Application/DeDRM ReadMe.rtf
Expand Up @@ -41,7 +41,7 @@ Mac OS X 10.5 and above: You do
\i not
\i0 need to install Python.\
\
Drag the DeDRM application from from tools_v5.6\\DeDRM_Applications\\Macintosh (the location of this ReadMe) to your Applications folder, or anywhere else you find convenient.\
Drag the DeDRM application from from tools_v5.6.1\\DeDRM_Applications\\Macintosh (the location of this ReadMe) to your Applications folder, or anywhere else you find convenient.\
\
\

Expand Down
6 changes: 3 additions & 3 deletions DeDRM_Macintosh_Application/DeDRM.app/Contents/Info.plist
Expand Up @@ -24,17 +24,17 @@
<key>CFBundleExecutable</key>
<string>droplet</string>
<key>CFBundleGetInfoString</key>
<string>DeDRM 5.6. AppleScript written 2010–2013 by Apprentice Alf and others.</string>
<string>DeDRM 5.6.1. AppleScript written 2010–2013 by Apprentice Alf and others.</string>
<key>CFBundleIconFile</key>
<string>DeDRM</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>DeDRM 5.6</string>
<string>DeDRM 5.6.1</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>5.6</string>
<string>5.6.1</string>
<key>CFBundleSignature</key>
<string>dplt</string>
<key>LSRequiresCarbon</key>
Expand Down
Binary file not shown.
Expand Up @@ -208,7 +208,7 @@ def CryptUnprotectData(indata, entropy, flags):
def getKindleInfoFiles():
kInfoFiles = []
# some 64 bit machines do not have the proper registry key for some reason
# or the pythonn interface to the 32 vs 64 bit registry is broken
# or the python interface to the 32 vs 64 bit registry is broken
path = ""
if 'LOCALAPPDATA' in os.environ.keys():
path = os.environ['LOCALAPPDATA']
Expand All @@ -217,17 +217,17 @@ def getKindleInfoFiles():
try:
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\")
path = winreg.QueryValueEx(regkey, 'Local AppData')[0]
except WindowsError:
pass
if not os.path.isdir(path):
path = ""
try:
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\")
path = winreg.QueryValueEx(regkey, 'Local AppData')[0]
except WindowsError:
pass
if not os.path.isdir(path):
path = ""
try:
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\")
path = winreg.QueryValueEx(regkey, 'Local AppData')[0]
if not os.path.isdir(path):
path = ""
except RegError:
pass
except RegError:
pass

found = False
if path == "":
Expand Down
Expand Up @@ -8,6 +8,7 @@
# 0.2 Added support for generating PID for iPhone (thanks to mbp)
# 0.3 changed to autoflush stdout, fixed return code usage
# 0.3 updated for unicode
# 0.4 Added support for serial numbers starting with '9', fixed unicode bugs.

import sys
import binascii
Expand Down Expand Up @@ -63,7 +64,7 @@ def unicode_argv():
xrange(start, argc.value)]
# if we don't have any arguments at all, just pass back script name
# this should never happen
return [u"mobidedrm.py"]
return [u"kindlepid.py"]
else:
argvencoding = sys.stdin.encoding
if argvencoding == None:
Expand Down Expand Up @@ -92,7 +93,6 @@ def checksumPid(s):

return res


def pidFromSerial(s, l):
crc = crc32(s)

Expand All @@ -113,27 +113,27 @@ def pidFromSerial(s, l):

def cli_main(argv=unicode_argv()):
print u"Mobipocket PID calculator for Amazon Kindle. Copyright © 2007, 2009 Igor Skochinsky"
if len(sys.argv)==2:
serial = sys.argv[1]
if len(argv)==2:
serial = argv[1]
else:
print u"Usage: kindlepid.py <Kindle Serial Number>/<iPhone/iPod Touch UDID>"
return 1
if len(serial)==16:
if serial.startswith("B"):
if serial.startswith("B") or serial.startswith("9"):
print u"Kindle serial number detected"
else:
print u"Warning: unrecognized serial number. Please recheck input."
return 1
pid = pidFromSerial(serial.encode("utf-8"),7)+'*'
print u"Mobipocket PID for Kindle serial#{0} is {1} ".format(serial,checksumPid(pid))
print u"Mobipocket PID for Kindle serial#{0} is {1}".format(serial,checksumPid(pid))
return 0
elif len(serial)==40:
print u"iPhone serial number (UDID) detected"
pid = pidFromSerial(serial.encode("utf-8"),8)
print u"Mobipocket PID for iPhone serial#{0} is {1} ".format(serial,checksumPid(pid))
print u"Mobipocket PID for iPhone serial#{0} is {1}".format(serial,checksumPid(pid))
return 0
print u"Warning: unrecognized serial number. Please recheck input."
return 1
return 1


if __name__ == "__main__":
Expand Down

0 comments on commit 490ee4e

Please sign in to comment.