diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-22 17:46:11 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-22 17:46:11 +0200 |
| commit | 8719b4570a2d10dd49a0d3a47e24f5c55bdda85e (patch) | |
| tree | ba095740888f3768e08b2ea058b0ea6da2d0403d /dev/zka/CFKit | |
| parent | 45944b3d2dab04b763fcc6d10164fe8069e60b08 (diff) | |
:boom: A big refactor on the filesystem structure.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/zka/CFKit')
| -rw-r--r-- | dev/zka/CFKit/GUIDWizard.hxx | 22 | ||||
| -rw-r--r-- | dev/zka/CFKit/GUIDWrapper.hxx | 58 | ||||
| -rw-r--r-- | dev/zka/CFKit/LoaderUtils.hxx | 53 | ||||
| -rw-r--r-- | dev/zka/CFKit/Property.hxx | 47 | ||||
| -rw-r--r-- | dev/zka/CFKit/URL.hxx | 33 |
5 files changed, 213 insertions, 0 deletions
diff --git a/dev/zka/CFKit/GUIDWizard.hxx b/dev/zka/CFKit/GUIDWizard.hxx new file mode 100644 index 00000000..034aceea --- /dev/null +++ b/dev/zka/CFKit/GUIDWizard.hxx @@ -0,0 +1,22 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <CFKit/GUIDWrapper.hxx> +#include <NewKit/Array.hxx> +#include <NewKit/ArrayList.hxx> +#include <NewKit/Defines.hxx> +#include <NewKit/ErrorOr.hxx> +#include <NewKit/Ref.hxx> +#include <NewKit/Stream.hxx> +#include <NewKit/String.hxx> + +namespace Kernel::XRN::Version1 +{ + Ref<GUIDSequence*> cf_make_sequence(const ArrayList<UInt32>& seq); + ErrorOr<Ref<Kernel::StringView>> cf_try_guid_to_string(Ref<GUIDSequence*>& guid); +} // namespace Kernel::XRN::Version1 diff --git a/dev/zka/CFKit/GUIDWrapper.hxx b/dev/zka/CFKit/GUIDWrapper.hxx new file mode 100644 index 00000000..8810f303 --- /dev/null +++ b/dev/zka/CFKit/GUIDWrapper.hxx @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.hxx> +#include <NewKit/Ref.hxx> +#include <NewKit/Stream.hxx> + +/* GUID for C++ Components */ + +#define kXRNNil "@{........-....-M...-N...-............}" + +// eXtensible Resource Information +namespace Kernel::XRN +{ + union GUIDSequence { + alignas(8) UShort u8[16]; + alignas(8) UShort u16[8]; + alignas(8) UInt u32[4]; + alignas(8) ULong u64[2]; + + struct + { + alignas(8) UInt fMs1; + UShort fMs2; + UShort fMs3; + UChar fMs4[8]; + }; + }; + + class GUID final + { + public: + explicit GUID() = default; + ~GUID() = default; + + public: + GUID& operator=(const GUID&) = default; + GUID(const GUID&) = default; + + public: + GUIDSequence& operator->() noexcept + { + return fUUID; + } + GUIDSequence& Leak() noexcept + { + return fUUID; + } + + private: + GUIDSequence fUUID; + }; +} // namespace Kernel::XRN diff --git a/dev/zka/CFKit/LoaderUtils.hxx b/dev/zka/CFKit/LoaderUtils.hxx new file mode 100644 index 00000000..7385fc2e --- /dev/null +++ b/dev/zka/CFKit/LoaderUtils.hxx @@ -0,0 +1,53 @@ +#ifndef __CFKIT_LOADER_UTILS_HXX__ +#define __CFKIT_LOADER_UTILS_HXX__ + +#include <KernelKit/PE.hxx> +#include <KernelKit/MSDOS.hxx> + +namespace Kernel +{ + /// @brief Find the PE header inside the blob. + inline auto ldr_find_exec_header(DosHeaderPtr ptrDos) -> LDR_EXEC_HEADER_PTR + { + if (!ptrDos) + return nullptr; + + if (ptrDos->eMagic[0] != kMagMz0) + return nullptr; + + if (ptrDos->eMagic[1] != kMagMz1) + return nullptr; + + return (LDR_EXEC_HEADER_PTR)(VoidPtr)(&ptrDos->eLfanew + 1); + } + + /// @brief Find the PE optional header inside the blob. + inline auto ldr_find_opt_exec_header(DosHeaderPtr ptrDos) -> LDR_OPTIONAL_HEADER_PTR + { + if (!ptrDos) + return nullptr; + + auto exec = ldr_find_exec_header(ptrDos); + + if (!exec) + return nullptr; + + return (LDR_OPTIONAL_HEADER_PTR)(VoidPtr)(&exec->mCharacteristics + 1); + } + + /// @brief Find the PE header inside the blob. + /// @note overloaded function. + inline auto ldr_find_exec_header(const Char* ptrDos) -> LDR_EXEC_HEADER_PTR + { + return ldr_find_exec_header((DosHeaderPtr)ptrDos); + } + + /// @brief Find the PE header inside the blob. + /// @note overloaded function. + inline auto ldr_find_opt_exec_header(const Char* ptrDos) -> LDR_OPTIONAL_HEADER_PTR + { + return ldr_find_opt_exec_header((DosHeaderPtr)ptrDos); + } +} // namespace Kernel + +#endif // ifndef __CFKIT_LOADER_UTILS_HXX__ diff --git a/dev/zka/CFKit/Property.hxx b/dev/zka/CFKit/Property.hxx new file mode 100644 index 00000000..eb9b4816 --- /dev/null +++ b/dev/zka/CFKit/Property.hxx @@ -0,0 +1,47 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __INC_PROPS_HPP__ +#define __INC_PROPS_HPP__ + +#include <NewKit/Array.hxx> +#include <NewKit/Defines.hxx> +#include <NewKit/Function.hxx> +#include <NewKit/String.hxx> + +#define cMaxPropLen 4096 + +namespace Kernel +{ + /// @brief handle to anything (number, ptr, string...) + using PropertyId = UIntPtr; + + /// @brief Kernel property class. + /// @example \Properties\SmpCores or \Properties\KernelVersion + class Property + { + public: + Property() = default; + virtual ~Property(); + + public: + Property& operator=(const Property&) = default; + Property(const Property&) = default; + + bool StringEquals(StringView& name); + PropertyId& GetValue(); + StringView& GetKey(); + + private: + StringView fName{cMaxPropLen}; + PropertyId fAction{No}; + }; + + template <SizeT N> + using PropertyArray = Array<Property, N>; +} // namespace Kernel + +#endif // !__INC_PROPS_HPP__ diff --git a/dev/zka/CFKit/URL.hxx b/dev/zka/CFKit/URL.hxx new file mode 100644 index 00000000..02cced28 --- /dev/null +++ b/dev/zka/CFKit/URL.hxx @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef _INC_URL_HPP_ +#define _INC_URL_HPP_ + +#include <NewKit/Defines.hxx> +#include <NewKit/String.hxx> + +namespace Kernel +{ + class URL final + { + public: + explicit URL(StringView& strUrl); + ~URL(); + + public: + Ref<ErrorOr<StringView>> Location() noexcept; + Ref<ErrorOr<StringView>> Protocol() noexcept; + + private: + Ref<StringView> fUrlView; + }; + + ErrorOr<StringView> url_extract_location(const Char* url); + ErrorOr<StringView> url_extract_protocol(const Char* url); +} // namespace Kernel + +#endif /* ifndef _INC_URL_HPP_ */ |
