noDRM / DeDRM_tools

DeDRM tools for ebooks
7.14k stars 319 forks source link

Cannot Import K4PC 1.17 Key on Windows 11 #223

Open srvrguy opened 1 year ago

srvrguy commented 1 year ago

Question / bug report

I'm trying to import the key for Kindle PC 1.17 on Windows 11 and the importer seems to be failing. When I run it in debug mode, I get the error shown in the log snippet I have posted.

Poking around kindlekey.py, it looks like UnprotectHeaderData() is possibly not working correctly and returning bad values, which causes the RE to fail to match anything.

Which version of Calibre are you running?

6.61

Which version of the DeDRM plugin are you running?

v10.0.3

If applicable, which version of the Kindle software are you running?

1.17

Log output

searching for kinfoFiles in C:\Users\USERNAME\AppData\Local
Found K4PC 1.9+ kinf2011 file: C:\Users\USERNAME\AppData\Local\Amazon\Kindle\storage\.kinf2011
Traceback (most recent call last):
  File "C:\Users\USERNAME\AppData\Roaming\calibre\plugins\DeDRM.zip\config.py", line 1254, in __init__
  File "C:\Users\USERNAME\AppData\Roaming\calibre\plugins\DeDRM.zip\kindlekey.py", line 947, in kindlekeys
  File "C:\Users\USERNAME\AppData\Roaming\calibre\plugins\DeDRM.zip\kindlekey.py", line 458, in getDBfromFile
UnboundLocalError: local variable 'version' referenced before assignment
ElleKayEm commented 1 year ago

This is trying to add the key from DeDRM's customization? What about adding a book and letting DeDRM automatically retrieve it?

srvrguy commented 1 year ago

That particular log is from doing a manual key import attempt inside the plugin inside Calibre. The plugin was not modified. I've tried both manual key import and key recovery via adding a book. The error lines are the same.

After getting those errors, I pulled the source manually and poked around a bit to try and see if there was an obvious issue. All I could determine is what I posted in the original issue description.

ElleKayEm commented 1 year ago

Thanks for clarifying. I just tried on my Windows 10 machine where I have Kindle 1.17, calibre 6.9, and DeDRM 10.0.3. Deleted the key that was already there (after saving it!). Then I was able to both manually import and automatically retrieve a working key. @nodrm will probably have to look into this one.

srvrguy commented 1 year ago

Yeah, I suspect this is something specific to Windows 11. My issue is that I can't really run 10 as most major VM tools on the M-series Macs don't support x86-64 (and there's not a true release of ARM Windows 10 outside the Surface builds).

I'd be happy to help test any fixes for this issue, if needed.

noDRM commented 1 year ago

That does indeed look like the regex in line 452 doesn't find the version number. Am I understanding this correctly that you're running an ARM version of Windows 11? Or just "regular" x86-64 Windows 11 in a VM on your Mac?

You could try adding something like print("Cleartext: " + str(cleartext)) after the call to UnprotectHeaderData to see if the decrypt function is indeed broken and returns junk, or if the decrypted data just looks a bit different on ARM machines causing the regex to no longer match.

Unfortunately I don't have much experience with Amazon's DRM so if it's indeed the decryption step of that header that fails to work correctly I don't think I will be able to fix this.