From e239f3cee53c51e6f705552d4e7aa269152df0d7 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Wed, 4 Oct 2023 11:49:12 -0700 Subject: [PATCH] Fix import issues --- binharness/__init__.py | 22 +++++++++--------- binharness/common/__init__.py | 4 ++-- binharness/common/busybox.py | 13 +++++++++++ binharness/tests/test_executor.py | 2 +- binharness/tests/test_target_local.py | 3 ++- binharness/types/__init__.py | 32 ++++++++++++++++++++++----- binharness/types/executor.py | 13 ----------- 7 files changed, 54 insertions(+), 35 deletions(-) diff --git a/binharness/__init__.py b/binharness/__init__.py index 1e4f088..ea85184 100644 --- a/binharness/__init__.py +++ b/binharness/__init__.py @@ -3,36 +3,34 @@ __version__ = "0.1.0dev0" -from binharness.common.busybox import BusyboxInjection -from binharness.environment.localenvironment import LocalEnvironment +from binharness.common import BusyboxInjection +from binharness.environment import LocalEnvironment from binharness.serialize import TargetImportError, export_target, import_target -from binharness.types.environment import Environment -from binharness.types.executor import ( - BusyboxShellExecutor, +from binharness.types import ( + IO, + Environment, + ExecutableInjection, Executor, ExecutorEnvironmentMismatchError, ExecutorError, InjectableExecutor, - NullExecutor, -) -from binharness.types.injection import ( - ExecutableInjection, Injection, InjectionAlreadyInstalledError, InjectionError, InjectionNotInstalledError, + NullExecutor, + Process, + Target, ) -from binharness.types.process import Process -from binharness.types.target import Target __all__ = [ "BusyboxInjection", - "BusyboxShellExecutor", "Environment", "ExecutableInjection", "Executor", "ExecutorEnvironmentMismatchError", "ExecutorError", + "IO", "InjectableExecutor", "Injection", "InjectionAlreadyInstalledError", diff --git a/binharness/common/__init__.py b/binharness/common/__init__.py index 3b00c6d..d06feb2 100644 --- a/binharness/common/__init__.py +++ b/binharness/common/__init__.py @@ -1,7 +1,7 @@ """binharness.common - Common utility injections and executors for Binharness.""" from __future__ import annotations -from .busybox import BusyboxInjection -from .qemu import QemuInjection +from binharness.common.busybox import BusyboxInjection +from binharness.common.qemu import QemuInjection __all__ = ["BusyboxInjection", "QemuInjection"] diff --git a/binharness/common/busybox.py b/binharness/common/busybox.py index 4447c58..30f84d6 100644 --- a/binharness/common/busybox.py +++ b/binharness/common/busybox.py @@ -5,6 +5,7 @@ from pathlib import Path from typing import TYPE_CHECKING +from binharness.types import InjectableExecutor, Target from binharness.types.injection import ExecutableInjection if TYPE_CHECKING: @@ -69,3 +70,15 @@ def nc( if listen: return self.run("nc", "-lp", str(port)) return self.run("nc", host, str(port)) + + +class BusyboxShellExecutor(BusyboxInjection, InjectableExecutor): + """BusyboxShellExecutor is a Executor that runs the target in a busybox shell.""" + + def _run_target(self: BusyboxShellExecutor, target: Target) -> Process: + return self.run( + "sh", + "-c", + f"{target.main_binary} {' '.join(target.args)}", + env=target.env, + ) diff --git a/binharness/tests/test_executor.py b/binharness/tests/test_executor.py index 10daede..170386b 100644 --- a/binharness/tests/test_executor.py +++ b/binharness/tests/test_executor.py @@ -4,9 +4,9 @@ import pytest +from binharness.common.busybox import BusyboxShellExecutor from binharness.environment.localenvironment import LocalEnvironment from binharness.types.executor import ( - BusyboxShellExecutor, ExecutorEnvironmentMismatchError, ) from binharness.types.injection import InjectionNotInstalledError diff --git a/binharness/tests/test_target_local.py b/binharness/tests/test_target_local.py index bf528f5..cc8c9b0 100644 --- a/binharness/tests/test_target_local.py +++ b/binharness/tests/test_target_local.py @@ -3,7 +3,8 @@ from pathlib import Path from binharness import LocalEnvironment -from binharness.types.executor import BusyboxShellExecutor, NullExecutor +from binharness.common.busybox import BusyboxShellExecutor +from binharness.types.executor import NullExecutor from binharness.types.target import Target diff --git a/binharness/types/__init__.py b/binharness/types/__init__.py index 2d07de0..f418dba 100644 --- a/binharness/types/__init__.py +++ b/binharness/types/__init__.py @@ -1,18 +1,38 @@ """binharness.types - Type definitions for Binharness.""" from __future__ import annotations -from .environment import Environment -from .executor import Executor -from .injection import Injection -from .io import IO -from .process import Process -from .target import Target +from binharness.types.environment import Environment +from binharness.types.executor import ( + Executor, + ExecutorEnvironmentMismatchError, + ExecutorError, + InjectableExecutor, + NullExecutor, +) +from binharness.types.injection import ( + ExecutableInjection, + Injection, + InjectionAlreadyInstalledError, + InjectionError, + InjectionNotInstalledError, +) +from binharness.types.io import IO +from binharness.types.process import Process +from binharness.types.target import Target __all__ = [ "Environment", + "ExecutableInjection", "Executor", + "ExecutorEnvironmentMismatchError", + "ExecutorError", "IO", + "InjectableExecutor", "Injection", + "InjectionAlreadyInstalledError", + "InjectionError", + "InjectionNotInstalledError", + "NullExecutor", "Process", "Target", ] diff --git a/binharness/types/executor.py b/binharness/types/executor.py index 85b4d5d..f399cb8 100644 --- a/binharness/types/executor.py +++ b/binharness/types/executor.py @@ -4,7 +4,6 @@ from abc import ABC, abstractmethod from typing import TYPE_CHECKING -from binharness.common.busybox import BusyboxInjection from binharness.types.injection import ( Injection, InjectionNotInstalledError, @@ -58,15 +57,3 @@ def run_target(self: NullExecutor, target: Target) -> Process: *target.args, env=target.env, ) - - -class BusyboxShellExecutor(BusyboxInjection, InjectableExecutor): - """BusyboxShellExecutor is a Executor that runs the target in a busybox shell.""" - - def _run_target(self: BusyboxShellExecutor, target: Target) -> Process: - return self.run( - "sh", - "-c", - f"{target.main_binary} {' '.join(target.args)}", - env=target.env, - )