Migrating from Kindle to iBooks

I started off reading eBooks from the Amazon Kindle store. As time has progressed, I’ve found myself using my physical Kindle less and less. Partly because I forget to charge it, and partly because I can never get the lighting in my favorite reading locations quite right. And at night? Forget about it.

So I’ve converted all of my Kindle purchases to ePubs for use in iBooks. I could use the Kindle app for iOS but I’ve found iBooks to be faster at syncing read position, and it feels a lot more natural to use.

Since I went through the effort of converting all of my Kindle documents, I figured I’d write a mini guide to getting it done. I’m specifically focusing on the Mac since that’s all I know; other users will have to venture elsewhere.

Setting up Calibre

Calibre is a Java application which is an eBook management suite. It’s a bit ugly but it does what it says and works well. Since the Kindle’s eBooks are encrypted, we need to install a decryption plugin to do the heavy lifting there.

  1. Download and install Calibre.1
  2. Download and decompress the DeDRM archive.
  3. Open Calibre’s preferences (⌘,).
  4. Go to “Plugins.”
  5. Click “Load plugin from file.”
  6. Choose the K4MobileDeDRM plugin’s zip file (zip within the main zip; don’t extract).

The encryption used on Kindle books is fairly basic. The decryption key is a product of the serial number for your device, so it’s not difficult to determine.

Getting books from Amazon

The DeDRM scripts work by understanding Kindle for Mac’s settings files, so to get the eBooks we need use the application. There are scripts to do conversions directly from Kindle hardware’s eBooks, but it’s more effort.

  1. Download Kindle for Mac.
  2. Register it with your account.
  3. Download all of your eBooks (open them from the “Archived Items”).

I really wish this application were retina.

Converting books to ePub format

Kindle eBooks are in the MobiPocket format. However, iBooks requires ePub, so we need to both decrypt and convert the files. At this point, we’ve got all we need, so we can use Calibre to do the conversion.

  1. Navigate to either of the following (likely the second):
    • ~/Library/Application Support/Kindle/My Kindle Content/
    • ~/Library/Containers/com.amazon.Kindle/Data/Library/Application Support/Kindle/My Kindle Content/
  2. Drag all of the .azw files into the Calibre window.
  3. Select the books in the Calibre window which you wish to export.
  4. Click the “Convert books” toolbar item.
  5. Choose “ePub” as the output format in the top-right of the convert window.
  6. Go to the “Page Setup” item in the left list, and configure the conversion:
    • Select “Kindle” as the input profile.
    • Select “iPad” as the output profile.
  7. Hit the “OK” button to begin the conversion. It will take a while.

If you have any issues at the decryption step, you should delete your ~/Library/Application Support/Kindle folder and start again.

Exporting and enjoyment

You can now “Save to disk” from the toolbar item to save the books which you’ve converted, and import them into iTunes for use in iBooks. Calibre is powerful enough to do many other formats if you want to use other devices as well.

Remember, don’t post any of the unencrypted documents anywhere. Just because the DRM is gone doesn’t mean you’re legally authorized to do so. They’re for your personal use only.


  1. This is a link to the project’s GitHub page because their main website does not support HTTPS. You should not install software over an unencrypted connection. ↩︎

Incrementing with a bitmask

Bitmasks are fun. There’s lots of little tricks you can do with them. A common situation is checking for the presence of a flag among elements in a linked list, or some similar data structure. I came across a trick a few years ago that makes it drop-dead simple.

Let’s say we needed to check for AUsefulFlag in the flags element of each node, and total how many elements in the linked list had the flag.

uint64_t count = 0;
for(Node *iter = head; iter != NULL; iter = iter->next)
{
    count += !!(iter->flags & AUsefulFlag);
}

After execution, count is the number of items which have AUsefulFlag set.

Double-not (!!) is one of those useful operations which are especially useful with bitmasks. It may require a double-take at first, but it behaves exactly how you’d think.

!! of 1 is 1. !! of 0 is 0. In fact, !! of any true value evaluates to 1, so we can use it to transform something like 0b00001000 to simply 1 and increment by that value.

From Atlas Shrugged by Ayn Rand:

James: What are you after?
Francisco: Money.
James: Don’t you have enough?
Francisco: In his lifetime, every one of my ancestors raised the production of d’Anconia Copper by about ten per cent. I intend to raise it by one hundred.
James: What for?
Francisco: When I die, I hope to go to heaven–whatever the hell that is–and I want to be able to afford the price of admission.
James: Virtue is the price of admission.
Francisco: That’s what I mean, James. So I want to be prepared to claim the greatest virtue of all–that I was a man who made money.
James: Any grafter can make money.
Francisco: James, you ought to discover some day that words have an exact meaning.