Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sxs] Add support for the undocumented loadFrom keyword #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>