mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
fix(desktop): an arm64 AppImage started directly runs like one opened from the file manager (#3108)
* fix(desktop): an arm64 AppImage started directly runs like one opened from the file manager Without proot a guest program starts through the dynamic loader, which refuses the nonzero ABI version byte that marks every type 2 AppImage, so running an arm64 AppImage from a terminal or from a menu entry that names the image failed with "ELF file ABI version invalid". The preload already hands foreign programs to droiddeck-open; AppImages now go there too, where they are unpacked and started as the file manager does. * fix(desktop): hand off only AppImages that carry a filesystem, never a bare runtime
This commit is contained in:
1 parent
5cb8e7fdf3
commit
366afa6b73
2 files changed
+32
-2
No files matched your search
@@ -32,17 +32,26 @@ static int handing_off(void) {
|
|||||||
return flag("DD_DESKTOP") || flag("DD_BINFMT");
|
return flag("DD_DESKTOP") || flag("DD_BINFMT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int appimage(int fd, const unsigned char *head, ssize_t n) {
|
||||||
|
Elf64_Ehdr eh;
|
||||||
|
if (n < (ssize_t)sizeof eh || head[EI_CLASS] != ELFCLASS64 || memcmp(head + EI_ABIVERSION, "AI\x02", 3)) return 0;
|
||||||
|
memcpy(&eh, head, sizeof eh);
|
||||||
|
char magic[6];
|
||||||
|
off_t at = (off_t)eh.e_shoff + (off_t)eh.e_shentsize * eh.e_shnum;
|
||||||
|
return pread(fd, magic, sizeof magic, at) == (ssize_t)sizeof magic && (!memcmp(magic, "hsqs", 4) || !memcmp(magic, "DWARFS", 6));
|
||||||
|
}
|
||||||
|
|
||||||
static int foreign(const char *path, int error) {
|
static int foreign(const char *path, int error) {
|
||||||
if (!path || !strcmp(path, BINFMT_HANDLER)) return 0;
|
if (!path || !strcmp(path, BINFMT_HANDLER)) return 0;
|
||||||
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||||
if (fd < 0) return 0;
|
if (fd < 0) return 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
unsigned char head[20];
|
unsigned char head[sizeof(Elf64_Ehdr)];
|
||||||
ssize_t n = fstat(fd, &st) == 0 && S_ISREG(st.st_mode) ? read(fd, head, sizeof head) : -1;
|
ssize_t n = fstat(fd, &st) == 0 && S_ISREG(st.st_mode) ? read(fd, head, sizeof head) : -1;
|
||||||
int kind = 0;
|
int kind = 0;
|
||||||
if (n >= 20 && !memcmp(head, ELFMAG, SELFMAG)) {
|
if (n >= 20 && !memcmp(head, ELFMAG, SELFMAG)) {
|
||||||
unsigned machine = head[EI_DATA] == ELFDATA2MSB ? (unsigned)head[18] << 8 | head[19] : head[18] | (unsigned)head[19] << 8;
|
unsigned machine = head[EI_DATA] == ELFDATA2MSB ? (unsigned)head[18] << 8 | head[19] : head[18] | (unsigned)head[19] << 8;
|
||||||
kind = machine == EM_X86_64 || machine == EM_386 || error == EACCES ? 1 : 0;
|
kind = machine == EM_X86_64 || machine == EM_386 || appimage(fd, head, n) || error == EACCES ? 1 : 0;
|
||||||
} else if (n >= 2 && head[0] == 'M' && head[1] == 'Z') {
|
} else if (n >= 2 && head[0] == 'M' && head[1] == 'Z') {
|
||||||
kind = 2;
|
kind = 2;
|
||||||
} else if (n >= 2 && head[0] == '#' && head[1] == '!' && error == EACCES) {
|
} else if (n >= 2 && head[0] == '#' && head[1] == '!' && error == EACCES) {
|
||||||
|
|||||||
@@ -138,6 +138,27 @@ class BinfmtPreloadTest(unittest.TestCase):
|
|||||||
program = self.file("arm64", bytes(arm64))
|
program = self.file("arm64", bytes(arm64))
|
||||||
self.assertEqual(self.run_program("execve", program), (3, "errno %d" % errno.ENOEXEC, None))
|
self.assertEqual(self.run_program("execve", program), (3, "errno %d" % errno.ENOEXEC, None))
|
||||||
|
|
||||||
|
def arm64_appimage(self, name, filesystem):
|
||||||
|
image = bytearray(128)
|
||||||
|
image[0:4], image[4], image[5], image[8:11], image[18] = b"\x7fELF", 2, 1, b"AI\x02", 183
|
||||||
|
image[0x28:0x30] = (64).to_bytes(8, "little")
|
||||||
|
image[0x3A:0x3C], image[0x3C:0x3E] = (32).to_bytes(2, "little"), (1).to_bytes(2, "little")
|
||||||
|
image[96:102] = filesystem
|
||||||
|
return self.file(name, bytes(image))
|
||||||
|
|
||||||
|
def test_an_arm64_appimage_goes_to_the_handler(self):
|
||||||
|
program = self.arm64_appimage("App.AppImage", b"hsqs\0\0")
|
||||||
|
for how in ("execve", "execvp"):
|
||||||
|
self.log.unlink(missing_ok=True)
|
||||||
|
target = program if how == "execve" else program.name
|
||||||
|
self.assertEqual(self.run_program(how, target, "--x"), (7, "", ["--exec", str(program), "--x"]))
|
||||||
|
self.log.unlink()
|
||||||
|
self.assertEqual(self.run_program("spawn", program, "y"), (0, "exit 7", ["--exec", str(program), "y"]))
|
||||||
|
|
||||||
|
def test_an_appimage_runtime_without_a_filesystem_keeps_its_error(self):
|
||||||
|
runtime = self.arm64_appimage("uruntime", bytes(6))
|
||||||
|
self.assertEqual(self.run_program("execve", runtime), (3, "errno %d" % errno.ENOEXEC, None))
|
||||||
|
|
||||||
def test_a_script_runs_as_itself(self):
|
def test_a_script_runs_as_itself(self):
|
||||||
script = self.file("script.sh", b"#!/bin/sh\nexit 5\n")
|
script = self.file("script.sh", b"#!/bin/sh\nexit 5\n")
|
||||||
self.assertEqual(self.run_program("execve", script), (5, "", None))
|
self.assertEqual(self.run_program("execve", script), (5, "", None))
|
||||||
|
|||||||
Reference in new issue
Block a user