microsoft / MSIX-PackageSupportFramework

The Package Support Framework (PSF) is a kit for applying compatibility fixes to packaged desktop applications.
MIT License
115 stars 57 forks source link

Get final file path for PackageRoot directory in case it is a reprasepoint #69

Closed jaholme closed 5 years ago

jaholme commented 5 years ago

In many cases the PackageRoot directory can be a reparsepoint in which case QueryFullProcessImageName will return a different value than the PackageRoot obtained by GetCurrentPackagePath*.

For example if an application is installed on a non-system drive D, GetCurrentPackagePath will return a path which is a junction C:\Program Files\WindowsApps\PackageFullName that points to the location on the other drive D:\WindowsApps\PackageFullName QueryFullProcessImageName resolves all intermediate reparse points and will return D:\WindowsApps\PackageFullName\Foo.exe. String comparison between C:\Program Files\WindowsApps\PackageFullName and the image path will fail and we will not inject PSF into the child process Foo.exe.

This change calculates the final path of the PackageRoot directory using GetFinalPathNameByHandle once per process and compares against that path when determining if PSF should be injected into a process.