From 486a9cf8165e3c558f35abdf58afed649f33af54 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 19 Jan 2024 12:24:22 -0700 Subject: [PATCH 1/6] Fix default injection path --- python/binharness/types/injection.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/binharness/types/injection.py b/python/binharness/types/injection.py index b8b5533..dba5be0 100644 --- a/python/binharness/types/injection.py +++ b/python/binharness/types/injection.py @@ -51,9 +51,7 @@ def install(self: Injection, environment: Environment) -> None: f"{self.host_path.name}-{generate_random_suffix()}.bh-inj" ) - environment.inject_files( - [(self.host_path, self.env_path / self.host_path.name)] - ) + environment.inject_files([(self.host_path, self.env_path)]) self._environment = environment def is_installed(self: Injection) -> bool: From 5737eb33c05bea0202e6a35ca3b7a710f773f44d Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 19 Jan 2024 12:51:52 -0700 Subject: [PATCH 2/6] Fix test_inject.py --- python/tests/test_inject.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/tests/test_inject.py b/python/tests/test_inject.py index a0e4e6c..f126d6e 100644 --- a/python/tests/test_inject.py +++ b/python/tests/test_inject.py @@ -19,7 +19,7 @@ def test_inject_true() -> None: true_injection = Injection(Path("/usr/bin/true"), None) true_injection.install(env) assert true_injection.env_path is not None - assert (true_injection.env_path / "true").is_file() + assert true_injection.env_path.is_file() @pytest.mark.linux() @@ -28,8 +28,7 @@ def test_inject_true_executable() -> None: true_injection = ExecutableInjection(Path("true"), Path("/usr/bin/true")) true_injection.install(env) assert true_injection.env_path is not None - assert true_injection.env_path.is_dir() - assert (true_injection.env_path / "true").is_file() + assert true_injection.env_path.is_file() assert true_injection.is_installed() assert true_injection.env_path.stat().st_mode & 0o111 != 0 assert true_injection.run().wait() == 0 From bccd03d5b78d2029a32b0cf4cc4742688ca69369 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 19 Jan 2024 12:53:10 -0700 Subject: [PATCH 3/6] Whoops --- python/binharness/types/injection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/binharness/types/injection.py b/python/binharness/types/injection.py index dba5be0..f346977 100644 --- a/python/binharness/types/injection.py +++ b/python/binharness/types/injection.py @@ -96,7 +96,7 @@ def run( if self._environment is None or self.env_path is None: raise InjectionNotInstalledError return self._environment.run_command( - [self.env_path / self.executable, *args], + [self.env_path, *args], env=env, cwd=cwd, ) From 9a01c1f43017b38e566135a4e993253b3952a680 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 19 Jan 2024 16:30:28 -0700 Subject: [PATCH 4/6] Clean up executable injection --- python/binharness/types/injection.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/binharness/types/injection.py b/python/binharness/types/injection.py index f346977..49ab9c8 100644 --- a/python/binharness/types/injection.py +++ b/python/binharness/types/injection.py @@ -74,17 +74,26 @@ class ExecutableInjection(Injection): environment. """ - executable: Path + _executable: Path | None def __init__( self: ExecutableInjection, - executable: Path, host_path: Path, env_path: Path | None = None, + executable: Path | None = None, ) -> None: """Create an ExecutableInjection.""" super().__init__(host_path, env_path) - self.executable = executable + self._executable = executable + + @property + def executable(self: ExecutableInjection) -> Path: + """Return the executable path.""" + if self.host_path is not None: + if self._executable is None: + return self.host_path + return self.host_path / self._executable + raise InjectionNotInstalledError def run( self: ExecutableInjection, @@ -96,7 +105,7 @@ def run( if self._environment is None or self.env_path is None: raise InjectionNotInstalledError return self._environment.run_command( - [self.env_path, *args], + [self.executable, *args], env=env, cwd=cwd, ) From 7b68e9fac4afc9fa8446eff7fef15ae19d2ef9e1 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 19 Jan 2024 16:48:18 -0700 Subject: [PATCH 5/6] Fix more issues --- python/binharness/common/busybox.py | 2 +- python/binharness/common/qemu.py | 4 +--- python/tests/test_inject.py | 12 ++++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/python/binharness/common/busybox.py b/python/binharness/common/busybox.py index 03d3ced..62da2a1 100644 --- a/python/binharness/common/busybox.py +++ b/python/binharness/common/busybox.py @@ -23,7 +23,7 @@ class BusyboxInjection(ExecutableInjection): def __init__(self: BusyboxInjection) -> None: """Create a BusyboxInjection.""" - super().__init__(Path("busybox"), self.BUSYBOX_PATH, None) + super().__init__(self.BUSYBOX_PATH) def install(self: BusyboxInjection, environment: Environment) -> None: """Install the injection into an environment.""" diff --git a/python/binharness/common/qemu.py b/python/binharness/common/qemu.py index 266e1c1..40afb51 100644 --- a/python/binharness/common/qemu.py +++ b/python/binharness/common/qemu.py @@ -31,9 +31,7 @@ class QemuInjection(ExecutableInjection): def __init__(self: QemuInjection, arch: str | None = None) -> None: """Create a QemuInjection.""" self.arch = arch if arch is not None else _get_qemu_host_arch() - super().__init__( - Path(f"qemu-{self.arch}-static"), Path(f"/usr/bin/qemu-{self.arch}-static") - ) + super().__init__(Path(Path(f"/usr/bin/qemu-{self.arch}-static"))) def run_with_log( self: QemuInjection, diff --git a/python/tests/test_inject.py b/python/tests/test_inject.py index f126d6e..fe896b6 100644 --- a/python/tests/test_inject.py +++ b/python/tests/test_inject.py @@ -16,7 +16,7 @@ @pytest.mark.linux() def test_inject_true() -> None: env = LocalEnvironment() - true_injection = Injection(Path("/usr/bin/true"), None) + true_injection = Injection(Path("/usr/bin/true")) true_injection.install(env) assert true_injection.env_path is not None assert true_injection.env_path.is_file() @@ -25,7 +25,7 @@ def test_inject_true() -> None: @pytest.mark.linux() def test_inject_true_executable() -> None: env = LocalEnvironment() - true_injection = ExecutableInjection(Path("true"), Path("/usr/bin/true")) + true_injection = ExecutableInjection(Path("/usr/bin/true")) true_injection.install(env) assert true_injection.env_path is not None assert true_injection.env_path.is_file() @@ -37,7 +37,7 @@ def test_inject_true_executable() -> None: @pytest.mark.linux() def test_inject_true_executable_twice() -> None: env = LocalEnvironment() - true_injection = ExecutableInjection(Path("true"), Path("/usr/bin/true")) + true_injection = ExecutableInjection(Path("/usr/bin/true")) true_injection.install(env) with pytest.raises(InjectionAlreadyInstalledError): true_injection.install(env) @@ -46,13 +46,13 @@ def test_inject_true_executable_twice() -> None: @pytest.mark.linux() def test_inject_two_true_executables() -> None: env = LocalEnvironment() - true_injection_1 = ExecutableInjection(Path("true"), Path("/usr/bin/true")) + true_injection_1 = ExecutableInjection(Path("/usr/bin/true")) true_injection_1.install(env) - true_injection_2 = ExecutableInjection(Path("true"), Path("/usr/bin/true")) + true_injection_2 = ExecutableInjection(Path("/usr/bin/true")) true_injection_2.install(env) def test_executable_injection_no_install() -> None: - true_injection = ExecutableInjection(Path("true"), Path("/usr/bin/true")) + true_injection = ExecutableInjection(Path("/usr/bin/true")) with pytest.raises(InjectionNotInstalledError): true_injection.run() From eb46f5e27c91aabeefe40ba74b72fc62a8c6b2ac Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 19 Jan 2024 16:57:47 -0700 Subject: [PATCH 6/6] Fix double path in qemu injection --- python/binharness/common/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/binharness/common/qemu.py b/python/binharness/common/qemu.py index 40afb51..e09cf82 100644 --- a/python/binharness/common/qemu.py +++ b/python/binharness/common/qemu.py @@ -31,7 +31,7 @@ class QemuInjection(ExecutableInjection): def __init__(self: QemuInjection, arch: str | None = None) -> None: """Create a QemuInjection.""" self.arch = arch if arch is not None else _get_qemu_host_arch() - super().__init__(Path(Path(f"/usr/bin/qemu-{self.arch}-static"))) + super().__init__(Path(f"/usr/bin/qemu-{self.arch}-static")) def run_with_log( self: QemuInjection,