diff --git a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt index b309bca43b..5658642733 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt @@ -488,6 +488,12 @@ object WinComponents { return dir } + internal fun nativeDlls(c: Component): List = c.steps.filter { it.action == "override_dll" }.flatMap { step -> + listOf(step.str("dll") to step.str("type")) + (step.json.optJSONArray("bundle")?.let { b -> + (0 until b.length()).map { b.getJSONObject(it).let { o -> o.optString("value") to o.optString("data") } } + } ?: emptyList()) + }.filter { (dll, type) -> type == "native" && validId(dll) }.map { it.first.lowercase() }.distinct() + private fun installPackage(context: Context, c: Component, step: Step, staging: File, onProgress: (Progress) -> Unit): Pair { val root = LinuxRuntime.rootDir(context) val url = step.str("url") @@ -505,7 +511,9 @@ object WinComponents { onProgress(Progress(c.name, "installing", Phase.INSTALL, 0)) var result: JSONObject? = null var problem: String? = null - val status = GuestCommand.run(context, guest(listOf(MSI_INSTALL, "/$MSI_CACHE/${file.name}", "/$STORE/${staging.name}")), + val native = nativeDlls(c) + val flags = if (native.isEmpty()) emptyList() else listOf("--native", native.joinToString(",")) + val status = GuestCommand.run(context, guest(listOf(MSI_INSTALL) + flags + listOf("/$MSI_CACHE/${file.name}", "/$STORE/${staging.name}")), logName = "wincomponents-${c.name}") { line -> when { line.startsWith("progress ") -> engineLine(line.removePrefix("progress ")).let { (text, pct) -> onProgress(Progress(c.name, text, Phase.INSTALL, pct)) } diff --git a/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt b/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt index 8311736999..5b29e67d70 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt @@ -31,6 +31,14 @@ class WinComponentsSupportTest { step("install_msi", "url" to "$base/ps-x86.msi"), step("install_msi", "url" to "$base/ps-x64.msi")))) } + @Test fun onlyDllsOrderedNativeAreKeptFromDownlevelSystemComponents() { + val c = component("dotnet40", step("override_dll", "dll" to "MSCOREE", "type" to "native"), + step("override_dll", "dll" to "fusion", "type" to "builtin"), step("override_dll", "dll" to "msvcr100"), + step("override_dll", "dll" to "../x", "type" to "native"), step("install_exe", "url" to "$base/dotnet40.exe")) + assertEquals(listOf("mscoree"), WinComponents.nativeDlls(c)) + assertEquals(emptyList(), WinComponents.nativeDlls(component("xna40", step("install_msi", "url" to "$base/xna40.msi")))) + } + @Test fun builtInArm64RuntimeIsRegistryOnlyInBothViews() { val c = WinComponents.builtInArm64Runtime() assertEquals(Support.READY, support(c)) diff --git a/external/MaliBridge b/external/MaliBridge index 64a3f22354..95a1e600a5 160000 --- a/external/MaliBridge +++ b/external/MaliBridge @@ -1 +1 @@ -Subproject commit 64a3f223547918315cad8773b20693459fd3a945 +Subproject commit 95a1e600a51299294e06bb09db2db8cc509fe6a3 diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install b/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install index 681cf4031b..bf39515d86 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install @@ -50,6 +50,8 @@ SYSTEM_PROPERTIES = { "Msix64": "6", "ALLUSERS": "1", "Privileged": "1", "AdminUser": "1", "MsiNTProductType": "1", "UILevel": "2", "INSTALLLEVEL": "1", "ProgramFilesFolder": None, "VersionMsi": "5.00", } +DOWNLEVEL_PROPERTIES = {"VersionNT": "502", "VersionNT64": "502", "WindowsBuild": "3790", "ServicePackLevel": "2"} +SYSTEM_DIRS = ("drive_c/windows/system32", "drive_c/windows/syswow64") COMPONENT_64BIT = 0x100 FILE_NONCOMPRESSED = 0x2000 @@ -318,8 +320,9 @@ def clr_version(path): class Installer: - def __init__(self, msi, out, package=None, span=None): + def __init__(self, msi, out, package=None, span=None, native=()): self.pkg = package or Package(msi) + self.native = {name.lower() for name in native} self.out = Path(out) self.span = span or Span() self.notes = [] @@ -462,10 +465,19 @@ class Installer: owners = mapped.get(name) if owners is not None and not owners & self.included_features: continue - if not self.conditions.evaluate(row.get("Condition", ""), default=True): + if not self.conditions.evaluate(row.get("Condition", ""), default=True) and not self.downlevel_native(row): continue self.included_components.add(name) + def downlevel_native(self, row): + if not self.native or (self.directory(row.get("Directory_", "")) or "").lower() not in SYSTEM_DIRS: + return False + key = next((f for f in self.pkg.table("File") if f["File"] == row.get("KeyPath")), None) + if key is None or Path(long_name(key["FileName"])).stem.lower() not in self.native: + return False + props = dict(self.props, **DOWNLEVEL_PROPERTIES) + return Conditions(props, self.feature_state, self.component_state).evaluate(row.get("Condition", ""), default=False) + def assemblies(self): names = {} for row in self.pkg.table("MsiAssemblyName"): @@ -874,7 +886,7 @@ def choose_packages(found, root): return chosen -def install_wrapper(path, out): +def install_wrapper(path, out, native=()): total = {"product": "", "version": "", "counts": {"files": 0, "assemblies": 0, "registry": 0}, "notes": [], "packages": []} with tempfile.TemporaryDirectory(dir=str(out.parent), prefix=".unpack-") as work: dest = Path(work) / "x" @@ -887,7 +899,7 @@ def install_wrapper(path, out): lo, hi = 0.1 + 0.9 * index / len(packages), 0.1 + 0.9 * (index + 1) / len(packages) progress("package %d of %d: %s" % (index + 1, len(packages), package.name), lo) try: - result = Installer(str(package), out, span=Span(lo, hi)).install() + result = Installer(str(package), out, span=Span(lo, hi), native=native).install() except MsiError as error: if "installs nothing" in str(error) and len(packages) > 1: total["notes"].append("%s: %s" % (package.name, error)) @@ -939,6 +951,10 @@ def unpack_only(path, dest): def main(): args = sys.argv[1:] + native = [] + while len(args) > 1 and args[0] == "--native": + native += [name for name in args[1].split(",") if name] + args = args[2:] if len(args) == 3 and args[0] == "--unpack": try: result = unpack_only(Path(args[1]), Path(args[2])) @@ -948,16 +964,16 @@ def main(): print("result " + json.dumps(result), flush=True) return 0 if len(args) != 2: - print("usage: droiddeck-msi-install \n" + print("usage: droiddeck-msi-install [--native dll,...] \n" " droiddeck-msi-install --unpack ", file=sys.stderr) return 2 source, out = Path(args[0]), Path(args[1]) out.mkdir(parents=True, exist_ok=True) try: if kind_of(source) == "msi": - result = Installer(str(source), out).install() + result = Installer(str(source), out, native=native).install() else: - result = install_wrapper(source, out) + result = install_wrapper(source, out, native) except MsiError as error: print("error " + str(error), flush=True) return 1 diff --git a/tools/tests/test_msi_install.py b/tools/tests/test_msi_install.py index 60d8fc8df4..a809dbc6f4 100644 --- a/tools/tests/test_msi_install.py +++ b/tools/tests/test_msi_install.py @@ -29,8 +29,8 @@ def rows(columns, *values): return [dict(zip(names, value)) for value in values] -def installer(tables, out="/tmp/unused", summary=None): - return MSI["Installer"]("fake.msi", out, FakePackage(tables, summary)) +def installer(tables, out="/tmp/unused", summary=None, native=()): + return MSI["Installer"]("fake.msi", out, FakePackage(tables, summary), native=native) class ToolsTest(unittest.TestCase): @@ -118,6 +118,40 @@ class LayoutTest(unittest.TestCase): inst.select() self.assertEqual(inst.included_components, {"Up", "Wide"}) + def downlevel_shim(self, native, directory="SysShim", key="ShimDll", condition="VersionNT < 600"): + inst = installer({ + "Directory": rows("Directory Directory_Parent DefaultDir", + ("TARGETDIR", "", "SourceDir"), + ("ProgramFilesFolder", "TARGETDIR", "PFiles"), + ("AppDir", "ProgramFilesFolder", "App"), + ("SysShim", "TARGETDIR", "Win")), + "CustomAction": rows("Action Type Source Target", ("SetSys", "51", "SysShim", "[SystemFolder]")), + "InstallExecuteSequence": rows("Action Condition Sequence", ("SetSys", "", "1")), + "Feature": rows("Feature Feature_Parent Level", ("Main", "", "1")), + "Component": rows("Component Directory_ Attributes Condition KeyPath", + ("Shim", directory, "0", condition, key), + ("Old", "SysShim", "0", "VersionNT < 600", "OldDll"), + ("Vista", "SysShim", "0", "VersionNT = 600", "VistaDll")), + "FeatureComponents": rows("Feature_ Component_", ("Main", "Shim"), ("Main", "Old"), ("Main", "Vista")), + "File": rows("File Component_ FileName", ("ShimDll", "Shim", "MSCOREE.DLL|mscoree.dll"), + ("OldDll", "Old", "dxva2.dll"), ("VistaDll", "Vista", "mscoree.dll")), + }, native=native) + inst.run_set_actions() + inst.select() + return inst.included_components + + def test_a_native_override_keeps_a_system_file_newer_windows_ships_itself(self): + self.assertEqual(self.downlevel_shim(["mscoree"]), {"Shim"}) + + def test_without_a_native_override_os_version_conditions_still_apply(self): + self.assertEqual(self.downlevel_shim([]), set()) + self.assertEqual(self.downlevel_shim(["mscorwks"]), set()) + + def test_only_system_folders_and_downlevel_conditions_are_relaxed(self): + self.assertEqual(self.downlevel_shim(["mscoree"], directory="AppDir"), set()) + self.assertEqual(self.downlevel_shim(["mscoree"], condition="VersionNT = 600"), set()) + self.assertEqual(self.downlevel_shim(["mscoree"], condition="VersionNT < 600 AND VersionNT64"), {"Shim"}) + def test_a_duplicate_onto_the_file_itself_is_skipped(self): with tempfile.TemporaryDirectory() as tmp: src = Path(tmp) / "cab" / "dotnet.exe"