Removing DRM from rented Amazon azw4 eBook

To make deDRM work with rented Kindle books, you have to open and find the lines:

if val406 != 0:

raise DrmException(u”Cannot decode library or rented ebooks.”)

Then either comment them out (using #) or remove these two lines. Then deDRM works perfectly with rented eBooks.