diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2025-01-24 10:38:36 +0100 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2025-01-24 10:38:36 +0100 |
| commit | 7b4bd3577a31d0f0adc7371840642791ae1567f4 (patch) | |
| tree | 1a8afc973aaa739d0d763315cad2fd376d1cea9c /public/tools/open/src/CommandLine.cc | |
ADD: Open version, with important changes kept out.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'public/tools/open/src/CommandLine.cc')
| -rw-r--r-- | public/tools/open/src/CommandLine.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/public/tools/open/src/CommandLine.cc b/public/tools/open/src/CommandLine.cc new file mode 100644 index 00000000..86282059 --- /dev/null +++ b/public/tools/open/src/CommandLine.cc @@ -0,0 +1,49 @@ +/* + * Created on Thu Oct 17 08:00:42 CEST 2024 + * + * Copyright (c) 2024 Amlal EL Mahrouss + */ + +#include <LibSCI/SCI.h> + +/// @brief This program opens an application from **OPEN_APP_BASE_PATH** + +#define OPEN_APP_APP_FLAG "-a" +#define OPEN_APP_HELP_FLAG "-h" +#define OPEN_APP_BASE_PATH "/app/" + +int main(int argc, char* argv[]) +{ + if (argc == 1) + return EXIT_FAILURE; + + for (SizeT i = 1UL; i < argc; ++i) + { + if (MmStrCmp(argv[i], OPEN_APP_HELP_FLAG) == 0) + { + ConOut(nullptr, "open: Open Tool.\n"); + ConOut(nullptr, "open: © Amlal EL Mahrouss, All rights reserved.\n"); + + ConOut(nullptr, "open: %s: Application is taken as input (opens a PEF/PE32+/ELF program depending on architecture).\n", OPEN_APP_APP_FLAG); + + return EXIT_SUCCESS; + } + else if (MmStrCmp(argv[i], OPEN_APP_APP_FLAG) == 0) + { + if ((i + 1) == argc) + return EXIT_FAILURE; + + Char base_path[FILE_MAX_LEN] = OPEN_APP_BASE_PATH; + MmCopyMemory(base_path + MmStrLen(OPEN_APP_BASE_PATH), argv[i + 1], MmStrLen(argv[i + 1])); + + Bool ret = RtlSpawnProcess(base_path, 0, nullptr, nullptr, 0); + + if (ret > 0) + return EXIT_SUCCESS; + + break; + } + } + + return EXIT_FAILURE; +} |
