noDRM / DeDRM_tools

DeDRM tools for ebooks
7.05k stars 316 forks source link

Can not generate kindle key file on windows when using a Chinese username #576

Open rApeNB opened 2 months ago

rApeNB commented 2 months ago

On windows, if the username contains non-ASCII characters, such as using a Chinese username, you will not be able to generate a Kindle key file. Unable to decrypt books. The programme reported that it could not decrypt .kinf2018

ElleKayEm commented 2 months ago

I thought that had been fixed. Which version of DeDRM?

rApeNB commented 2 months ago

I thought that had been fixed. Which version of DeDRM?

It's v10.0.3. Latest version of releases.

I use windows 10, Kindle For PC v2.4.0, and windows uername is Chinese name.

I also checked the git log at Kindlekey. v2.5 of the py file claims to have solved the problem. I did run into the problem though.

The previous key was replacing non-ascii characters in username.

` def GetUserName(): GetUserNameW = advapi32.GetUserNameW GetUserNameW.argtypes = [c_wchar_p, POINTER(c_uint)] GetUserNameW.restype = c_uint def GetUserName(): buffer = create_unicode_buffer(2) size = c_uint(len(buffer)) while not GetUserNameW(buffer, byref(size)): errcd = getLastError() if errcd == 234:

bad wine implementation up through wine 1.3.21

                return "AlternateUserName"
            # double the buffer size
            buffer = create_unicode_buffer(len(buffer) * 2)
            size.value = len(buffer)

        # replace any non-ASCII values with 0xfffd
        for i in range(0,len(buffer)):
            if sys.version_info[0] == 2:
                if buffer[i]>u"\u007f":
                    #print "swapping char "+str(i)+" ("+buffer[i]+")"
                    buffer[i] = u"\ufffd"
            else: 
                if buffer[i]>"\u007f":
                    #print "swapping char "+str(i)+" ("+buffer[i]+")"
                    buffer[i] = "\ufffd"
        # return utf-8 encoding of modified username
        #print "modified username:"+buffer.value
        return buffer.value.encode('utf-8')
    return GetUserName
GetUserName = GetUserName()`

This code should work, but it really doesn't work in my environment.

ElleKayEm commented 2 months ago

Try DeDRM 10.0.9: https://github.com/noDRM/DeDRM_tools/releases/tag/v10.0.9

And let's see a log of adding a book: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md#i-cannot-solve-my-problem-with-the-dedrm-plugin-and-now-i-need-to-post-a-log-how-do-i-do-that

rApeNB commented 2 months ago

image

I used the version you mentioned and the results are still the same.

ElleKayEm commented 2 months ago

Let's see the whole log.

rApeNB commented 2 months ago

There's no log. I do not use the plugins nor Calibre. I just run the kindlekey.py file, The purpose of this file is to generate the relevant key files used by kindle decryption. On my computer, Chinese username, can't generate key. If you use a plain English character username, you can generate a key.

ElleKayEm commented 2 months ago

Ok, maybe @noDRM can take a look.

rApeNB commented 2 months ago

Any suggestions?

ElleKayEm commented 2 months ago

Use calibre and the plugins. :) Honestly I don't know if that would help. But it has been years since I last saw this issue, and I find it hard to imagine it is because no one had non-ascii characters in their Windows user name.