mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
feat(xbox): install MSIXVC2 back-compat titles from their content boxes (#2851)
* feat(xbox): install MSIXVC2 packages from their encrypted content boxes * feat(xbox): run a package's custom install actions once per prefix * fix(xbox): launch the program a launcher menu names instead of the menu * fix(xbox): check free space before an MSIXVC2 install starts * fix(xbox): keep a forwarded launch path relative when the install folder is reached through a link * fix(xbox): rebuild the MSIXVC2 patch on the final legacy install * fix(xbox): keep a backup whose release fails, and test an interrupted restore * fix(xbox): verify resumed msixvc2 files, contain writes, decode install action arguments * fix(xbox): keep one completion record per msixvc2 file, never follow a linked install state * fix(xbox): drop a torn msixvc2 completion record before appending to it * fix(xbox): repair a torn msixvc2 record from its tail instead of rereading it
This commit is contained in:
1 parent
b43724e5f3
commit
6ed281f78d
8 files changed
+1464
-21
No files matched your search
@@ -102,8 +102,29 @@ internal object XboxManifest {
|
||||
file = matches.single()
|
||||
}
|
||||
require(file.canonicalPath.startsWith(folder.canonicalPath + File.separator))
|
||||
if (file.isFile) return file.relativeTo(folder).invariantSeparatorsPath
|
||||
if (file.isFile) return forwarded(folder, file) ?: file.relativeTo(folder).invariantSeparatorsPath
|
||||
}
|
||||
error("The Xbox package has no supported PC launch executable.")
|
||||
}
|
||||
|
||||
private fun forwarded(folder: File, launcher: File): String? = try {
|
||||
val arguments = File(launcher.parentFile, launcher.nameWithoutExtension + "LaunchArguments.txt")
|
||||
if (!arguments.isFile || arguments.length() > 65_536) null
|
||||
else arguments.readLines().firstNotNullOfOrNull { line ->
|
||||
line.trim().takeIf { it.startsWith("exe=", ignoreCase = true) }?.substring(4)?.trim()
|
||||
}?.takeIf { it.isNotEmpty() && !it.contains(':') }?.let { target -> located(folder.canonicalFile, launcher.parentFile.canonicalFile, target) }
|
||||
} catch (_: java.io.IOException) {
|
||||
null
|
||||
}
|
||||
|
||||
private fun located(root: File, start: File, target: String): String? {
|
||||
var file = start
|
||||
for (part in target.split('/', '\\').filter { it.isNotEmpty() && it != "." }) {
|
||||
file = if (part == "..") file.parentFile ?: return null
|
||||
else file.listFiles().orEmpty().filter { it.name.equals(part, true) }.singleOrNull() ?: return null
|
||||
}
|
||||
val resolved = file.canonicalFile
|
||||
if (!resolved.isFile || !resolved.path.startsWith(root.path + File.separator) || !resolved.extension.equals("exe", true)) return null
|
||||
return resolved.relativeTo(root).invariantSeparatorsPath
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,46 @@ class XboxManifestTest {
|
||||
java.io.File(root, "MicrosoftGame.Config").writeText("<Game><ExecutableList><Executable Name=\"bin\\GAME.EXE\" TargetDeviceFamily=\"PC\"/></ExecutableList></Game>")
|
||||
assertEquals("Bin/Game.exe", XboxInstaller.executable(root))
|
||||
}
|
||||
@Test fun aLauncherMenuIsSkippedForTheProgramItNames() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "EmuMenu").mkdir()
|
||||
java.io.File(root, "EmuMenu/EmuMenu.exe").writeText("menu")
|
||||
java.io.File(root, "Emu.exe").writeText("emulator")
|
||||
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList><Executable Name=\"EmuMenu\\EmuMenu.exe\"/></ExecutableList></Game>")
|
||||
java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\Emu.exe\r\ntitlename=Game\r\n")
|
||||
assertEquals("Emu.exe", XboxInstaller.executable(root))
|
||||
java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\..\\outside.exe\r\n")
|
||||
assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root))
|
||||
java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("titlename=Game\r\n")
|
||||
assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root))
|
||||
java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\EMU.EXE\r\n")
|
||||
assertEquals("Emu.exe", XboxInstaller.executable(root))
|
||||
java.io.File(root, "emu.exe").writeText("other")
|
||||
if (root.listFiles().orEmpty().count { it.name.equals("emu.exe", true) } == 2)
|
||||
assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root))
|
||||
}
|
||||
@Test fun anUnreadableForwardingFileFallsBackToTheDeclaredProgram() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "EmuMenu").mkdir()
|
||||
java.io.File(root, "EmuMenu/EmuMenu.exe").writeText("menu")
|
||||
java.io.File(root, "Emu.exe").writeText("emulator")
|
||||
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList><Executable Name=\"EmuMenu\\EmuMenu.exe\"/></ExecutableList></Game>")
|
||||
val arguments = java.io.File(root, "EmuMenu/EmuMenuLaunchArguments.txt").apply { writeText("exe=..\\Emu.exe\r\n") }
|
||||
org.junit.Assume.assumeTrue(arguments.setReadable(false, false) && !arguments.canRead())
|
||||
try { assertEquals("EmuMenu/EmuMenu.exe", XboxInstaller.executable(root)) } finally { arguments.setReadable(true, false) }
|
||||
}
|
||||
@Test fun aForwardedProgramStaysRelativeWhenTheFolderIsReachedThroughALink() {
|
||||
val real = temporary.newFolder()
|
||||
java.io.File(real, "EmuMenu").mkdir()
|
||||
java.io.File(real, "EmuMenu/EmuMenu.exe").writeText("menu")
|
||||
java.io.File(real, "Emu.exe").writeText("emulator")
|
||||
java.io.File(real, "MicrosoftGame.config").writeText("<Game><ExecutableList><Executable Name=\"EmuMenu\\EmuMenu.exe\"/></ExecutableList></Game>")
|
||||
java.io.File(real, "EmuMenu/EmuMenuLaunchArguments.txt").writeText("exe=..\\Emu.exe\r\n")
|
||||
val link = java.io.File(temporary.root, "linked")
|
||||
val linked = runCatching { java.nio.file.Files.createSymbolicLink(link.toPath(), real.toPath()) }.isSuccess
|
||||
org.junit.Assume.assumeTrue(linked)
|
||||
assertEquals("Emu.exe", XboxInstaller.executable(link))
|
||||
}
|
||||
@Test fun rejectsTraversalAndExternalEntities() {
|
||||
for (xml in listOf("<Game><Executable Name=\"../escape.exe\"/></Game>",
|
||||
"<!DOCTYPE Game [<!ENTITY external SYSTEM 'file:///etc/passwd'>]><Game>&external;</Game>",
|
||||
|
||||
Reference in new issue
Block a user