Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Print Statement in WineGetKeys Has ASCII Encoding and Kills Function Before Prepping Kindle Key #116

Closed
xee5ch opened this issue Jul 25, 2016 · 8 comments

Comments

@xee5ch
Copy link

xee5ch commented Jul 25, 2016

I have installed DeDRM with tagged release 6.4.3 in a contained VM using Vagrant with configuration here.

  • Debian 8.5.0 amd64
  • calibre and calibre 2.5.0+dfsg-1 (current stable in Debian)
  • wine-1.8.2
  • winetrick (20160628; was current master a few days ago)
  • Ran wine with the following winetricks vcrun2008, winetricks winhttp, winetricks wininet
  • Installed Adobe Digital Editions 1.7 via winetricks adobe_diged
  • Installed current Kindle for PC Edition via winetricks kindle
  • Authorized Adobe Digital Editions (as I heard this makes a difference)

I added the DeDRM plugin, and exported with export WINEPREFIX=/home/vagrant/.wine and specified it in the config of DeDRM. I consistently get this error.

I ran export DISPLAY=:0; calibre-debug -s; calibre-customize -b /vagrant/DeDRM_tools/DeDRM_calibre_plugin/DeDRM_plugin/; calibre from the terminal with the unzipped plugin too. I consistently get the following error.

DeDRM v6.4.3: Running kindlekey.py under Wine
Traceback (most recent call last):
File "calibre_plugins.dedrm.config", line 794, in init
File "calibre_plugins.dedrm.wineutils", line 34, in WineGetKeys
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 28: ordinal not in range(128)

Commenting outline 34 of wineutils.py and rerunning it is successful. I tested this successfully a few times and was successful.

What can I do to help track more? I have tried running pdb.set_trace(), but I am not so solid with PDB. Even stopping the Qt5 event loop, I always segfault and I am not able to stop at this line to get to know what non-ASCII variable value is throwing the error. Can I help more?

@apprenticeharper
Copy link
Owner

Thanks for your report. The path for on your system to the script contains a non-ASCII character, probably in your user folder name. I'll try to reproduce and fix it. I expect that adding the stdout processing from the main python scripts to wineutils.py will do the trick. hat is, add the SafeUnbuffered function (from, for example, kindlekey.py) to wineutils.py and then add

sys.stdout=SafeUnbuffered(sys.stdout)
sys.stderr=SafeUnbuffered(sys.stderr)

to the top of WineKeyKeys() just after the import statements.

@xee5ch
Copy link
Author

xee5ch commented Jul 26, 2016

Thanks for your report. The path for on your system to the script contains a non-ASCII character, probably in your user folder name.

That's the problem though, it is vagrant. Believe it or not, the home
folder is just /home/vagrant. The WINEPREFIX I set explicity as
/home/vagrant/.wine, suspecting from a previous experience many months
ago (that I sadly did not document and thus wasted more time again
ironically) that use of the ~ bashism and writing in ~/.wine made it
worse. But again, I played with this furiously forever because I cannot
figure out for the life of where the non-ASCII character is, especially
not ~ anyway.

Or does this have to do with the repr in Wine?

I'll try to reproduce and fix it. I expect that adding the stdout processing
from the main python scripts to wineutils.py will do the trick. hat is,
add the SafeUnbuffered function (from, for example, kindlekey.py) to
wineutils.py and then add

sys.stdout=SafeUnbuffered(sys.stdout)
sys.stderr=SafeUnbuffered(sys.stderr)

to the top of WineKeyKeys() just after the import statements.

I'll try later this evening and let you know.

@apprenticeharper
Copy link
Owner

The character causing the problem is 0x201c - the left open double quotation mark. Checing more carfully, position 28 in the line, if you have a WINEPEFIX specified, puts it somewhere in the WINEPREFIX you've set. Probably. Very puzzling.

@xee5ch
Copy link
Author

xee5ch commented Jul 27, 2016

Well I checked my bash history in the test VM. I do not quote WINEPREFIX. I also checked the DeDRM config plugin menu, and I certainly did not quote it there. I am kind of at a loss.

xee5ch added a commit to xee5ch/DeDRM_tools that referenced this issue Jul 27, 2016
First attempt was using unclean code. Properly debug by explicitly
following @apprenticealf's instructions.
@xee5ch
Copy link
Author

xee5ch commented Jul 27, 2016

Sorry for spamming, I just wanted to make sure I posted your code as requested to see we are on the same page. I am guessing we are.

But ...

I will be damned, adding that debug code seems to make a difference if I switch between it and clean v6.4.3 tagged code!? How!? Below is the output with the v6.4.3_debug_gh116 changes.

vagrant@jessie:~$ export DISPLAY=:0; export WINEARCH=win32; export WINEPREFIX=/home/vagrant/.wine; calibre-debug -s; calibre-customize -b 
/vagrant/DeDRM_tools/DeDRM_calibre_plugin/DeDRM_plugin/; calibre                                                                         
QWidget: Must construct a QApplication before a QWidget
Aborted
Plugin updated: DeDRM (6, 4, 3)
Unable to open ~/.mtpz-data for reading, MTPZ disabled.
DeDRM v6.4.3: Running kindlekey.py under Wine
DeDRM v6.4.3: Command line: ?WINEPREFIX="/home/vagrant/.wine" wine python.exe "/home/vagrant/.config/calibre/plugins/DeDRM/libraryfiles/ki
ndlekey.py" "/home/vagrant/.config/calibre/plugins/DeDRM/libraryfiles/winekeysdir"?                                                      
kindlekey.py v2.2
Copyright ? 2010-2016 by some_updates, Apprentice Alf and Apprentice Harper
searching for kinfoFiles in C:\users\vagrant\Local Settings\Application Data
Found K4PC 1.9+ kinf2011 file: C:\users\vagrant\Local Settings\Application Data\Amazon\Kindle\storage\.kinf2011
Decrypted key file using IDString '0' and UserName '0123456789ABCD'
Saved a key to Z:\home\vagrant\.config\calibre\plugins\DeDRM\libraryfiles\winekeysdir\kindlekey1.k4i
DeDRM v6.4.3: Found and decrypted 1 key file

So I continued further and discovered that wine is annoyed at me declaring a 32 bit install with WINEARCH even though it is (I export WINEARCH=win32 along with WINEPREFIX=/home/vagrant/.wine), and maybe that is the issue. But I noticed that there is this difference when I remove the GUI WINEPREFIX specification in your plugin's menu at the bottom. I need to specify it there, as export WINEPREFIX=/home/vagrant/.wine are different and your app sets up WINEPREFIX=/home/vagrant. Maybe I misunderstand the official Wine guidance and I am giving erroneous input to your app?

eDRM v6.4.3: Command line: ?WINEPREFIX="/home/vagrant" wine python.exe "/home/vagrant/.config/calibre/plugins/DeDRM/libraryfiles/kindleke
y.py" "/home/vagrant/.config/calibre/plugins/DeDRM/libraryfiles/winekeysdir"?                                                            
wine: WINEARCH set to win32 but '/home/vagrant' is a 64-bit installation.
DeDRM v6.4.3: Found and decrypted 0 key files
Traceback (most recent call last):
  File "calibre_plugins.dedrm.config", line 796, in __init__
IndexError: list index out of range
DeDRM v6.4.3: Running kindlekey.py under Wine
DeDRM v6.4.3: Command line: ?WINEPREFIX="/home/vagrant" wine python.exe "/home/vagrant/.config/calibre/plugins/DeDRM/libraryfiles/kindleke
y.py" "/home/vagrant/.config/calibre/plugins/DeDRM/libraryfiles/winekeysdir"?                                                            
wine: WINEARCH set to win32 but '/home/vagrant' is a 64-bit installation.
DeDRM v6.4.3: Found and decrypted 0 key files
Traceback (most recent call last):
  File "calibre_plugins.dedrm.config", line 796, in __init__
IndexError: list index out of range

@xee5ch
Copy link
Author

xee5ch commented Jul 27, 2016

Just to be clear, this is why I set my WINEPREFIX and WINEARCH the way I do.

wine man page from Debian

Why your app knows to truncate the .wine and who is right or wrong I am not sure very sure, haha.

@apprenticeharper
Copy link
Owner

I don't know about the wineprefix (I really need to do a proper investigation of current Linux setups), but I have spotted the problem.

The open double quotes actually appears in the python string on that line. It seems surprising that it's ever worked!

@apprenticeharper
Copy link
Owner

Fixed in 6.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants