
The Definitive Guide on Win32 to NT Path Conversion (2016) - camtarn
https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html
======
maxxxxx
Windows paths can be really infuriating. We constantly run into problems with
the 255 file name length limit and even if you use the APIs to create longer
paths then Explorer or other apps can't deal with these names.

It's hard to believe that after all these years this is still a problem but I
guess a clunky foundation doesn't prevent one from being successful.

------
voldacar
The ugliness of the windows API never ceases to amaze me. Functions with names
like RtlDetermineDosPathNameType_U and return types like PCWSTR just make my
eyes bleed.

~~~
colatkinson
My personal favorite is PCZZWSTR: a const pointer to a contiguous WCHAR array,
where each substring is NUL-terminated, and the array itself is also
terminated by a NUL. Thus (I assume) the ZZ--zero zero. I've only ever seen it
used in the SHFILEOPSTRUCTW struct.

~~~
voldacar
>SHFILEOPSTRUCTW

now that takes the cake

~~~
whoopdedo
Nah. That would be INITCOMMONCONTROLSEX. And the related LVM_SORTITEMSEX,
DDSCAPSEX, and of course MPR_CREDENTIALSEX_0.

~~~
saagarjha
With Microsoft's use of ALLCAPS and using an "Ex" prefix, this was all but
guaranteed…

------
gumby
Shoutout for calling himself a "path'ological reverse engineer"

------
saagarjha
> we can only store at most 215-1 characters, which just happens to be 32,767

I think the formatting ate the superscript here.

~~~
hoseja
<span style="background-color: transparent; color: black; font-family: Arial;
font-size: 14.666666666666666px; font-style: normal; font-variant: normal;
font-weight: 400; text-decoration: none; vertical-align: baseline; white-
space: pre-wrap;">2</span> <span style="background-color: transparent; color:
black; font-family: Arial; font-size: 14.666666666666666px; font-style:
normal; font-variant: normal; font-weight: 400; text-decoration: none;
vertical-align: baseline; white-space: pre-wrap;">15</span>

Yeah, I think it did.

------
yokohummer7
> Somewhere in Explorer something is passing one of these shell names to a
> file API, which is interpreting it as a Drive Relative path for the ‘:’
> drive.

Isn't this just a pure bug? I'm quite surprised such an intimidating behavior
still exists in today's Windows...

------
makomk
Gotta love how there's a whole chunk of complicated compatibility code to
emulate the old DOS-ism of having per-drive current directories.

------
MarekKnapek
> Fortunately this doesn’t seem to work in the Explorer shell, but it does
> work when passed to native APIs such as CreateFile.

CreateFile is Win32 API, not Native API. NtCreateFile would be Native API.

------
Endy
And yet with all this, I still prefer Win16/Win32 paths and system layout as
they are implemented for user needs compared to any UNIX/BSD/Linux pathing and
system structure.

~~~
m45t3r
Windows paths is full of WTFs:

\- The main driver is named C:\ because DOS used A:\ and B:\ for floppy disks!
C'mon, floppy disks were not used as the main disk since god knows why (I
think even MS-DOS itself was already supposed to run from HDDs and not floppy
disks).

\- I can't have a file named LPT1, COM, AUX, PRN, NUL, etc. This would be
fine, however I can't even have a file named _aux.ext_ , for example. I know
this is for compatibility purposes with DOS, however the fact that the error
message is terrible does not help.

-255 char limit. I know that you can use an API that allows more characters than this, however this does not work everywhere (last time I remember having problems to access those files in Windows Explorer; I think they fixed this in the latest versions of Windows 10, though).

\- Some common characters are prohibit in filenames, like ? or :. Unix has
some limitations too, however the Windows are much more ridiculous.

\- In 64 bits systems, C:\Windows\SysWoW64\system32 is for 32 bits DLLs, while
C:\Windows\system32 is for 64 bits DLLs. I really is curious why Microsoft
choose this one, it is not like they needed for legacy software [1] (since 64
bits were new systems not old ones).

I mean, most of the Windows WTFs are for compatibility purposes, however Unix
has a much more sensible path rules even if you consider that Unix has much
more history than Windows. There is much less WTFs in Unix paths (like
/usr/bin vs /bin, or /opt vs. /usr/local).

I can't really understand what is going on with Windows paths. Unix paths are
far more sane to me IMO.

[1]: If someone can link to me the reason why I would be thankful. I know that
Microsoft engineers are not stupid, I just find it really curious why
C:\Windows\system64 was not used, for example.

~~~
wvenable
The short answer:

"The 32 is just part of the name and doesn’t mean anything." \-- Raymond Chen

The long answer:

"There are quite a number of existing 32-bit programs that hard-code the
System32 path rather than calling the GetSystemDirectory function. When these
programs are recompiled for 64-bit Windows, they will still try to access the
System32 directory, expecting to find 64-bit files (because the program is now
compiled 64-bit). Paths written into configuration files or the registry need
to be meaningful to both 32-bit and 64-bit processes, yet need to refer to the
appropriate directory depending on the “bitness” of the program doing the
asking."

[https://docs.microsoft.com/en-us/previous-
versions/technet-m...](https://docs.microsoft.com/en-us/previous-
versions/technet-magazine/ff955767\(v=msdn.10\))

Basically System32 is the system directory regardless of the bitness of the
OS. What matters is the bitness of the program being executed. If a 32bit
program accesses System32 on a 64bit machine, it's silently redirected to a
folder containing 32bit libraries.

~~~
ygra
I think the only kind of program that need(ed) to know the distinction and
access those paths directly and deliberately would be an installer for a
different-fitness program. But that was also still in the days where programs
would place their files in the Windows or system directory which hopefully no
longer happens.

