From 71cda91c42fa9d8564d47806714e056dff732b30 Mon Sep 17 00:00:00 2001 From: Netkas Date: Wed, 7 Dec 2022 22:53:18 -0500 Subject: [PATCH] Added PerlRunner https://git.n64.cc/nosial/ncc/-/issues/32 --- src/ncc/Classes/PerlExtension/PerlRunner.php | 53 ++++++++++++++++++++ src/ncc/Managers/ExecutionPointerManager.php | 3 ++ src/ncc/Utilities/Functions.php | 2 + 3 files changed, 58 insertions(+) create mode 100644 src/ncc/Classes/PerlExtension/PerlRunner.php diff --git a/src/ncc/Classes/PerlExtension/PerlRunner.php b/src/ncc/Classes/PerlExtension/PerlRunner.php new file mode 100644 index 0000000..0be4cdb --- /dev/null +++ b/src/ncc/Classes/PerlExtension/PerlRunner.php @@ -0,0 +1,53 @@ +Execute->Target = null; + if(!file_exists($path) && !is_file($path)) + throw new FileNotFoundException($path); + $execution_unit->ExecutionPolicy = $policy; + $execution_unit->Data = Base64::encode(IO::fread($path)); + + return $execution_unit; + } + + /** + * @inheritDoc + */ + public static function getFileExtension(): string + { + return '.pl'; + } + + /** + * @inheritDoc + */ + public static function prepareProcess(ExecutionPointer $pointer): Process + { + $perl_bin = PathFinder::findRunner(Runners::perl); + + if($pointer->ExecutionPolicy->Execute->Options !== null && count($pointer->ExecutionPolicy->Execute->Options) > 0) + return new Process(array_merge([$perl_bin, $pointer->FilePointer], $pointer->ExecutionPolicy->Execute->Options)); + return new Process([$perl_bin, $pointer->FilePointer]); + } + } \ No newline at end of file diff --git a/src/ncc/Managers/ExecutionPointerManager.php b/src/ncc/Managers/ExecutionPointerManager.php index 775b439..34192e6 100644 --- a/src/ncc/Managers/ExecutionPointerManager.php +++ b/src/ncc/Managers/ExecutionPointerManager.php @@ -8,6 +8,7 @@ use ncc\Abstracts\Runners; use ncc\Abstracts\Scopes; use ncc\Classes\BashExtension\BashRunner; + use ncc\Classes\PerlExtension\PerlRunner; use ncc\Classes\PhpExtension\PhpRunner; use ncc\Exceptions\AccessDeniedException; use ncc\Exceptions\ExecutionUnitNotFoundException; @@ -143,6 +144,7 @@ $bin_file .= match ($unit->ExecutionPolicy->Runner) { Runners::bash => BashRunner::getFileExtension(), Runners::php => PhpRunner::getFileExtension(), + Runners::perl => PerlRunner::getFileExtension(), default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'), }; @@ -276,6 +278,7 @@ { Runners::bash => BashRunner::prepareProcess($unit), Runners::php => PhpRunner::prepareProcess($unit), + Runners::perl => PerlRunner::prepareProcess($unit), default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'), }; diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index 5e196c8..294ac7a 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -6,6 +6,7 @@ use ncc\Abstracts\Runners; use ncc\Abstracts\Scopes; use ncc\Classes\BashExtension\BashRunner; + use ncc\Classes\PerlExtension\PerlRunner; use ncc\Classes\PhpExtension\PhpRunner; use ncc\Exceptions\AccessDeniedException; use ncc\Exceptions\FileNotFoundException; @@ -260,6 +261,7 @@ return match (strtolower($policy->Runner)) { Runners::bash => BashRunner::processUnit($path, $policy), Runners::php => PhpRunner::processUnit($path, $policy), + Runners::perl => PerlRunner::processUnit($path, $policy), default => throw new UnsupportedRunnerException('The runner \'' . $policy->Runner . '\' is not supported'), }; }