mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(native): programs started through the rootfs loader show their own command line (#3055)
* fix(native): programs started through the rootfs loader show their own command line Without proot every dynamic guest program runs as "ld.so --preload <hook> --library-path <dirs> --argv0 <name> <program> <args>", and the kernel's /proc/<pid>/cmdline kept all of it. Launchers and the session match programs by their command line, and Wine only moves its Windows command line over its loader's name when its arguments follow each other, so the Battle.net launcher never saw Battle.net.exe, gave up after five minutes and ended the session with the game still running. The hook now moves the program's own arguments to the front of that area at start, as an exec of the program would have laid them out. * fix(native): programs the app starts natively keep their path for /proc/<pid>/exe * fix(native): the rewritten command line keeps AT_EXECFN naming the program --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
3c4ac03656
commit
1772291da7
8 files changed
+335
-31
No files matched your search
@@ -74,8 +74,8 @@ class NativeHookProcExeTest(unittest.TestCase):
|
||||
shutil.copy(shutil.which(cls.prefix[0]), cls.loader)
|
||||
cls.loader_args = list(cls.prefix[1:])
|
||||
else:
|
||||
ld = next(p for p in ("/lib/ld-linux-aarch64.so.1", "/lib64/ld-linux-aarch64.so.1") if os.path.exists(p))
|
||||
shutil.copy(ld, cls.loader)
|
||||
cls.ld_so = next(p for p in ("/lib/ld-linux-aarch64.so.1", "/lib64/ld-linux-aarch64.so.1") if os.path.exists(p))
|
||||
shutil.copy(cls.ld_so, cls.loader)
|
||||
cls.loader_args = []
|
||||
|
||||
@classmethod
|
||||
@@ -83,11 +83,13 @@ class NativeHookProcExeTest(unittest.TestCase):
|
||||
cls.tmp.cleanup()
|
||||
|
||||
def start(self, loader, real_exe=None, program=None):
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("LD_PRELOAD", "DDNATV_REAL_EXE")}
|
||||
if real_exe:
|
||||
env["DDNATV_REAL_EXE"] = real_exe
|
||||
program = program or Path(self.tmp.name) / "sleeper"
|
||||
cmd = ([str(self.loader), *self.loader_args] if loader else list(self.prefix)) + [str(program)]
|
||||
return self.spawn(cmd, {"DDNATV_REAL_EXE": real_exe} if real_exe else {})
|
||||
|
||||
def spawn(self, cmd, extra_env):
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("LD_PRELOAD", "DDNATV_ROOT", "DDNATV_REAL_EXE")}
|
||||
env.update(extra_env)
|
||||
child = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, text=True)
|
||||
self.addCleanup(child.stdout.close)
|
||||
self.addCleanup(child.wait)
|
||||
@@ -141,6 +143,14 @@ class NativeHookProcExeTest(unittest.TestCase):
|
||||
link = f"/proc/{pid}/exe"
|
||||
self.assertEqual(os.readlink(link), self.readlink(link)[link])
|
||||
|
||||
@unittest.skipIf(runner()[1], "qemu answers /proc/self/cmdline from its own copy of the arguments")
|
||||
def test_a_program_whose_hook_moved_its_arguments_is_still_named(self):
|
||||
cmd = [self.ld_so, "--preload", str(self.hook), "--argv0", self.kwin.name, str(self.kwin)]
|
||||
pid = self.spawn(cmd, {"DDNATV_ROOT": str(self.root), "DDNATV_REAL_EXE": str(self.kwin)})
|
||||
self.assertEqual(b"kwin_wayland", Path(f"/proc/{pid}/cmdline").read_bytes().rstrip(b"\0"))
|
||||
link = f"/proc/{pid}/exe"
|
||||
self.assertEqual("/usr/bin/kwin_wayland", self.readlink(link)[link])
|
||||
|
||||
def test_a_loader_without_a_known_program_keeps_the_kernel_link(self):
|
||||
pid = self.start(loader=True)
|
||||
link = f"/proc/{pid}/exe"
|
||||
|
||||
Reference in new issue
Block a user