From d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:23:36 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- tools/common_zka.h | 7 +++++ tools/common_zka.hxx | 7 ----- tools/framework.h | 13 ++++++++ tools/framework.hxx | 13 -------- tools/src/make_framework.cc | 42 ++++++++++++++++++++++++++ tools/src/make_framework.cxx | 42 -------------------------- tools/src/make_zxd.cc | 72 ++++++++++++++++++++++++++++++++++++++++++++ tools/src/make_zxd.cxx | 72 -------------------------------------------- tools/zxd.h | 50 ++++++++++++++++++++++++++++++ tools/zxd.hxx | 50 ------------------------------ 10 files changed, 184 insertions(+), 184 deletions(-) create mode 100644 tools/common_zka.h delete mode 100644 tools/common_zka.hxx create mode 100644 tools/framework.h delete mode 100644 tools/framework.hxx create mode 100644 tools/src/make_framework.cc delete mode 100644 tools/src/make_framework.cxx create mode 100644 tools/src/make_zxd.cc delete mode 100644 tools/src/make_zxd.cxx create mode 100644 tools/zxd.h delete mode 100644 tools/zxd.hxx (limited to 'tools') diff --git a/tools/common_zka.h b/tools/common_zka.h new file mode 100644 index 00000000..3b7a1b19 --- /dev/null +++ b/tools/common_zka.h @@ -0,0 +1,7 @@ +#include +#include +#include +#include +#include +#include +#include diff --git a/tools/common_zka.hxx b/tools/common_zka.hxx deleted file mode 100644 index 3b7a1b19..00000000 --- a/tools/common_zka.hxx +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include diff --git a/tools/framework.h b/tools/framework.h new file mode 100644 index 00000000..3fae1307 --- /dev/null +++ b/tools/framework.h @@ -0,0 +1,13 @@ +/** + Thu Oct 17 07:57:43 CEST 2024 + (C) ZKA Web Services Co. +*/ + +#pragma once + +#include + +#define kFKDLLDirectory "ZKA/DLL/" +#define kFKManifestDirectory "ZKA/Manifests/" +#define kFKRootDirectory "ZKA/" +#define kFKExtension ".framework" diff --git a/tools/framework.hxx b/tools/framework.hxx deleted file mode 100644 index 416aa8b0..00000000 --- a/tools/framework.hxx +++ /dev/null @@ -1,13 +0,0 @@ -/** - Thu Oct 17 07:57:43 CEST 2024 - (C) ZKA Web Services Co. -*/ - -#pragma once - -#include - -#define kFKDLLDirectory "ZKA/DLL/" -#define kFKManifestDirectory "ZKA/Manifests/" -#define kFKRootDirectory "ZKA/" -#define kFKExtension ".framework" diff --git a/tools/src/make_framework.cc b/tools/src/make_framework.cc new file mode 100644 index 00000000..718a9ad1 --- /dev/null +++ b/tools/src/make_framework.cc @@ -0,0 +1,42 @@ +/* + * Created on Thu Oct 17 08:00:42 CEST 2024 + * + * Copyright (c) 2024 ZKA Web Services Co + */ + +#include +#include + +/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. +/// @note ZXD is a format for ZKA signed drivers. +int main(int argc, char* argv[]) +{ + for (size_t i = 1ul; i < argc; ++i) + { + if (strcmp(argv[i], "/?") == 0) + { + std::cout << "make_framework: Framework Tool.\n"; + std::cout << "make_framework: © ZKA Web Services Co, all rights reserved.\n"; + + return 0; + } + } + + auto path = std::string(argv[1]); + + if (!path.ends_with(kFKExtension)) + return 1; + + std::filesystem::path path_arg = path; + + if (std::filesystem::create_directory(path_arg)) + { + std::filesystem::create_directory(path_arg / kFKRootDirectory); + std::filesystem::create_directory(path_arg / kFKManifestDirectory); + std::filesystem::create_directory(path_arg / kFKDLLDirectory); + + return 0; + } + + return 1; +} diff --git a/tools/src/make_framework.cxx b/tools/src/make_framework.cxx deleted file mode 100644 index 2886b142..00000000 --- a/tools/src/make_framework.cxx +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Created on Thu Oct 17 08:00:42 CEST 2024 - * - * Copyright (c) 2024 ZKA Web Services Co - */ - -#include -#include - -/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. -/// @note ZXD is a format for ZKA signed drivers. -int main(int argc, char* argv[]) -{ - for (size_t i = 1ul; i < argc; ++i) - { - if (strcmp(argv[i], "/?") == 0) - { - std::cout << "make_framework: Framework Tool.\n"; - std::cout << "make_framework: © ZKA Web Services Co, all rights reserved.\n"; - - return 0; - } - } - - auto path = std::string(argv[1]); - - if (!path.ends_with(kFKExtension)) - return 1; - - std::filesystem::path path_arg = path; - - if (std::filesystem::create_directory(path_arg)) - { - std::filesystem::create_directory(path_arg / kFKRootDirectory); - std::filesystem::create_directory(path_arg / kFKManifestDirectory); - std::filesystem::create_directory(path_arg / kFKDLLDirectory); - - return 0; - } - - return 1; -} diff --git a/tools/src/make_zxd.cc b/tools/src/make_zxd.cc new file mode 100644 index 00000000..535b51db --- /dev/null +++ b/tools/src/make_zxd.cc @@ -0,0 +1,72 @@ +/* + * Created on Thu Aug 22 09:29:13 CEST 2024 + * + * Copyright (c) 2024 ZKA Web Services Co + */ + +#include + +/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. +/// @note ZXD is a format for ZKA signed drivers. +int main(int argc, char* argv[]) +{ + for (size_t i = 1ul; i < argc; ++i) + { + if (strcmp(argv[i], "/?") == 0) + { + std::cout << "make_zxd: ZXD Tool.\n"; + std::cout << "make_zxd: © ZKA Web Services Co, all rights reserved.\n"; + + return 0; + } + } + + if (!std::filesystem::exists(argv[1]) || + !std::string(argv[1]).ends_with(kDriverExt)) + return -1; + + ZXD::ZXD_HEADER zxd_hdr{0}; + + zxd_hdr.d_binary_version = 1; + + memcpy(zxd_hdr.d_binary_magic, kSignedDriverMagic, strlen(kSignedDriverMagic)); + memcpy(zxd_hdr.d_binary_name, argv[1], strlen(argv[1])); + + zxd_hdr.d_binary_size = std::filesystem::file_size(argv[1]); + + memset(zxd_hdr.d_binary_padding, 0x00, 512); + + zxd_hdr.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 (!ZXD::zxd_check_for_mz(ss.str())) + { + std::filesystem::remove(signed_path); + std::cout << "zxdmake: Couldn't sign current driver, Input driver isn't a valid executable.\n"; + + return 1; + } + + for (auto ch : ss.str()) + { + zxd_hdr.d_binary_checksum |= ch; + } + + zxd_hdr.d_binary_checksum ^= zxd_hdr.d_binary_size; + + of_drv.write((char*)&zxd_hdr, sizeof(ZXD::ZXD_HEADER)); + of_drv.write(ss.str().c_str(), ss.str().size()); + + std::cout << "zxdmake: Signing is done, quiting, Checksum: " << zxd_hdr.d_binary_checksum << ".\n"; + + return 0; +} diff --git a/tools/src/make_zxd.cxx b/tools/src/make_zxd.cxx deleted file mode 100644 index 94d01197..00000000 --- a/tools/src/make_zxd.cxx +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Created on Thu Aug 22 09:29:13 CEST 2024 - * - * Copyright (c) 2024 ZKA Web Services Co - */ - -#include - -/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. -/// @note ZXD is a format for ZKA signed drivers. -int main(int argc, char* argv[]) -{ - for (size_t i = 1ul; i < argc; ++i) - { - if (strcmp(argv[i], "/?") == 0) - { - std::cout << "make_zxd: ZXD Tool.\n"; - std::cout << "make_zxd: © ZKA Web Services Co, all rights reserved.\n"; - - return 0; - } - } - - if (!std::filesystem::exists(argv[1]) || - !std::string(argv[1]).ends_with(kDriverExt)) - return -1; - - ZXD::ZXD_HEADER zxd_hdr{0}; - - zxd_hdr.d_binary_version = 1; - - memcpy(zxd_hdr.d_binary_magic, kSignedDriverMagic, strlen(kSignedDriverMagic)); - memcpy(zxd_hdr.d_binary_name, argv[1], strlen(argv[1])); - - zxd_hdr.d_binary_size = std::filesystem::file_size(argv[1]); - - memset(zxd_hdr.d_binary_padding, 0x00, 512); - - zxd_hdr.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 (!ZXD::zxd_check_for_mz(ss.str())) - { - std::filesystem::remove(signed_path); - std::cout << "zxdmake: Couldn't sign current driver, Input driver isn't a valid executable.\n"; - - return 1; - } - - for (auto ch : ss.str()) - { - zxd_hdr.d_binary_checksum |= ch; - } - - zxd_hdr.d_binary_checksum ^= zxd_hdr.d_binary_size; - - of_drv.write((char*)&zxd_hdr, sizeof(ZXD::ZXD_HEADER)); - of_drv.write(ss.str().c_str(), ss.str().size()); - - std::cout << "zxdmake: Signing is done, quiting, Checksum: " << zxd_hdr.d_binary_checksum << ".\n"; - - return 0; -} diff --git a/tools/zxd.h b/tools/zxd.h new file mode 100644 index 00000000..07702595 --- /dev/null +++ b/tools/zxd.h @@ -0,0 +1,50 @@ +/* + * Created on Thu Aug 22 09:29:13 CEST 2024 + * + * Copyright (c) 2024 ZKA Web Services Co + */ + +#pragma once + +#include + +#define kDriverSignedExt ".zxd" +#define kDriverExt ".sys" +#define kSignedDriverMagic " ZXD" + +#define cZXDPaddingSize (512) +#define cZXDMagicSize (5) + +namespace ZXD +{ + /// + /// ZXD header. + /// + struct ZXD_HEADER final + { + char d_binary_padding[cZXDPaddingSize]; + // doesn't change. + char d_binary_magic[cZXDMagicSize]; + std::int32_t d_binary_version; + // can change. + char d_binary_name[4096]; + std::uint64_t d_binary_checksum; + std::uint64_t d_binary_size; + }; + + /***********************************************************************************/ + /* @brief These two handles the detection of a MZ header. */ + /***********************************************************************************/ + + inline bool zxd_check_for_mz(const char* mz_blob) noexcept + { + return mz_blob[0] == 'M' && + mz_blob[1] == 'Z'; + } + + inline bool zxd_check_for_mz(std::string mz_blob) noexcept + { + return mz_blob[0] == 'M' && + mz_blob[1] == 'Z'; + } +} // namespace ZXD diff --git a/tools/zxd.hxx b/tools/zxd.hxx deleted file mode 100644 index bec145d8..00000000 --- a/tools/zxd.hxx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Created on Thu Aug 22 09:29:13 CEST 2024 - * - * Copyright (c) 2024 ZKA Web Services Co - */ - -#pragma once - -#include - -#define kDriverSignedExt ".zxd" -#define kDriverExt ".sys" -#define kSignedDriverMagic " ZXD" - -#define cZXDPaddingSize (512) -#define cZXDMagicSize (5) - -namespace ZXD -{ - /// - /// ZXD header. - /// - struct ZXD_HEADER final - { - char d_binary_padding[cZXDPaddingSize]; - // doesn't change. - char d_binary_magic[cZXDMagicSize]; - std::int32_t d_binary_version; - // can change. - char d_binary_name[4096]; - std::uint64_t d_binary_checksum; - std::uint64_t d_binary_size; - }; - - /***********************************************************************************/ - /* @brief These two handles the detection of a MZ header. */ - /***********************************************************************************/ - - inline bool zxd_check_for_mz(const char* mz_blob) noexcept - { - return mz_blob[0] == 'M' && - mz_blob[1] == 'Z'; - } - - inline bool zxd_check_for_mz(std::string mz_blob) noexcept - { - return mz_blob[0] == 'M' && - mz_blob[1] == 'Z'; - } -} // namespace ZXD -- cgit v1.2.3