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 /dev/Kernel/CFKit | |
ADD: Open version, with important changes kept out.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/CFKit')
| -rw-r--r-- | dev/Kernel/CFKit/GUIDWizard.h | 24 | ||||
| -rw-r--r-- | dev/Kernel/CFKit/GUIDWrapper.h | 60 | ||||
| -rw-r--r-- | dev/Kernel/CFKit/Property.h | 54 | ||||
| -rw-r--r-- | dev/Kernel/CFKit/Utils.h | 55 |
4 files changed, 193 insertions, 0 deletions
diff --git a/dev/Kernel/CFKit/GUIDWizard.h b/dev/Kernel/CFKit/GUIDWizard.h new file mode 100644 index 00000000..0a652310 --- /dev/null +++ b/dev/Kernel/CFKit/GUIDWizard.h @@ -0,0 +1,24 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <CFKit/GUIDWrapper.h> +#include <NewKit/Array.h> +#include <NewKit/ArrayList.h> +#include <NewKit/Defines.h> +#include <NewKit/ErrorOr.h> +#include <NewKit/Ref.h> +#include <NewKit/Stream.h> +#include <NewKit/KString.h> + +namespace CFKit::XRN::Version1 +{ + using namespace Kernel; + + Ref<GUIDSequence*> cf_make_sequence(const ArrayList<UInt32>& seq); + ErrorOr<Ref<Kernel::KString>> cf_try_guid_to_string(Ref<GUIDSequence*>& guid); +} // namespace CFKit::XRN::Version1 diff --git a/dev/Kernel/CFKit/GUIDWrapper.h b/dev/Kernel/CFKit/GUIDWrapper.h new file mode 100644 index 00000000..e69aa82a --- /dev/null +++ b/dev/Kernel/CFKit/GUIDWrapper.h @@ -0,0 +1,60 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.h> +#include <NewKit/Ref.h> +#include <NewKit/Stream.h> + +/* GUID for C++ Components */ + +#define kXRNNil "@{........-....-M...-N...-............}" + +// eXtensible Resource Information +namespace CFKit::XRN +{ + using namespace Kernel; + + 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 CFKit::XRN diff --git a/dev/Kernel/CFKit/Property.h b/dev/Kernel/CFKit/Property.h new file mode 100644 index 00000000..162b757b --- /dev/null +++ b/dev/Kernel/CFKit/Property.h @@ -0,0 +1,54 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef CFKIT_PROPS_H +#define CFKIT_PROPS_H + +#include <NewKit/Array.h> +#include <NewKit/Defines.h> +#include <NewKit/Function.h> +#include <NewKit/KString.h> + +#define kMaxPropLen 255 + +namespace CFKit +{ + using 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(); + virtual ~Property(); + + public: + Property& operator=(const Property&) = default; + Property(const Property&) = default; + + bool StringEquals(KString& name); + PropertyId& GetValue(); + KString& GetKey(); + + private: + KString fName{kMaxPropLen}; + PropertyId fValue{0UL}; + }; + + template <SizeT N> + using PropertyArray = Array<Property, N>; +} // namespace CFKit + +namespace Kernel +{ + using namespace CFKit; +} + +#endif // !CFKIT_PROPS_H diff --git a/dev/Kernel/CFKit/Utils.h b/dev/Kernel/CFKit/Utils.h new file mode 100644 index 00000000..370eca45 --- /dev/null +++ b/dev/Kernel/CFKit/Utils.h @@ -0,0 +1,55 @@ +#ifndef CFKIT_UTILS_H +#define CFKIT_UTILS_H + +#include <KernelKit/PE.h> +#include <KernelKit/MSDOS.h> + +namespace CFKit +{ + using namespace Kernel; + + /// @brief Finds 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 Finds 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 Finds 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 Finds 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 CFKit + +#endif // ifndef CFKIT_UTILS_H |
