From 2df89db8f2908564392dbb0ff2066e615e8346c3 Mon Sep 17 00:00:00 2001 From: Paul Durrant Date: Thu, 8 Jan 2009 18:26:01 +0000 Subject: [PATCH] mobidedrm 0.06 and Applescript --- Kindle_Mobi_Tools/lib/mobidedrm.py | 14 +++--- .../Mobipocket Unlocker ReadMe.txt | 47 +----------------- .../Contents/Resources/MobiDeDRM.py | 21 ++++---- .../Contents/Resources/Scripts/main.scpt | Bin 15980 -> 15480 bytes .../Contents/Resources/Scripts/main.scpt.txt | 5 +- 5 files changed, 25 insertions(+), 62 deletions(-) diff --git a/Kindle_Mobi_Tools/lib/mobidedrm.py b/Kindle_Mobi_Tools/lib/mobidedrm.py index 5963b91..ffb67e3 100644 --- a/Kindle_Mobi_Tools/lib/mobidedrm.py +++ b/Kindle_Mobi_Tools/lib/mobidedrm.py @@ -7,6 +7,7 @@ # 0.03 - Wasn't checking MOBI header length # 0.04 - Wasn't sanity checking size of data record # 0.05 - It seems that the extra data flags take two bytes not four +# 0.06 - And that low bit does mean something after all :-) import sys,struct,binascii @@ -73,14 +74,15 @@ def getSizeOfTrailingDataEntries(ptr, size, flags): if (v & 0x80) != 0 or (bitpos >= 28) or (size == 0): return result num = 0 - flags >>= 1 - while flags: - if flags & 1: + testflags = flags >> 1 + while testflags: + if testflags & 1: num += getSizeOfTrailingDataEntry(ptr, size - num) - flags >>= 1 + testflags >>= 1 + if flags & 1: + num += (ord(ptr[size - num - 1]) & 0x3) + 1 return num - class DrmStripper: def loadSection(self, section): if (section + 1 == self.num_sections): @@ -171,7 +173,7 @@ class DrmStripper: def getResult(self): return self.data_file -print "MobiDeDrm v0.05. Copyright (c) 2008 The Dark Reverser" +print "MobiDeDrm v0.06. Copyright (c) 2008 The Dark Reverser" if len(sys.argv)<4: print "Removes protection from Mobipocket books" print "Usage:" diff --git a/Macintosh_Applications/Mobipocket Unlocker ReadMe.txt b/Macintosh_Applications/Mobipocket Unlocker ReadMe.txt index f672585..832d986 100644 --- a/Macintosh_Applications/Mobipocket Unlocker ReadMe.txt +++ b/Macintosh_Applications/Mobipocket Unlocker ReadMe.txt @@ -1,4 +1,4 @@ -Mobipocket Unlocker AppleScript Version 3 +Mobipocket Unlocker How to get Drag&Drop decryption of DRM-encumbered Mobipocket eBook files. @@ -6,50 +6,7 @@ You'll need the MobiDeDRM.py python script, as well as an installed version 2.4 Control-click the script and select "Show Package Contents" from the contextual menu. Copy the python script, which must be called "MobiDeDRM.py" into the Resources folder inside the Contents folder. (NB not into the Scripts folder - that's where the Applescript part is stored.) -Close the package, and you now have a drag&drop Mobipocket decrypter. +Close the package, and you now have a drag&drop Mobipocket unlocker. You can use the AppleScript ScriptEditor application to put your Mobipocket code into the script to save you having to enter it in the dialog all the time. -If you run the script directly, you'll be asked to select a folder of Mobipocket files, and then your PID. The script will attempt to unlock all Mobipocket files in the folder selected, including files in subfolders. - -If you drag and drop files and/or folders onto the script, you will be asked for your PID and then the script will attampt to unlock all the Mobipocket files dragged directly, and all Mobipocket files in the dragged folders (& subfolders). - -If the Python script returns an error, the AppleScript will report it, otherwise it works without any visible feedback. - -The MobiDeDRM.py scripts out there don't work perfectly. If you get the 0.02 version of the script, you can fix up a few problems by apply these changes: - -After line 63: -[tab][tab]bitpos, result = 0,0 - -add in the following two lines: -[tab][tab]if size <= 0: -[tab][tab][tab]return result - -After line 135: -[tab][tab]records, = struct.unpack('>H', sect[0x8:0x8+2]) - -add in the following three lines -[tab][tab]mobi_length, = struct.unpack('>L',sect[0x14:0x18]) -[tab][tab]extra_data_flags = 0 -[tab][tab]if mobi_length >= 0xE4: - -(note that tricky comma after the first instance of mobi_length) - -Add a tab to line 136: -[tab][tab]extra_data_flags, = struct.unpack('>L', sect[0xF0:0xF4]) - -to make it -[tab][tab][tab]extra_data_flags, = struct.unpack('>L', sect[0xF0:0xF4]) - -and change line 165: -print "MobiDeDrm v0.02. Copyright (c) 2008 The Dark Reverser" - -to -print "MobiDeDrm v0.04. Copyright (c) 2008 The Dark Reverser" - -just so that you don't get confused at the command line. - - -Oh -- [tab] just means a single tab character - not the five literal characters [tab]. - - diff --git a/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/MobiDeDRM.py b/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/MobiDeDRM.py index 3f46e77..ffb67e3 100644 --- a/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/MobiDeDRM.py +++ b/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/MobiDeDRM.py @@ -4,8 +4,10 @@ # Changelog # 0.01 - Initial version # 0.02 - Huffdic compressed books were not properly decrypted -# 0.03 - fix 0.02 to work with all Mobipocket eBooks -# 0.04 - Wasn't checking MOBI header length +# 0.03 - Wasn't checking MOBI header length +# 0.04 - Wasn't sanity checking size of data record +# 0.05 - It seems that the extra data flags take two bytes not four +# 0.06 - And that low bit does mean something after all :-) import sys,struct,binascii @@ -72,14 +74,15 @@ def getSizeOfTrailingDataEntries(ptr, size, flags): if (v & 0x80) != 0 or (bitpos >= 28) or (size == 0): return result num = 0 - flags >>= 1 - while flags: - if flags & 1: + testflags = flags >> 1 + while testflags: + if testflags & 1: num += getSizeOfTrailingDataEntry(ptr, size - num) - flags >>= 1 + testflags >>= 1 + if flags & 1: + num += (ord(ptr[size - num - 1]) & 0x3) + 1 return num - class DrmStripper: def loadSection(self, section): if (section + 1 == self.num_sections): @@ -140,7 +143,7 @@ class DrmStripper: mobi_length, = struct.unpack('>L',sect[0x14:0x18]) extra_data_flags = 0 if mobi_length >= 0xE4: - extra_data_flags, = struct.unpack('>L', sect[0xF0:0xF4]) + extra_data_flags, = struct.unpack('>H', sect[0xF2:0xF4]) crypto_type, = struct.unpack('>H', sect[0xC:0xC+2]) @@ -170,7 +173,7 @@ class DrmStripper: def getResult(self): return self.data_file -print "MobiDeDrm v0.04. Copyright (c) 2008 The Dark Reverser" +print "MobiDeDrm v0.06. Copyright (c) 2008 The Dark Reverser" if len(sys.argv)<4: print "Removes protection from Mobipocket books" print "Usage:" diff --git a/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/Scripts/main.scpt b/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/Scripts/main.scpt index 4a448e3c25ffbf986ac451e9217997a7cc47e225..443c1ecfed10ce66e526b48d77c5bdb087f71d5d 100644 GIT binary patch delta 1840 zcmaJ>Nl;W*6usv+Ht;{Mp;a6h1Vj;dG zP=|VfIzp-ZUPdc;kOB>LFppckx8f$4C&oy}N ze`yE=?Y!$~J5OP-mWZv`CS-UVVFOiivBAYA%JVWbY?H@rJX@g6KCYyV zTx4*O*_)9covrGdr;JCDt|3W_Xp@{tNJB_Qh7l16lU7NP+YM+(hd?`NA?a2{_1KP1 zf$jECs>qKW*eS5X9*URzT&Q!QWEyPglsG#{lO2?CUY>cw%*lkNK zAj|4Tl=FGIKsRZtBv^oUq6fVKJ+{yS6ht5P2=v+c0@TQP2Ir}K%LVq>`5LJOdtKN| z_ze5p*hfypgTp+{;2d(5klr3_ZuK>(rpc+{uv|xQRN#oMrf%xRF&q~-X6Nmu zC}$g-{boNGDOC#`w>dqPW|$DfHMRJ?BhP# z!&42Os^rv|p_DXDnS6B-rmKH5hzzcHlYpJS+Kw-#IXuPSDe>aMtu6lewF|4_s^mJ! zlLb!NH+O)>coIyU(s`0uU6CmpY1%~$&?yYMFsK@N+KtmxKr7{FgK~wbLB3hF^6mOi zemBeZ`lu;>R!{SsI7JRl#~BRioGx2X6A6X|&Jfl}Z4A;d&T2R-X$-Rz+pwK%kcKeg z!U#oWwsUTrqXep?wHi+(a$-mVPQZB{uk!>6SX%s*Fo{j>>hBg}}wQ=a#r@3LC70Qf+rQs4Ka1tl7lgAmH^p>;?PBdRsOw`zEewmf&(0QDBFF$j< z3uBa+#tD?f4%ToD*UjxEImtI1OyqFkhB;c&g=?{_(rn;*tYX14q+ON))(aZ7eztzX zP24iG%kq+MJFFj7z-@C?Sr2ZSkIQ~FZjqoz)-&sSd}@AEUMTIW@|WpXRQOZ+#d=~r z#vRfJO&eNFffi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