tools v2.3
First appearance of DeDRM AppleScript application
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
__version__ = '1.1'
|
||||
__version__ = '1.2'
|
||||
|
||||
class Unbuffered:
|
||||
def __init__(self, stream):
|
||||
@@ -284,7 +284,7 @@ def getK4Pids(exth, title, kInfoFile=None):
|
||||
global kindleDatabase
|
||||
try:
|
||||
kindleDatabase = parseKindleInfo(kInfoFile)
|
||||
except Exception as message:
|
||||
except Exception, message:
|
||||
print(message)
|
||||
|
||||
if kindleDatabase != None :
|
||||
@@ -313,6 +313,8 @@ def getK4Pids(exth, title, kInfoFile=None):
|
||||
exth_records = {}
|
||||
nitems, = unpack('>I', exth[8:12])
|
||||
pos = 12
|
||||
|
||||
exth_records[209] = None
|
||||
# Parse the exth records, storing data indexed by type
|
||||
for i in xrange(nitems):
|
||||
type, size = unpack('>II', exth[pos: pos + 8])
|
||||
@@ -397,6 +399,7 @@ def main(argv=sys.argv):
|
||||
kindleDatabase = None
|
||||
infile = args[0]
|
||||
outfile = args[1]
|
||||
DecodeErrorString = ""
|
||||
try:
|
||||
# first try with K4PC/K4M
|
||||
ex = MobiPeek(infile)
|
||||
@@ -405,11 +408,15 @@ def main(argv=sys.argv):
|
||||
return 2
|
||||
title = ex.getBookTitle()
|
||||
exth = ex.getexthData()
|
||||
if exth=='':
|
||||
raise DrmException("Not a Kindle Mobipocket file")
|
||||
pid = getK4Pids(exth, title)
|
||||
unlocked_file = mobidedrm.getUnencryptedBook(infile, pid)
|
||||
except DrmException:
|
||||
except DrmException, e:
|
||||
DecodeErrorString += "Error trying default K4 info: " + str(e) + "\n"
|
||||
pass
|
||||
except mobidedrm.DrmException:
|
||||
except mobidedrm.DrmException, e:
|
||||
DecodeErrorString += "Error trying default K4 info: " + str(e) + "\n"
|
||||
pass
|
||||
else:
|
||||
file(outfile, 'wb').write(unlocked_file)
|
||||
@@ -422,11 +429,15 @@ def main(argv=sys.argv):
|
||||
try:
|
||||
title = ex.getBookTitle()
|
||||
exth = ex.getexthData()
|
||||
if exth=='':
|
||||
raise DrmException("Not a Kindle Mobipocket file")
|
||||
pid = getK4Pids(exth, title, infoFile)
|
||||
unlocked_file = mobidedrm.getUnencryptedBook(infile, pid)
|
||||
except DrmException:
|
||||
except DrmException, e:
|
||||
DecodeErrorString += "Error trying " + infoFile + " K4 info: " + str(e) + "\n"
|
||||
pass
|
||||
except mobidedrm.DrmException:
|
||||
except mobidedrm.DrmException, e:
|
||||
DecodeErrorString += "Error trying " + infoFile + " K4 info: " + str(e) + "\n"
|
||||
pass
|
||||
else:
|
||||
file(outfile, 'wb').write(unlocked_file)
|
||||
@@ -445,6 +456,7 @@ def main(argv=sys.argv):
|
||||
return 0
|
||||
|
||||
# we could not unencrypt book
|
||||
print DecodeErrorString
|
||||
print "Error: Could Not Unencrypt Book"
|
||||
return 1
|
||||
|
||||
@@ -463,7 +475,7 @@ if not __name__ == "__main__" and inCalibre:
|
||||
Provided by the work of many including DiapDealer, SomeUpdates, IHeartCabbages, CMBDTC, Skindle, DarkReverser, ApprenticeAlf, etc.'
|
||||
supported_platforms = ['osx', 'windows', 'linux'] # Platforms this plugin will run on
|
||||
author = 'DiapDealer, SomeUpdates' # The author of this plugin
|
||||
version = (0, 1, 1) # The version number of this plugin
|
||||
version = (0, 1, 3) # The version number of this plugin
|
||||
file_types = set(['prc','mobi','azw']) # The file types that this plugin will be applied to
|
||||
on_import = True # Run this plugin during the import
|
||||
priority = 200 # run this plugin before mobidedrm, k4pcdedrm, k4dedrm
|
||||
@@ -509,6 +521,8 @@ if not __name__ == "__main__" and inCalibre:
|
||||
return path_to_ebook
|
||||
title = ex.getBookTitle()
|
||||
exth = ex.getexthData()
|
||||
if exth=='':
|
||||
raise DrmException("Not a Kindle Mobipocket file")
|
||||
pid = getK4Pids(exth, title)
|
||||
unlocked_file = mobidedrm.getUnencryptedBook(path_to_ebook,pid)
|
||||
except DrmException:
|
||||
@@ -528,6 +542,8 @@ if not __name__ == "__main__" and inCalibre:
|
||||
try:
|
||||
title = ex.getBookTitle()
|
||||
exth = ex.getexthData()
|
||||
if exth=='':
|
||||
raise DrmException("Not a Kindle Mobipocket file")
|
||||
pid = getK4Pids(exth, title, infoFile)
|
||||
unlocked_file = mobidedrm.getUnencryptedBook(path_to_ebook,pid)
|
||||
except DrmException:
|
||||
|
||||
@@ -237,24 +237,36 @@ LibCrypto = _load_crypto()
|
||||
#
|
||||
|
||||
# uses a sub process to get the Hard Drive Serial Number using ioreg
|
||||
# returns with the first found serial number in that class
|
||||
# returns with the serial number of drive whose BSD Name is "disk0"
|
||||
def GetVolumeSerialNumber():
|
||||
cmdline = '/usr/sbin/ioreg -r -c AppleAHCIDiskDriver'
|
||||
sernum = os.getenv('MYSERIALNUMBER')
|
||||
if sernum != None:
|
||||
return sernum
|
||||
cmdline = '/usr/sbin/ioreg -l -S -w 0 -r -c AppleAHCIDiskDriver'
|
||||
cmdline = cmdline.encode(sys.getfilesystemencoding())
|
||||
p = Process(cmdline, shell=True, bufsize=1, stdin=None, stdout=PIPE, stderr=PIPE, close_fds=False)
|
||||
poll = p.wait('wait')
|
||||
results = p.read()
|
||||
reslst = results.split('\n')
|
||||
sernum = '9999999999'
|
||||
cnt = len(reslst)
|
||||
bsdname = None
|
||||
sernum = None
|
||||
foundIt = False
|
||||
for j in xrange(cnt):
|
||||
resline = reslst[j]
|
||||
pp = resline.find('"Serial Number" = "')
|
||||
if pp >= 0:
|
||||
sernum = resline[pp+19:]
|
||||
sernum = sernum[:-1]
|
||||
sernum = sernum.lstrip()
|
||||
break
|
||||
sernum = resline[pp+19:-1]
|
||||
sernum = sernum.strip()
|
||||
bb = resline.find('"BSD Name" = "')
|
||||
if bb >= 0:
|
||||
bsdname = resline[bb+14:-1]
|
||||
bsdname = bsdname.strip()
|
||||
if (bsdname == 'disk0') and (sernum != None):
|
||||
foundIt = True
|
||||
break
|
||||
if not foundIt:
|
||||
sernum = '9999999999'
|
||||
return sernum
|
||||
|
||||
# uses unix env to get username instead of using sysctlbyname
|
||||
@@ -319,4 +331,4 @@ def openKindleInfo(kInfoFile=None):
|
||||
raise K4MDrmException('Error: .kindle-info file can not be found')
|
||||
return open(kinfopath,'r')
|
||||
else:
|
||||
return open(kInfoFile, 'r')
|
||||
return open(kInfoFile, 'r')
|
||||
|
||||
@@ -3,14 +3,6 @@
|
||||
# This is a python script. You need a Python interpreter to run it.
|
||||
# For example, ActiveState Python, which exists for windows.
|
||||
#
|
||||
# It can run standalone to convert files, or it can be installed as a
|
||||
# plugin for Calibre (http://calibre-ebook.com/about) so that
|
||||
# importing files with DRM 'Just Works'.
|
||||
#
|
||||
# To create a Calibre plugin, rename this file so that the filename
|
||||
# ends in '_plugin.py', put it into a ZIP file and import that Calibre
|
||||
# using its plugin configuration GUI.
|
||||
#
|
||||
# Changelog
|
||||
# 0.01 - Initial version
|
||||
# 0.02 - Huffdic compressed books were not properly decrypted
|
||||
@@ -46,8 +38,9 @@
|
||||
# 0.18 - It seems that multibyte entries aren't encrypted in a v7 file...
|
||||
# Removed the disabled Calibre plug-in code
|
||||
# Permit use of 8-digit PIDs
|
||||
# 0.19 - It seems that multibyte entries aren't encrypted in a v6 file either.
|
||||
|
||||
__version__ = '0.18'
|
||||
__version__ = '0.19'
|
||||
|
||||
import sys
|
||||
import struct
|
||||
@@ -215,8 +208,8 @@ class DrmStripper:
|
||||
if (mobi_length >= 0xE4) and (mobi_version >= 5):
|
||||
extra_data_flags, = struct.unpack('>H', sect[0xF2:0xF4])
|
||||
print "Extra Data Flags = %d" %extra_data_flags
|
||||
if mobi_version < 7:
|
||||
# multibyte utf8 data is included in the encryption for mobi_version 5 (& 6?)
|
||||
if mobi_version <= 5:
|
||||
# multibyte utf8 data is included in the encryption for mobi_version 5 and below
|
||||
# so clear that byte so that we leave it to be decrypted.
|
||||
extra_data_flags &= 0xFFFE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user