noDRM / DeDRM_tools

DeDRM tools for ebooks
7.4k stars 325 forks source link

Calibre can't import the backup.ab file for kindle for android, throws a Windows error code #438

Open Driver480 opened 1 year ago

Driver480 commented 1 year ago

Question / bug report

I followed the instructions in this https://www.mobileread.com/forums/showthread.php?t=352278&page=7 thread on mobileread. The instructions are for doing Kindle for Android on BlueStacks. Everything seems to be working right up until it is time to add the key (backup.ab) to the plugin in Calibre. Everything installs. I get a 6 MB backup.ab file when I do the backup process from bluestacks. But when I go to click on the green + sign, navigate to the backup.ab file and click on that for Choose Backup File button, it throws an error code --- I think it is windows 10 but it could be Calibre. I would appreciate any help someone can give to find out why I am getting the error and how to fix this, if that is possible. I pasted the error code being thrown when I go to import the kindle for android key down in the box for "Log Output". Thanks

P.S. : This is a "fresh" install of kindle for android, haven't even downloaded any books to the library under that yet. I don't that that should be causing a problem with importing the backup.ab file though. If anything, I would think it would cause Calibre to throw an error about no key in the backup file. Because I did register Kindle with Amazon before doing the AB backup file, and I am logged in when I do the backup. But even though it is extremely unlikely this could be the problem, thought I should go ahead and add the information anyway.

Which version of Calibre are you running?

7.1.0

Which version of the DeDRM plugin are you running?

v10.0.3

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

Amazon Kindle 4.16.0.75-1145045067

Log output

calibre, version 7.1.0
ERROR: Cannot open file or folder as it is in use: <p>Could not open the file: "C:\Users\Steve\AppData\Local\Temp\tmp3tcb323g". It is already opened in the following programs:<div>The main calibre program: C:\Program Files\Calibre2\calibre.exe

calibre 7.1  embedded-python: True
Windows-10-10.0.19045-SP0 Windows ('64bit', 'WindowsPE')
('Windows', '10', '10.0.19045')
Python 3.11.5
Windows: ('10', '10.0.19045', 'SP0', 'Multiprocessor Free')
Interface language: None
Successfully initialized third party plugins: DeDRM (10, 0, 3)
Traceback (most recent call last):
  File "C:\Users\Steve\AppData\Roaming\calibre\plugins\DeDRM.zip\config.py", line 1423, in get_android_file
  File "C:\Users\Steve\AppData\Roaming\calibre\plugins\DeDRM.zip\androidkindlekey.py", line 316, in get_serials
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\Steve\\AppData\\Local\\Temp\\tmp3tcb323g'
ElleKayEm commented 1 year ago

File still open in another program. Try closing bluestacks after getting the backup file and books. I haven't tried this method yet myself.

Driver480 commented 1 year ago

I tried that, closed bluestacks and that didn't work. Closed Windows Explorer, every program I could see running without going into the system monitor or whatever you call it and actually killing processes. Did not seem to help

ElleKayEm commented 1 year ago

Ok, took a closer look at the error log above. It says the file you're trying to open is already open in calibre. Maybe you were trying again while it was still processing?

Driver480 commented 1 year ago

No, the error message pops up immediately every time I use it. I am wondering if it has something to do with Windows Defender, or some other security setting in Windows 10. Also, if you look, the directory it is in is a temp directory, and the file name is a gibberish nonsense random character temp file name. I am about tempted to try using another emulator, but lots of people depend on BlueStacks to make this work, so even if I got it working through another one would have to find out what is causing this because it could affect many other users in the future.

Edit : And I have tried running Calibre in normal mode as well as running it as an Administrator. Same thing happens.

ElleKayEm commented 1 year ago

Once you select the backup file and click open, does the file name appear to the right of the Choose Backup File button?

Driver480 commented 1 year ago

No, it immediately throws that error in a popup window, the first 2 lines that are in the 'log output' box above show on the window, and the rest of the code shows when you click the details button for more details about the error. It never gets anywhere close to letting Calibre even open that backup.ab file. I think, not sure, that something in Windows is locking it up right away.

ElleKayEm commented 1 year ago

Okay, just tried this myself and I'm getting the same error. And it occurs before the file name appears. I wonder if it is calibre 7.x. Too late right now for me to experiment further.

Driver480 commented 1 year ago

I do believe it is. I followed the instructions on that mobileread forum post exactly, including installing the exact version of Calibre they wanted, 6.17, and the exact version of DeDRM, 7.2.1, they called for. Which was the old plugin. This time it loaded the backup.ab file right up, and took the key. Or so it seems. I still haven't downloaded a book yet, so I don't know whether it is going to work, but I am hopeful. That DeDRM was from the other maintainer, and if it works I am going to stick with it. After days of trying to get this to work, if I actually finally have now, I am not going to mess with it again. Perhaps I will try the plugin in this repository later, if I get to feeling adventurous, but I am not going to mess with things right now if it indeed does work. Thanks for trying to help. I won't close this issue though, until I see that with the old versions of Calibre and the plugin it is actually working now. Thank you for the assistance you tried to provide ElleKayEm, it was greatly appreciated.

Driver480 commented 1 year ago

I decided to try DeDRM 10.0.3 (I think it is) and it took in the older version of Calibre. Now I just have to try it and see if it actually works.

Driver480 commented 1 year ago

So it seems that the DeDRM 10.0.3 works fine but you have to use the older version of Calibre. Going to have to mention this on their forum, and see what they do about it in the next new version. Anyway, it seems Calibre is the problem, not DeDRM

ElleKayEm commented 1 year ago

Did some more experimenting myself. Uninstalled calibre 7.1 and installed 6.29 -- the finale 6.x version. Was able to add my backup.ab file and decrypt a book with DeDRM 10.0.9. Then I updated back to calibre 7.1 and was still able to decrypt books from the bluestacks/Kindle for Android 4.16.0.75.

So definitely something about calibre 7 just not handling the extraction of the key from backup.ab. Possibly DeDRM could be modified to work around whatever change happened in calibre. Hopefully @noDRM can take a look.

John1772 commented 11 months ago

Just wanted to add that Calibre 7 can still extract the key from "map_data_storage.db", which is found in the root directory under "/data/data/com.amazon.kindle/databases". It works perfectly with Windows Subsystems for Android.

ElleKayEm commented 11 months ago

noDRM has addressed this issue and it should be in the next release.

matbgn commented 5 months ago

Hi folks

Any news for the integration to the next release?

ElleKayEm commented 5 months ago

You can download the autorelease with all the latest code including this fix: https://github.com/noDRM/DeDRM_tools_autorelease/releases

matbgn commented 5 months ago

For an obscure reason, Calibre cannot import the backup.ab even if I tried all possible combination (OK I'm on Linux but I was expecting some similarity to this bug nope?)

Debug mode from Calibre does not give any clue here as it seems that this is a problem with DeDRM just not able to read the file, the rest seems working fine.

Any clue on this?

matbgn commented 5 months ago

Forget it, it's only the backup that is empty... I inspected it with

https://github.com/nelenkov/android-backup-extractor

java -jar abe.jar unpack backup.ab backup.tar ""

Package com.amazon.kindle is now protected against backup

ElleKayEm commented 5 months ago

Yes, you need an older version of the Kindle Android app for backup to actually give you a key. I believe 4.17 and below.