Skip to content

Commit

Permalink
[sxs] Add support for the undocumented loadFrom keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
learn-more committed Apr 11, 2022
1 parent 1997a40 commit aedd00e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
25 changes: 25 additions & 0 deletions DependenciesLib/SxsManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ public SxsEntry(XElement SxsAssemblyIdentity, XElement SxsFile, string Folder)
Type = "";
PublicKeyToken = "";

string loadFrom = SxsFile.Attribute("loadFrom")?.Value?.ToString();
if (!string.IsNullOrEmpty(loadFrom))
{
loadFrom = Environment.ExpandEnvironmentVariables(loadFrom);
if (!System.IO.Path.IsPathRooted(loadFrom))
{
loadFrom = System.IO.Path.Combine(Folder, loadFrom);
}

// It's only a folder
if (loadFrom.EndsWith("\\") || loadFrom.EndsWith("/"))
{
Path = System.IO.Path.Combine(loadFrom, RelPath);
}
else
{
// It's also a dll name!
Path = loadFrom;
if (!Path.ToLower().EndsWith(".dll"))
{
Path += ".DLL";
}
}
}

if (SxsAssemblyIdentity != null)
{
if (SxsAssemblyIdentity.Attribute("version") != null)
Expand Down
16 changes: 14 additions & 2 deletions test/manifest-regress/Test-ManifestRegress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Test-Executable {
}
else
{
Write-Host -ForegroundColor Green "[+] $TestName test passed";
Write-Host -ForegroundColor Green "[+] $TestName test passed";
}

Write-Output ""
Expand All @@ -72,4 +72,16 @@ Test-Executable -TestName "SystemSettings" -TestExecutable $SystemSettingsPath -

# Double quotes in assemblyIdentity name attribute !
$DevicePairingFolderPath = Join-Path $RegressDir "DevicePairingFolder.dll";
Test-Executable -TestName "DevicePairingFolder" -TestExecutable $DevicePairingFolderPath -Command "-manifest" -StringToFound '<assemblyIdentity name="Microsoft.Windows.Shell.DevicePairingFolder" processorArchitecture="amd64"' -BinFolder $DependenciesDir
Test-Executable -TestName "DevicePairingFolder" -TestExecutable $DevicePairingFolderPath -Command "-manifest" -StringToFound '<assemblyIdentity name="Microsoft.Windows.Shell.DevicePairingFolder" processorArchitecture="amd64"' -BinFolder $DependenciesDir

# Redirect dll loading to a directory, so search for this directory name in the sxs dependencies
$UseDll32Path = Join-Path $RegressDir "use_dll32.exe";
Test-Executable -TestName "DllRedirection32" -TestExecutable $UseDll32Path -Command "-sxsentries" -StringToFound '\test_folder\depdll32.dll' -BinFolder $DependenciesDir

# Redirect the dll to a directory, but also change the dll name!
$UseDll64Path = Join-Path $RegressDir "use_dll64.exe";
Test-Executable -TestName "DllRedirection64CustomName" -TestExecutable $UseDll64Path -Command "-sxsentries" -StringToFound '\test_folder\custom_name64.DLL' -BinFolder $DependenciesDir

# Re-run the previous test, but ensure dependencies also knows the original dll name!
$UseDll64Path = Join-Path $RegressDir "use_dll64.exe";
Test-Executable -TestName "DllRedirection64RealName" -TestExecutable $UseDll64Path -Command "-sxsentries" -StringToFound 'depdll64.dll' -BinFolder $DependenciesDir
Binary file not shown.
Binary file added test/manifest-regress/test_folder/depdll32.dll
Binary file not shown.
Binary file added test/manifest-regress/use_dll32.exe
Binary file not shown.
8 changes: 8 additions & 0 deletions test/manifest-regress/use_dll32.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="use_dll" version="0.0.0.0"/>

<file name="depdll32.dll" loadFrom="test_folder\" />

</assembly>

Binary file added test/manifest-regress/use_dll64.exe
Binary file not shown.
8 changes: 8 additions & 0 deletions test/manifest-regress/use_dll64.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="use_dll" version="0.0.0.0"/>

<file name="depdll64.dll" loadFrom="test_folder/custom_name64" />

</assembly>

0 comments on commit aedd00e

Please sign in to comment.