Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9e8a01bb6 | ||
|
|
861121144c |
No files matched your search
@@ -112,8 +112,9 @@ object NativeGuest {
|
||||
File(BwrapSpawner.hostPath(binds.map { BwrapSpawner.Bind.parse(it) }, root.path, cwd)).takeIf { it.isDirectory } ?: root
|
||||
|
||||
/** A process for [guest] (argv) started as proot would with [binds], in guest directory [cwd]. */
|
||||
fun processBuilder(context: Context, root: File, binds: List<String>, guest: List<String>, cwd: String = "/root"): ProcessBuilder =
|
||||
ProcessBuilder(command(root, guest.first(), guest.drop(1)))
|
||||
fun processBuilder(context: Context, root: File, binds: List<String>, guest: List<String>, cwd: String = "/root"): ProcessBuilder {
|
||||
if (sessionMode == null) prepare(context, root)
|
||||
return ProcessBuilder(command(root, guest.first(), guest.drop(1)))
|
||||
.directory(workingDirectory(root, binds, cwd))
|
||||
.also { builder ->
|
||||
builder.environment().apply {
|
||||
@@ -121,6 +122,7 @@ object NativeGuest {
|
||||
putAll(sessionEnvironment(root, binds, guest.first(), SessionPrefs.guestHostname(context)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val RUNPATH_CONF = "etc/ld.so.conf.d/zz-droiddeck-native.conf"
|
||||
private val SCAN_DIRS = listOf("usr/lib", "usr/local/lib", "opt")
|
||||
@@ -149,6 +151,7 @@ object NativeGuest {
|
||||
}
|
||||
|
||||
/** What a rootfs needs before anything runs in it natively; cheap once done. */
|
||||
@Synchronized
|
||||
fun prepare(context: Context, root: File) {
|
||||
val relinked = relinkAbsoluteSymlinks(context, root)
|
||||
if (relinked > 0) android.util.Log.i(TAG, "native userland: $relinked absolute symlinks made relative")
|
||||
|
||||
@@ -94,17 +94,16 @@ internal object XboxManifest {
|
||||
}
|
||||
|
||||
fun executable(folder: File): String {
|
||||
for (path in read(folder).executables) {
|
||||
val listed = read(folder).executables
|
||||
for (path in listed) {
|
||||
require(!path.startsWith('/') && !path.contains(':') && path.split('/').none { it == ".." || it.isEmpty() })
|
||||
var file = folder
|
||||
for (part in path.split('/')) {
|
||||
val matches = file.listFiles().orEmpty().filter { it.name.equals(part, true) }
|
||||
require(matches.size == 1) { "Missing or ambiguous Xbox launch path." }
|
||||
file = matches.single()
|
||||
}
|
||||
val file = path.split('/').fold<String, File?>(folder) { dir, part ->
|
||||
dir?.listFiles().orEmpty().filter { it.name.equals(part, true) }.singleOrNull()
|
||||
} ?: continue
|
||||
require(file.canonicalPath.startsWith(folder.canonicalPath + File.separator))
|
||||
if (file.isFile) return forwarded(folder, file) ?: file.relativeTo(folder).invariantSeparatorsPath
|
||||
}
|
||||
require(listed.isEmpty()) { "Missing or ambiguous Xbox launch path." }
|
||||
error("The Xbox package has no supported PC launch executable.")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.droiddeck.launcher.runtime
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import java.io.File
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import java.nio.file.Files
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class NativeGuestPrepareTest {
|
||||
private val svc = 0xd4000001.toInt()
|
||||
private val rseq = 0xd28024a8.toInt()
|
||||
private val enosys = 0x928004a0.toInt()
|
||||
|
||||
private fun unpatchedLoader(): ByteArray {
|
||||
val data = ByteArray(0x200)
|
||||
val b = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN)
|
||||
b.put(0, 0x7f); b.put(1, 'E'.code.toByte()); b.put(2, 'L'.code.toByte()); b.put(3, 'F'.code.toByte())
|
||||
b.put(4, 2); b.put(5, 1)
|
||||
b.putShort(18, 183)
|
||||
b.putLong(32, 64)
|
||||
b.putShort(54, 56); b.putShort(56, 1)
|
||||
b.putInt(64, 1); b.putInt(68, 5)
|
||||
b.putLong(72, 0x100); b.putLong(96, 0x100)
|
||||
b.putInt(0x100, rseq); b.putInt(0x104, svc)
|
||||
return data
|
||||
}
|
||||
|
||||
private fun rootWithUnpatchedLoader(): Pair<File, File> {
|
||||
val root = Files.createTempDirectory("native-prepare").toFile()
|
||||
val loader = File(root, "usr/lib/ld-linux-aarch64.so.1")
|
||||
loader.parentFile!!.mkdirs()
|
||||
loader.writeBytes(unpatchedLoader())
|
||||
return root to loader
|
||||
}
|
||||
|
||||
private fun instructionAfterRseq(loader: File): Int =
|
||||
ByteBuffer.wrap(loader.readBytes()).order(ByteOrder.LITTLE_ENDIAN).getInt(0x104)
|
||||
|
||||
@After
|
||||
fun endSession() {
|
||||
NativeGuest.sessionMode = null
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aProgramStartedOutsideASessionGetsALoaderThatSurvivesSeccomp() {
|
||||
val (root, loader) = rootWithUnpatchedLoader()
|
||||
NativeGuest.sessionMode = null
|
||||
NativeGuest.processBuilder(ApplicationProvider.getApplicationContext(), root, emptyList(), listOf("/usr/bin/true"))
|
||||
assertEquals(enosys, instructionAfterRseq(loader))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aProgramStartedInARunningSessionLeavesTheRootfsAsTheSessionPreparedIt() {
|
||||
val (root, loader) = rootWithUnpatchedLoader()
|
||||
val before = loader.readBytes()
|
||||
NativeGuest.sessionMode = true
|
||||
NativeGuest.processBuilder(ApplicationProvider.getApplicationContext(), root, emptyList(), listOf("/usr/bin/true"))
|
||||
assertArrayEquals(before, loader.readBytes())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anAlreadyPreparedLoaderIsNotRewritten() {
|
||||
val (root, loader) = rootWithUnpatchedLoader()
|
||||
NativeGuest.processBuilder(ApplicationProvider.getApplicationContext(), root, emptyList(), listOf("/usr/bin/true"))
|
||||
val modified = loader.lastModified()
|
||||
val bytes = loader.readBytes()
|
||||
loader.setLastModified(modified - 10_000)
|
||||
NativeGuest.processBuilder(ApplicationProvider.getApplicationContext(), root, emptyList(), listOf("/usr/bin/true"))
|
||||
assertArrayEquals(bytes, loader.readBytes())
|
||||
assertEquals(modified - 10_000, loader.lastModified())
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,34 @@ 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 aListedExecutableThePackageDoesNotShipFallsThroughToTheNextOne() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "bin/x64_dx12").mkdirs()
|
||||
java.io.File(root, "bin/x64_dx12/game.exe").writeText("encrypted")
|
||||
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList>" +
|
||||
"<Executable Name=\"bin\\x64\\game.exe\" TargetDeviceFamily=\"PC\"/>" +
|
||||
"<Executable Name=\"Launcher\\start.exe\" TargetDeviceFamily=\"PC\"/>" +
|
||||
"<Executable Name=\"bin\\x64_dx12\\game.exe\" TargetDeviceFamily=\"PC\"/></ExecutableList></Game>")
|
||||
assertEquals("bin/x64_dx12/game.exe", XboxInstaller.executable(root))
|
||||
}
|
||||
@Test fun anAmbiguouslyCasedExecutableFallsThroughToTheNextOne() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "Game.exe").writeText("one")
|
||||
java.io.File(root, "GAME.exe").writeText("two")
|
||||
java.io.File(root, "Other.exe").writeText("three")
|
||||
org.junit.Assume.assumeTrue(root.listFiles().orEmpty().count { it.name.equals("game.exe", true) } == 2)
|
||||
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList>" +
|
||||
"<Executable Name=\"game.exe\"/><Executable Name=\"Other.exe\"/></ExecutableList></Game>")
|
||||
assertEquals("Other.exe", XboxInstaller.executable(root))
|
||||
}
|
||||
@Test fun aPackageWithNoneOfItsListedExecutablesStillFails() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "Unlisted.exe").writeText("encrypted")
|
||||
java.io.File(root, "MicrosoftGame.config").writeText("<Game><ExecutableList>" +
|
||||
"<Executable Name=\"bin\\Game.exe\"/><Executable Name=\"Game.exe\"/></ExecutableList></Game>")
|
||||
val failure = assertThrows(IllegalArgumentException::class.java) { XboxInstaller.executable(root) }
|
||||
assertEquals("Missing or ambiguous Xbox launch path.", failure.message)
|
||||
}
|
||||
@Test fun aLauncherMenuIsSkippedForTheProgramItNames() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "EmuMenu").mkdir()
|
||||
|
||||
Reference in new issue
Block a user