diff options
| -rw-r--r-- | dev/ZKA/Sources/ProcessScheduler.cxx | 4 | ||||
| -rw-r--r-- | tools/compile_flags.txt | 1 | ||||
| -rwxr-xr-x | tools/drvsign | bin | 0 -> 80424 bytes | |||
| -rw-r--r-- | tools/drvsign.cxx | 106 | ||||
| -rw-r--r-- | tools/drvsign.json | 6 |
5 files changed, 115 insertions, 2 deletions
diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx index 4186808e..db11b4e9 100644 --- a/dev/ZKA/Sources/ProcessScheduler.cxx +++ b/dev/ZKA/Sources/ProcessScheduler.cxx @@ -6,7 +6,7 @@ /***********************************************************************************/ /// @file ProcessScheduler.cxx -/// @brief MicroKernel process scheduler. +/// @brief User Process scheduler. /***********************************************************************************/ #include <KernelKit/ProcessScheduler.hxx> @@ -19,7 +19,7 @@ ///! BUGS: 0 /***********************************************************************************/ -/* This file handles the process scheduling. */ +/* TODO: Document more the kernel, sdk and kits. */ /***********************************************************************************/ namespace Kernel diff --git a/tools/compile_flags.txt b/tools/compile_flags.txt new file mode 100644 index 00000000..e23b2aef --- /dev/null +++ b/tools/compile_flags.txt @@ -0,0 +1 @@ +-std=c++20 diff --git a/tools/drvsign b/tools/drvsign Binary files differnew file mode 100755 index 00000000..093b4bc4 --- /dev/null +++ b/tools/drvsign diff --git a/tools/drvsign.cxx b/tools/drvsign.cxx new file mode 100644 index 00000000..28001208 --- /dev/null +++ b/tools/drvsign.cxx @@ -0,0 +1,106 @@ +/* + * Created on Thu Aug 22 09:29:13 CEST 2024 + * + * Copyright (c) 2024 ZKA Technologies + */ + +#include <cstdint> +#include <iostream> +#include <fstream> +#include <string> +#include <sstream> +#include <filesystem> + +#define kDriverSignedExt ".sigg" +#define kDriverExt ".sys" +#define kSignedDriverMagic "SIGG" + +namespace details +{ + struct SIGNED_DRIVER_HEADER final + { + // doesn't change. + char d_binary_magic[5]; + int d_binary_version; + // can change. + char d_binary_name[4096]; + std::uint64_t d_binary_checksum; + std::uint64_t d_binary_size; + char d_binary_padding[512]; + }; + + /***********************************************************************************/ + /* This handles the detection of a MZ header. */ + /***********************************************************************************/ + + bool drvsign_check_for_mz(std::string mz_blob) noexcept + { + return mz_blob[0] == 'M' && + mz_blob[1] == 'Z'; + } +} // namespace details + +/// @brief This program converts a PE32+ driver, into a custom format, the SIGG. +/// @note SIGG is used to tell that we're dealing with a ZKA driver. +int main(int argc, char* argv[]) +{ + for (size_t i = 1ul; i < argc; ++i) + { + if (strcmp(argv[i], "/?") == 0) + { + std::cout << "drvsign: ZKA Driver Signing Tool.\n"; + std::cout << "drvsign: © ZKA Technologies, all rights reserved.\n"; + + return 0; + } + } + + if (!std::filesystem::exists(argv[1]) || + !std::string(argv[1]).ends_with(kDriverExt)) + return -1; + + details::SIGNED_DRIVER_HEADER sig{0}; + + sig.d_binary_version = 1; + + memcpy(sig.d_binary_magic, kSignedDriverMagic, strlen(kSignedDriverMagic)); + memcpy(sig.d_binary_name, argv[1], strlen(argv[1])); + + sig.d_binary_size = std::filesystem::file_size(argv[1]); + + memset(sig.d_binary_padding, 0x00, 512); + + sig.d_binary_checksum = 0; + + std::string signed_path = argv[1]; + signed_path.erase(signed_path.find(kDriverExt), strlen(kDriverExt)); + signed_path += kDriverSignedExt; + + std::ofstream of_drv(signed_path, std::ios::binary); + std::ifstream if_drv(argv[1], std::ios::binary); + + std::stringstream ss; + ss << if_drv.rdbuf(); + + if (!details::drvsign_check_for_mz(ss.str())) + { + std::filesystem::remove(signed_path); + std::cout << "drvsign: Couldn't sign current driver, Input driver isn't a valid executable.\n"; + + return 1; + } + + for (auto ch : ss.str()) + { + sig.d_binary_checksum |= ch; + } + + sig.d_binary_checksum ^= sig.d_binary_size; + + of_drv.write((char*)&sig, sizeof(details::SIGNED_DRIVER_HEADER)); + of_drv.write(ss.str().c_str(), ss.str().size()); + + std::cout << "drvsign: Signing is done, quiting, here is the key: " << sig.d_binary_checksum << ".\n"; + + return 0; +} diff --git a/tools/drvsign.json b/tools/drvsign.json new file mode 100644 index 00000000..33bd4ea8 --- /dev/null +++ b/tools/drvsign.json @@ -0,0 +1,6 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "sources_path": ["drvsign.cxx"], + "output_name": "drvsign" +} |
