Kindle DRM Removal Using SCons

I have a Kindle. I like it a lot, but it has some issues. The recent Macmillan vs. Amazon fight is one. Another is the DRM on every file purchased from Amazon. If I buy a book, I want to know that I can read it forever. Luckily, smart people figured out how to break the DRM on most Kindle books a long time ago. A few books are in another format called Topaz that until recently hadn’t been broken. I just found a book I wanted that was in that format, so I went and looked again, and it turns out someone finally cracked it about a month ago.

I’m not going to link to any of the actual tools here, but they shouldn’t be too hard to find. My contribution is an SConstruct file for the SCons build system that automatically copies all my books to my computer and removes the DRM all in one step.  It’s not your typical use of a build system, but when I thought about what I was trying to do, I realized it was really just a simple dependency graph, something SCons is perfect for.

The complete process is:

  1. Plug Kindle into computer via USB
  2. In a shell, cd <path/where/this/file/lives>
  3. scons

This will automatically get any new books, and remove the DRM (and in Topaz’s case, convert them into svg files viewable in a browser)

Installation is not difficult either:

  1. Install SCons
  2. Put this SConstruct file in the directory where you want to save your books
  3. Get your Kindle’s PID and put it in the SConstruct file (the DRM tools will tell you how to do that)
  4. Edit the location your Kindle gets mounted to. The one I have in there is for a Mac, but except for that path I don’t see any reason this won’t all work on any OS
  5. Put the DRM tools in a tools subdirectory

SConstruct file after the jump

import os
 
env = Environment()
 
# Put your Kindle's PID here
env['KINDLECODE'] = '1234567890'
 
# Put the path to your Kindle when attached via USB
# (This is where it shows up on a Mac)
env['DEVICEDIR'] = '/Volumes/Kindle/documents'
 
# Topaz dedrm only wants the first 8 chars of the kindle PID
env['SHORTKINDLECODE'] = env['KINDLECODE'][:8]
 
env['MOBIDEDRM'] = 'tools/MOBI/MobiDeDrm09.py'
topazprogs='tools/TOPAZ/'
env['TOPAZDEDRM'] = topazprogs + 'cmbtc_dump_nonK4PC.py'
env['TOPAZ2SVG'] = topazprogs + 'gensvg.py'
env['TOPAZ2HTML'] = topazprogs + 'genhtml.py'
 
if os.path.exists(env['DEVICEDIR']):
    kindle = Glob(env['DEVICEDIR'] + '/*.azw') + Glob(env['DEVICEDIR'] + '/*.azw1')
    for k in kindle:
        Command('DRM/'+k.name, k, Copy("$TARGET", "$SOURCE"))
 
azw = Glob('DRM/*.azw')
mobi = []
 
for a in azw:
    base,ext = os.path.splitext(a.name)
    mobi += env.Command('#Mobi/'+base+'.mobi', a,
                        '$MOBIDEDRM $SOURCE $TARGET "$KINDLECODE"')
Ignore(mobi, env['MOBIDEDRM'])
 
azw1 = Glob('DRM/*.azw1')
topaz = []
for a in azw1:
    base,ext = os.path.splitext(a.name)
    topazdir = env.Dir('#Topaz/'+base+'/')
    dat = env.Command(topazdir.File('dict0000.dat'), a,
                      '$TOPAZDEDRM -v -v -d -o "'+topazdir.path+'" -p "$SHORTKINDLECODE" $SOURCE')
    svg = env.Command(topazdir.Dir('svg'), dat,
                      '$TOPAZ2SVG "'+topazdir.path+'"')
    topaz += svg
    #html = env.Command('#Topaz/'+base+'/book.html', topazdir,
    #                   '$TOPAZ2HTML $SOURCE')
    #topaz += html
    #env.Depends(html, svg)
 
env.Alias('all', mobi)
env.Alias('all', topaz)
 
env.Alias('mobi', mobi)
env.Alias('topaz', topaz)

5 Comments »

  1. Ogre Said,

    April 7, 2010 @ 6:27 pm

    I believe the tools that I didn’t link to also work with books downloaded for Kindle for PC. I’m not completely sure, but I think the recent liberation of Topaz files was actually due to the release of Kindle for PC making it that much easier.

  2. why why Said,

    October 20, 2010 @ 9:47 pm

    Hello,I wonder whether it can used to remove the DRM from books downloaded by kindle 3 which has latest firmware, have you ever tested?

  3. Apprentice Alf Said,

    January 5, 2011 @ 8:05 am

    The latest tools will work with Mobipocket and Topaz ebooks from a Kindle 3. See my blog for details and links.

    http://apprenticealf.wordpress.com/

    — Alf.

  4. Ibede91 Said,

    February 1, 2017 @ 2:04 am

    estradiol internet purchase buy estradiol no rx online http://gravatar.com/estradiolqem
    buy estradiol online compare

  5. Terrytiz Said,

    October 21, 2018 @ 9:42 am

    Программы для сети Wi-Fi
    http://hanxiu.net/space-uid-88237.html

    fesCofteerb
    StomoStomo

RSS feed for comments on this post · TrackBack URI

Leave a Comment