]> xmof Git - DeDRM.git/commitdiff
mobidedrm 0.06 and Applescript
authorPaul Durrant <paul@durrant.co.uk>
Thu, 8 Jan 2009 18:26:01 +0000 (18:26 +0000)
committerApprentice Alf <apprenticealf@gmail.com>
Thu, 26 Feb 2015 07:27:15 +0000 (07:27 +0000)
Kindle_Mobi_Tools/lib/mobidedrm.py
Macintosh_Applications/Mobipocket Unlocker ReadMe.txt
Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/MobiDeDRM.py
Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/Scripts/main.scpt
Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/Scripts/main.scpt.txt

index 5963b914a5bd7052727a57734b19c6f95c1522d2..ffb67e351f5151cc77a5fa4dd78e1828b48ef9eb 100644 (file)
@@ -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:"
index f672585cd2ed94181d058cdc278811d28e9376fb..832d986c4c4e04e3f8c10f009ac33922c644f99c 100644 (file)
@@ -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].
-
-
index 3f46e779acb7e0b2d599ff8efea80746e4d7fc52..ffb67e351f5151cc77a5fa4dd78e1828b48ef9eb 100644 (file)
@@ -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:"
index 4a448e3c25ffbf986ac451e9217997a7cc47e225..443c1ecfed10ce66e526b48d77c5bdb087f71d5d 100644 (file)
Binary files a/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/Scripts/main.scpt and b/Macintosh_Applications/Mobipocket Unlocker.app/Contents/Resources/Scripts/main.scpt differ
index b67f2f3b9c0472876023ec4d56927f9a7685c118..aad343d518c8a620f274f22d012d395eb64f26fa 100644 (file)
@@ -36,14 +36,14 @@ end unlockfolder
 on run
        set MobiDeDRMPath to POSIX path of file ((path to me as text) & "Contents:Resources:MobiDeDRM.py")
        set encryptedFolder to choose folder with prompt "Please choose the folder of encrypted Mobipocket files."
-       set encryptionKey to (display dialog "Enter Mobipocket key for encrypted Mobipocket files." default answer "X12QIL1M3D" buttons {"Cancel", "OK"} default button 2)
+       set encryptionKey to (display dialog "Enter Mobipocket key for encrypted Mobipocket files." default answer "Your PID Here" buttons {"Cancel", "OK"} default button 2)
        set encryptionKey to text returned of encryptionKey
        unlockfolder(encryptedFolder, MobiDeDRMPath, encryptionKey)
 end run
 
 on open some_items
        set MobiDeDRMPath to POSIX path of file ((path to me as text) & "Contents:Resources:MobiDeDRM.py")
-       set encryptionKey to (display dialog "Enter Mobipocket key for encrypted Mobipocket files." default answer "X12QIL1M3D" buttons {"Cancel", "OK"} default button 2)
+       set encryptionKey to (display dialog "Enter Mobipocket key for encrypted Mobipocket files." default answer "Your PID Here" buttons {"Cancel", "OK"} default button 2)
        set encryptionKey to text returned of encryptionKey
        repeat with this_item in some_items
                if (folder of (info for this_item) is true) then
@@ -55,5 +55,6 @@ on open some_items
                        end if
                end if
        end repeat
+       display dialog "Finished Unlocking." buttons {"OK"} default button 1
 end open