From e6edf3e3701951343d142e0ab761aed48bcdeaac Mon Sep 17 00:00:00 2001 From: Paul Durrant Date: Sun, 22 Jun 2008 13:35:18 +0100 Subject: [PATCH] First patch to mobidedrm --- Kindle_Mobi_Tools/lib/mobidedrm.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Kindle_Mobi_Tools/lib/mobidedrm.py b/Kindle_Mobi_Tools/lib/mobidedrm.py index e424d02..8660bce 100644 --- a/Kindle_Mobi_Tools/lib/mobidedrm.py +++ b/Kindle_Mobi_Tools/lib/mobidedrm.py @@ -4,6 +4,7 @@ # 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 import sys,struct,binascii @@ -60,6 +61,8 @@ def checksumPid(s): def getSizeOfTrailingDataEntries(ptr, size, flags): def getSizeOfTrailingDataEntry(ptr, size): bitpos, result = 0, 0 + if size <= 0: + return result while True: v = ord(ptr[size-1]) result |= (v & 0x7F) << bitpos @@ -69,10 +72,10 @@ def getSizeOfTrailingDataEntries(ptr, size, flags): return result num = 0 flags >>= 1 - while flags: - if flags & 1: - num += getSizeOfTrailingDataEntry(ptr, size - num) - flags >>= 1 +# while flags: + if flags & 1: + num += getSizeOfTrailingDataEntry(ptr, size - num) + flags >>= 1 return num @@ -162,7 +165,7 @@ class DrmStripper: def getResult(self): return self.data_file -print "MobiDeDrm v0.02. Copyright (c) 2008 The Dark Reverser" +print "MobiDeDrm v0.03. Copyright (c) 2008 The Dark Reverser" if len(sys.argv)<4: print "Removes protection from Mobipocket books" print "Usage:" @@ -175,4 +178,4 @@ else: try: file(outfile, 'wb').write(DrmStripper(data_file, pid).getResult()) except DrmException, e: - print "Error: %s" % e \ No newline at end of file + print "Error: %s" % e