Using inept to strip DRM for better viewing

Anathem
Image via Wikipedia

(Update: This post wasn’t intended as a how-to but people are getting some use out of it. To fill in the gaps, here is an article on how to install the required tools like pycrypto.)

I remove DRM whenever possible because I lost a few iTunes tracks. Also, since the FoxIt eSlick won’t work with DRM immediately, I wanted to be able to test how readily I could use purchases on my eink reader. I’m not intending to pirate ebooks here. It turns out that until a new version of ADEPT comes out I don’t have anything to worry about. The process is easy, fast, and appears to be lossless.

I found out about tools to unwrap DRM from e-books when a DCMA takedown notice was used to remove two python scripts. I managed to snag copies of the suppressed python scripts (ineptpdf.pyw, ineptkey.pyw for Windows or ineptkeymac.pyw for OS X, ineptepub.pyw) from the slashdot comments more easily than my copy of Adobe Digital Editions from the Adobe site, since their web installer failed repeatedly and I had to hunt down the EXE.

So, while I install I ask on Twitter where to buy some ePub or ADEPT ebooks. Someone suggested BooksOnBoard. They have a copy of Anathem in ADEPT format for $18.07 after the 1% Google Checkout discount, about $2 less than the cost of the hardcover. I’m not happy that it’s so expensive for an electronic copy but I decide to pay anyways because I can’t find another ADEPT copy, let alone cheaper.

I download the 16 megabyte book through Adobe Digital Editions in about a minute and then execute ineptkey.pyw. It notifies me that my key has been stored in adeptkey.der. Next, I run ineptpdf.pyw. I’m greeted with a dialogue box asking me for the key file, the input file, and the output destination. It turns out that the ebook I bought got sent to My Documents/My Digital Editions/. I fill out all the required boxes and click decrypt.

There’s no progress bar, just the hourglass for about thirty seconds, and then it goes away. No success or failure message.

Just to make sure that the PDF I downloaded from BooksOnBoard was encrypted I tried to open it with FoxIt Reader. I get the error “This document is encrypted with some unsupported security handler.” Okay, now I try to open up the decrypted version. Success!

Everything looks to be in tact, including the chapter bookmarks and graphics. I opened it up side by side with the Adobe Digital Edition and started from chapter six, where I left off from the library book. The two did not look alike.

It turns out that the decrypted version looks better! Take a look at the screenshots below, particularly the middle one which compares the Adobe Digital Edition to the decrypted PDF.

Apparently the ebook I bought contains PDF features that Adobe Digital Editions does not support. FoxIt Reader does, though! I’m stunned to think that if I didn’t break the DMCA I’d be stuck with a product that wasn’t just less flexible, but that was inferior!

I wasn’t the only success, but there were a few others having issues. Mobileread has a thread on the inept decryptor.

82 Comments to “Using inept to strip DRM for better viewing”

  1. Pam G. 22 March 2009 at 6:30 pm #

    Hoping you can give me a pointer or two. Appreciate your how-to on using inept. I’m not highly conversant with python scripts, but I’ve successfully used them to strip DRM from ereader and mobipocket files.

    However, I’ve run into the proverbial wall with inept. I dl’d and saved the two scripts as directed and installed Python 26 and PyCrypto. The next step is to double-click on the ineptkey.pyw to create the adeptkey.der file. But double-clicking on ineptkey produces no results–my feeling is there’s likely some basic step that I’ve overlooked because I don’t know any better.

    I’d greatly appreciate it if you can help clear this up for me–I have a couple of different ebook readers and I feel strongly that I should be able to change formats of books that I’ve paid for so they can be read on the devices I’ve paid for!

    Many thanks for any assistance you can provide.

  2. lance 22 March 2009 at 8:50 pm #

    Hi Pam,

    Did you open the ebook successfully in Adobe Digital Editions? If so..

    Try opening up IDLE (Python GUI). From there, File->Open and open the ineptkey.pyw. Next, hit Run->Run Module.

    What error message does it bring up?

  3. Pam G. 23 March 2009 at 12:24 am #

    Thanks very much for your swift reply!
    Yes, I can open the book(s) successfully in Adobe Digital Editions. Following is the error message generated per your instructions:

    Exception in Tkinter callback
    Traceback (most recent call last):
    File “C:\Python26\lib\lib-tk\Tkinter.py”, line 1410, in __call__
    return self.func(*args)
    File “C:\Python26\lib\idlelib\IOBinding.py”, line 217, in open
    self.editwin.flist.open(filename)
    File “C:\Python26\lib\idlelib\FileList.py”, line 36, in open
    return self.EditorWindow(self, filename, key)
    File “C:\Python26\lib\idlelib\PyShell.py”, line 109, in __init__
    EditorWindow.__init__(self, *args)
    File “C:\Python26\lib\idlelib\EditorWindow.py”, line 245, in __init__
    self.set_indentation_params(self.ispythonsource(filename))
    File “C:\Python26\lib\idlelib\EditorWindow.py”, line 1054, in set_indentation_
    params
    i = self.guess_indent()
    File “C:\Python26\lib\idlelib\EditorWindow.py”, line 1411, in guess_indent
    opener, indented = IndentSearcher(self.text, self.tabwidth).run()
    File “C:\Python26\lib\idlelib\EditorWindow.py”, line 1484, in run
    _tokenize.tokenize(self.readline, self.tokeneater)
    File “C:\Python26\lib\tokenize.py”, line 169, in tokenize
    tokenize_loop(readline, tokeneater)
    File “C:\Python26\lib\tokenize.py”, line 175, in tokenize_loop
    for token_info in generate_tokens(readline):
    File “C:\Python26\lib\tokenize.py”, line 346, in generate_tokens
    (“”, lnum, pos, line))
    File “”, line 19
    10.
    ^
    IndentationError: unindent does not match any outer indentation level

  4. lance 23 March 2009 at 1:16 am #

    It looks like you copied and pasted the code and some line numbers got left in, plus some errant spacing. Python is very finicky when it comes to spacing.

    Redownload the files. Don’t copy and paste them. When you go to the pastebin link, click the download link near the top right under “Posted by Anonymous on Sat 28 Feb 15:11″. Rename f(whatever).txt to ineptkey.pyw. Then double click that.

  5. Pam G. 23 March 2009 at 3:07 am #

    It worked like a charm! Thanks so much for taking the time to help me clear this up. I’m thinking “inept” applies more to me and less to the script…

  6. lance 23 March 2009 at 3:11 am #

    My pleasure. Glad you got it to work. Don’t be too hard on yourself, it can be a bit of a pain to unwrap DRM sometimes. :)

  7. Debra 29 March 2009 at 10:09 pm #

    This is a wonderful script, but all of a sudden it has stopped working for me. About 2/3 of all the books I try fail. I get all the books from the library (Overdrive) and I can’t see any difference between the ones that decrypt and the ones that don’t. And advice would be very much appreciated. Debra

  8. lance 30 March 2009 at 9:02 am #

    Hi Debra,

    Sorry to say but you might be out of luck. I don’t think the decrypter works for all versions of ADEPT, only the most recent one. Books that you bought a while ago might not work. If they’re recent, are they EPUB or PDF? The script I posted only works for PDF, if you’ve got EPUB check out the EPUB page from the author.

    You can follow the blog of the author called I heart cabbages in case he releases new versions of the script. He also posts on the mobileread forums and there’s a long thread on inept.

  9. Benoneya 30 March 2009 at 1:28 pm #

    Oooookay, so how do I figure out which script to download from that list?

    Unfortunately I still have a Windows based OS.

    I’m not completely technically void, but jeesh!

    I reckon the windows binary?

    And does this script only work for Adobe?

    I recently scrubbed my hard drive of everything Adobe, and downloaded Foxit instead. *Groan* Now I can’t open some of my ebooks because of the DRM crapola. I paid for these books, I ought to be able to read them.

    Thanks…

  10. lance 30 March 2009 at 1:48 pm #

    Hi Benoneya,

    Oh, yeah, you’re going to need to download the Windows binary of python. Version 2.6 or above should work. I use 2.6.1.

    You’re going to need Adobe Digital Editions, the ineptkey.pyw and ineptpdf.pyw. It sounds like you’re going to have to reinstall ADE and reauthorize it so you can read the books on ADE again, and then run the inept scripts.

    ineptkey.pyw extracts the unlock key from Adobe Digital Editions. ineptpdf.pyw unlocks the PDF.

  11. imeagor 13 April 2009 at 9:18 pm #

    thanks for the wonderful work!
    but a problem is that when the pdf files were decrypted, they cannot be opened by pdf reader such as adobe acrobat,foxit, scansoft, nitro etc.

    btw, no error messges appear during decryption process.

  12. Row 20 April 2009 at 3:28 pm #

    Sounds terrific

    All seems to have installed ok, but when I click on the pyw file it say that pycryto is not installed, yet it seemed to go through the install procedure. I loaded the software into a new directory together, does location matter.

    In anticipation, thanks so much.

  13. lance_ 22 April 2009 at 6:51 am #

    Hi Row,

    Any luck? Pycrypto does need to be able to find your python install so that it can add itself to the list of libraries.

  14. ernie 30 April 2009 at 11:28 pm #

    I managed to use the scripts to get the key, and even get a success message! but every time I try to open my “decrypted” PDF Adobe throws me a 140 error! Any idea how to fix this?

    Also I’m not sure what to put in the “Output File” Field! Thanks in advance!

  15. lance_ 1 May 2009 at 8:11 am #

    hi ernie,

    The output file field can be any pdf file name. That’s where it’ll write the decrypted file.

    As for the error I’m not sure what to say. It could be any number of things. The error code doesn’t say how the PDF is broken, just that it is, so I’m not sure what steps can be taken to repair. (I also haven’t had a file break on me so I can’t take a look at it.)

    My best guess would be to try to repair the pdf using pdftk, just in case it’s an issue with XREF. Please let me know if that works. Good luck!

  16. ernie 1 May 2009 at 9:52 pm #

    I just tried out pdftk and once again no luck! I’m pretty angry cause I bought this ebook from ebook.com thinking “Adobe” meant .pdf! I need to use lots of quotes from this ebook for an upcoming seminar and now I have no way of copy portions of it! Is it possible for me to e-mail you the key + pdf?

  17. patrick 2 May 2009 at 12:26 pm #

    I’m also having issues with this. I bought an ebook that clearly said it was PDF, and thought I could read it on my blackberry & linux box at work, but with DRM, I’m screwed! So I tried Inept… and I actually get the success message but cant open it. I’m hoping that the ineptpdf script writer will update the script. Follow the progress here:

    http://www.mobileread.com/forums/showthread.php?t=39423

  18. Tarbh 3 May 2009 at 4:16 pm #

    Thanks a lot for that Lance. It worked a treat.

  19. jack 14 May 2009 at 10:22 pm #

    I’m having the foolowing error:
    “Traceback (most recent call last):
    File “C:\Documents and Settings
    …..

    cpuid0__(buffer)
    WindowsError: exception: access violation writing 0x00C14B58″

  20. Row 25 May 2009 at 1:00 pm #

    Not had any joy at all, seem to have had an authorisation issue with the second book reader and has taken all this time to resolve.

    There are no versoins around, does it matter if it is not the version you advise?

    Thanks :~)

  21. Clif 17 June 2009 at 11:32 am #

    Thank you, thank you, thank you, Lance.

    I bought at least $200 dollars worth of ebooks that I could not open simply because I put the wrong user id in ADE. This was 8 MONTHS AGO! Because of this script, I’ve been able to finally get into the books that I paid for.

    I do have one thing: If you hadn’t given the instructions to Pam on how to run the script, I would not have been able to do it, because this would be the first time in dealing with Python on any level. So a more KISS format on how to run the script in the future dealing with mundane problems like this would help out alot.

    But once again, thank you thank you thank you.

  22. G 2 August 2009 at 3:59 pm #

    Thanks.

  23. IANAL 14 August 2009 at 12:02 pm #

    IANAL -but this site looks like it is aiding and abetting illegal activities -and then documenting it on a publicly addressable server. Good luck with that, bro.

  24. lance_ 14 August 2009 at 1:40 pm #

    @IANAL, thanks for your concern. Unlocking books you bought isn’t illegal in Canada.

  25. Steve 19 August 2009 at 3:18 pm #

    Thanks for posting this. I’m able to run the scripts without error, but I’m unable to open the pdf file I create. I get the error: There was an error opening this document. The root object is missing or invalid

    Can anyone help?

  26. Julie 2 September 2009 at 7:51 pm #

    Did you ever get the “Error: error decrypting book session key” message? I have a few books this worked on, but the rest of them are giving me this error.

    I bought a bunch of books with ADE not authorized (yes, I’m just that stupid…) and am trying to crack ‘em open!

  27. xz739 11 September 2009 at 8:59 pm #

    i get an error of “unexpected EOF”,anyone here get the same error and any solutions here?

  28. BookWorm 24 September 2009 at 9:39 pm #

    I just read about this today – http://www.pdfunlock.com/ebook, worked for the few books I tried.

  29. happy 26 October 2009 at 3:24 pm #

    thanks to BookWorm – I can now read my newly purchased ebook on my Stanza app on my iPhone. Thank you!

  30. Kez 16 December 2009 at 11:02 pm #

    If you cannot open the decrypted PDF file because it is corrupt, check that you have version 3 of ineptpdf.pyw. Worked a treat, Yippee!
    # Revision history:
    # 1 – Initial release
    # 2 – Improved determination of key-generation algorithm
    # 3 – Correctly handle PDF >=1.5 cross-reference streams

    Find it by searching for “# ineptpdf.pyw, version 3″ on the web.

  31. Erik 18 December 2009 at 3:11 am #

    Just tried it, with success. Awesome guide!

  32. lance_ 26 December 2009 at 6:38 pm #

    Thanks Kez. I didn’t buy many ebooks recently but now that Christmas is here and I’ve got some more cash, I’m going to pick up a few.

    ineptpdf.pyw is up to version 5 now.

    # Revision history:
    # 1 – Initial release
    # 2 – Improved determination of key-generation algorithm
    # 3 – Correctly handle PDF >=1.5 cross-reference streams
    # 4 – Removal of ciando’s personal ID
    # 5 – adding pdf 1.5 support (alpha version so don’t expect everything working)

  33. Clotilde 6 January 2010 at 12:54 pm #

    Thanks for all this help. I recently bought a PDF ebook from Taylor & Francis and appling version 3 results in a corrupt pdf (it can be opened but no text is inside). Could anybody tell me where to find the latest version of the scripts?

  34. Andy Stokes 19 January 2010 at 5:49 pm #

    Massive, huge thanks for this. I will continue to buy eBooks, but at least now I don’t have to rely on Adobe Support.

  35. CJ 21 January 2010 at 4:49 am #

    Hi Lance,

    Are you aware of a similar Python script that would work under Mac OS X? Tried to use the one you link to but it references the Windows directory structure, so won’t work under Mac.

    I already opened my ADEPT book on the Mac so I probably won’t be able to reopen in my Windows virtual machine…

  36. lance_ 21 January 2010 at 9:34 pm #

    Hi CJ,

    I’m afraid I don’t know any way to get the key on OSX. You might be out of luck for that particular book. Sorry.

  37. PT 30 January 2010 at 7:40 pm #

    Lance,

    I’ve downloaded both files, ineptkey.pyw runs fine and returns a success, but when I double click ineptpdf.pyw nothing happens. Any suggestions? Thanks…

    PT

  38. r8qt7 22 February 2010 at 10:33 pm #

    ineptkey 7 does work with newer xref stream pdfs which weren’t working before

  39. joblack 23 February 2010 at 12:14 pm #

    There is a script called ineptkeymac which gets the key on the mac. The ineptpdf7 now decrypts all kind of pdfs.

  40. LeonJac 1 March 2010 at 10:34 am #

    Hi, Lance

    I downloaded an Adobe eBook (and paid for it) and it downloaded and read fine in Adobe Digital Editions.

    I want to read on my Kindle2 but I’ve run into an error while running ineptpdf.pyw:

    :Error decrypting book session key” I think Liz had the same problem last year, but I did not see a solution to her problem.

    Any ideas?

  41. LeonJac 2 March 2010 at 5:00 am #

    I managed to solve my own problem: just get the latest versions of the scripts and it all works like a charm. You can get both ineptkey.pyw (4.3) and ineptpdf.pyw(7.2) from Pastebin.com

    Apologies to Julie for calling her Liz and thanks to Lance for sharing the methodology with us – but it would be nice if you updated the links to the newer scripts!

  42. lance_ 5 March 2010 at 3:20 pm #

    Hi LeonJac,

    I’ve updated the link to point to ineptpdf.pyw 7.3.

    Also, for the mac people, there’s also ineptkeymac.py.

    Also, my Adobe Digital Editions just told me I have 44 days to update. I wonder if that’ll muck up things. I’ve stayed with my working version for now.

  43. LeonJac 6 March 2010 at 3:04 am #

    Thanks, Lance. This site has been one of the most practical and up to date I’ve come across in a long time. I’ll keep you posted if I come across anything new. Meanwhile, keep up the good work!

  44. neo1981 10 March 2010 at 5:46 pm #

    Hi there, I am having the same problem as Julie.

    I can generate the certificate, but when I try to use the ineptPDF script, it complains “Error decrypting book session key”.

    I have version 3 of ineptkey and version 7.3 of ineptpdf [1.7.2.1131 of Digital Edition] but I can’t crack open the books I got from Overdirve.

    Ideas?

    Any help is much appreciated!

  45. aman207 29 March 2010 at 12:51 pm #

    I’m a noob. How do you generate the certificate?

  46. aman207 15 April 2010 at 7:30 pm #

    does anybody know

  47. [...] I had an updated Python 2.6 distribution via MacPorts. I installed the py26-crypto package, found sources for inept on the Web, and downloaded [...]

  48. mcnolo 18 April 2010 at 11:20 am #

    Hello, i also have the same problem.

    I have inetpdf 7.4 and inetkey 4.3 and get the “Error decrypting book session key”.

    Please any help!!!

    Thanks,

  49. [...] Shared Using inept to strip DRM for better viewing – im addicted. [...]

  50. DrLarryE 24 April 2010 at 5:55 pm #

    I’ve also had the “Error decrypting book session key” error message from books downloaded through Overdrive. Has everybody been getting this message just from Overdrive books or purchased ones as well?


Leave a Reply