Nmap Development mailing list archives
Re: Non-ASCII user names on Windows; internationalization fun
From: David Fifield <david () bamsoftware com>
Date: Tue, 16 Sep 2008 12:00:59 -0600
On Sun, Sep 14, 2008 at 10:13:24PM +0200, Dirk Loss wrote:
David Fifield wrote:home = os.path.expanduser("~").decode(sys.getfilesystemencoding())Thanks for doing some research. Zenmap already uses that solution.[...]But it doesn't work for my user with the Japanese name, unless the system locale is set to Japanese.I just tested in a VM and it doesn't work for me either. Sorry, I posted too quickly. Maybe you could use a ctypes based solution: import ctypes def SHGetFolderPath(nFolder, flags=0, MAX_PATH=255): buf = ctypes.create_unicode_buffer(MAX_PATH) ctypes.windll.shell32.SHGetFolderPathW(None, nFolder, None, flags, buf) return buf.value def get_home(): # CSIDL_PROFILE return SHGetFolderPath(40) def get_appdata(): # CSIDL_APPDATA return SHGetFolderPath(26) For my test account (Confucius in Chinese spelling on a German Windows XP installation) get_appdata() returns the following Unicode string: u'C:\\Dokumente und Einstellungen\\\u5b54\u592b\u5b50\\Anwendungsdaten' Using this string as input to the open() function, I have successfully created a file in this directory. But that was only a quick test and I might be wrong on this stuff as well. It's just an idea. And using ctypes arguably is not the prettiest solution...
Thanks. I was afraid the answer might be something like this. I agree that it's not pretty. In an ideal world it would be hidden inside the implementation of expanduser. I am tempted to use this solution, because it appears to be the most direct way to get a Unicode string of the home directory. ctypes requires Python 2.5, and though we try to keep Zenmap compatible with 2.4, we use 2.5 to build the Windows binaries. I'll keep the current solution for now.
BTW: According to [1] applications should not create files or folders at the profile level, so I used get_appdata() instead of get_home() in my above example. [1] http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx
I didn't know that. Does anyone have a strong opinion as to where the .zenmap directory should go on Windows? We've just been using C:\Documents and Setting\user because it's the most directly analogous to /home/user on Unix. David Fifield _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- Still trouble with non-ASCII user names on Windows--please test David Fifield (Sep 08)
- Non-ASCII user names on Windows; internationalization fun David Fifield (Sep 10)
- Re: Non-ASCII user names on Windows; internationalization fun jah (Sep 13)
- Re: Non-ASCII user names on Windows; internationalization fun David Fifield (Sep 13)
- Re: Non-ASCII user names on Windows; internationalization fun Dirk Loss (Sep 14)
- Re: Non-ASCII user names on Windows; internationalization fun David Fifield (Sep 14)
- Message not available
- Re: Non-ASCII user names on Windows; internationalization fun David Fifield (Sep 16)
- RE: Non-ASCII user names on Windows; internationalization fun Aaron Leininger (Sep 16)
- Re: Non-ASCII user names on Windows; internationalization fun jah (Sep 13)
- Non-ASCII user names on Windows; internationalization fun David Fifield (Sep 10)
- Re: Non-ASCII user names on Windows; internationalization fun Fyodor (Sep 13)
- Re: Non-ASCII user names on Windows; internationalization fun jah (Sep 14)
- Re: Non-ASCII user names on Windows; internationalization fun David Fifield (Sep 14)