9

I'd like to know how I can strip DRM from a Kindle book. I would like to buy a Kindle ebook from Amazon. I'd strip the DRM, and convert it to Epub (so I can listen to it on a headset connected to my iPhone) and to PDF format (so, while listening, I can follow the story in a PDF reader (Okular) using my Ubuntu based distro, and annotate the book).

I have spent an hour searching for software for stripping the DRM but only found links to pages of which the content didn't seem helpful, or which I didn't trust.

  • Since removing a DRM violates copywrite laws, I don't think you will find anything trustable. – ravery Mar 19 '18 at 23:51
  • 2
    Removing or bypassing DRM doesn't violate copyright. It may violate some other (more serious) anti-circumvention law, such as the DCMA, but this is dependent on where you live and possibly what purpose you will be using the e-book for. The OP may or may not live somewhere that format shifting is an exemption, or even somewhere where there is no DMCA equivalent. – thomasrutter Mar 20 '18 at 0:02
  • If you're in the US, the DMCA makes it it illegal to bypass a control that would prevent you accessing (eg viewing) some content, but it's not illegal to bypass a control that only prevents you copying or doing some other action with the content. It is however illegal to distribute tools that do that. – thomasrutter Mar 20 '18 at 0:07
  • I live in the US and the Kindle formats are not controls that prevent me from "accessing (eg viewing)" the contents from Kindle books since Amazon offers Kindle book readers which are available to me. Since I intent to pay for the book, I feel justified doing with it as I described in my initial posting. I have no intention to distribute it or to do anything with it which would result in financial gain. – Vim Linux dummy born in 1935 Mar 20 '18 at 0:45
8

I'll leave the legalities, and ethicalness of this up to the lawyers, but my understanding is that it's illegal to break DRM, but legal to make a single backup of DRM material you have a legal right to have access to.

The answer to the question I believe is found by combining two separate works:

  1. First this package: Calibre
  2. Coupled with this plugin: DeDRM

The directions are detailed at the plugin link.

| improve this answer | |
2

I'm not going to go into the legality of the removal of DRM, as it varies by country — in some it falls under fair use, in others the situation is murky and in others yet it's explicitly illegal.

The following steps worked for me, on Ubuntu 18.04.

Install necessary programs using the package manager

sudo apt-get install wine64
sudo apt-get install calibre
# sudo apt-get install winetricks # this is optional — see below

Download other necessary programs

DeDRM plugin

wget https://github.com/apprenticeharper/DeDRM_tools/releases/download/v6.6.3/DeDRM_tools_6.6.3.zip

Kindle for PC v 1.17

(Closely based on the information from the official FAQ (snapshot). Link to the latest version.)

For best results you need an old version of Kindle for PC (≤1.17). (Slightly more recent versions (≥1.24) use the sub-optimal KFX file format for downloaded books, while even more recent versions can't be "exploited" by the DeDRM plugin, at all.)

Unfortunately, that version of Kindle for PC is no longer available from Amazon's websites, so you'll need to google/duckduckgo for the filename KindleForPC-installer-1.17.44170.exe and download it from some sketchy website. To ensure that you've downloaded the "original" file (and not a modified version with bonus malware), you need to check the hash of the file. (md5 is "broken" and sha1 is partially "broken" so I don't recommend relying solely on them.)

sha256sum KindleForPC-installer-1.17.44170.exe | grep 14e0f0053f1276c0c7c446892dc170344f707fbfe99b6951762c120144163200

If you don't trust me, a random person on the internet, to tell you the correct hash, (you have no reason to) you can go to the official FAQ, above — after all, you're already trusting the DeDRM plugin not to be malicious. (There's a space in the sha256 hash, in the FAQ, for some reason.)

winetricks

We can't use winetricks for Kindle for PC, as that installs version 1.20, which isn't as suitable.

Install and run Kindle for PC

wine64 KindleForPC-installer-1.17.44170.exe

Enter your amazon account details, download the relevant books to the "device" (i.e. your computer) etc.

Install the calibre DeDRM plugin

unzip DeDRM_tools_6.6.3.zip
calibre-customize --add DeDRM_calibre_plugin/DeDRM_plugin.zip

Alternatively, after unzipping you can just install it via Calibre's standard UI. (Preferences > Advanced > Plugins > Load plugin from file.)

Extract your kindle keys

If you're using WINE/Linux, the DeDRM plugin won't extract the keys by itself "auto-magically" without some fiddling.

DeDRM_calibre_plugin/DeDRM_plugin_ReadMe.txt contains some suggestions on how to proceed. They partially, but not completely worked for me.

Install python (within wine)

In order to extract the DRM keys, a python script (provided by the calibre plugin) will need to be run within wine (ideally) by the calibre plugin itself. Hence, you need to install python within the wine environment.

There are two alternatives here — use winetricks or install manually from the official python website.

Manual installation (currently recommended)

wget https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi
msiexec /i python-2.7.13.msi ALLUSERS=1

Note that this differs from the instructions currently in DeDRM_calibre_plugin/DeDRM_plugin_ReadMe.txt by the crucial addition of ALLUSERS=1.

Winetricks (not recommended unless you have a new version of winetricks)

If you're using winetricks installed from Ubuntu's repositories, on 18.04, then unfortunately only python-2.6 (which you can install with winetricks python26) is available. Because the calibre plugin currently hardcodes the path to a standard python-2.7 installation, that's suboptimal. Consequently you would either need to patch the calibre plugin or run the wine python script yourself and copy the decryption keys.

If you have a newer version of winetricks, you can install python-2.7.

winetricks python27

Have the wine python script run

In order for the calibre plugin to run the script, you have to tell it where your wine installation is located (the so-called "WINEPREFIX"). By default, the wineprefix is ~/.wine/. You can tell the calibre plugin your WINEPREFIX, in Calibre, by going to Preferences > Advanced > Plugins > File type plugins > DeDRM > Customize plugin > Kindle for PC and Adobe Digital Editions. You can prompt the running of the script by pressing the "+" button — otherwise it will be run when you first try adding a book with Kindle DRM.

That should be it — when you add books to calibre, they'll be automatically stripped of DRM. Alternatively, you can look at the (almost) cli version, below, which is stripped of most of my verbose explanations.

(Almost) purely command-line version

Don't just copy-paste all of this in one go, as it won't work — a couple of the steps need human participation.

sudo apt-get install wine64
sudo apt-get install calibre

mkdir -p ~/Downloads/kindle_dedrm/
cd ~/Downloads/kindle_dedrm/

# somehow get KindleForPC-installer-1.17.44170.exe
# check its hash
sha256sum KindleForPC-installer-1.17.44170.exe | grep 14e0f0053f1276c0c7c446892dc170344f707fbfe99b6951762c120144163200

wine64 ~/Downloads/kindle_dedrm/KindleForPC-installer-1.17.44170.exe &

# Enter your amazon account details, download your relevant books to the device etc.

wget https://github.com/apprenticeharper/DeDRM_tools/releases/download/v6.6.3/DeDRM_tools_6.6.3.zip
unzip DeDRM_tools_6.6.3.zip
# Install plugin (could also use Calibre's GUI)
calibre-customize --add DeDRM_calibre_plugin/DeDRM_plugin.zip

wget https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi
msiexec /i python-2.7.13.msi ALLUSERS=1

# Configure the calibre dedrm plugin with the correct wineprefix
# (could also use Calibre's GUI)
# (could also save it to a file and run, say,
# python add_wine_prefix_to_dedrm_config.py #)
python -c '
import json
import os

home = os.path.expanduser("~")
file = open(home + "/.config/calibre/plugins/dedrm.json", "r+")

dedrm_config = json.load(file)

dedrm_config["kindlewineprefix"] = home + "/.wine/"

file.seek(0)
json.dump(dedrm_config, file)
file.truncate()
file.close()
'

# Add all your Kindle books to the Calibre Library for automatic processing
calibredb add ~/Documents/My\ Kindle\ Content/*.azw --with-library="Calibre Library"
## (Optionally) list your books
# calibredb list --with-library="Calibre Library"
## (Optionally) export the first book
# calibredb export 1 --with-library="Calibre Library"
## (Optionally) export all your books
# calibredb export --all --with-library="Calibre Library"

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.