Skip to content

Commit

Permalink
Fix import issues
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Oct 4, 2023
1 parent e12537d commit e239f3c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 35 deletions.
22 changes: 10 additions & 12 deletions binharness/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions binharness/common/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 13 additions & 0 deletions binharness/common/busybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion binharness/tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion binharness/tests/test_target_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
32 changes: 26 additions & 6 deletions binharness/types/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
13 changes: 0 additions & 13 deletions binharness/types/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)

0 comments on commit e239f3c

Please sign in to comment.