summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/CFKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-18 21:39:29 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-18 21:39:29 +0200
commitda70596895d8135e08f8caac6978117697b4c021 (patch)
tree2516785b5434df8453687f05dc8dd877438901ab /dev/ZKA/CFKit
parent005de79004c9d30e64bdee6e14e06f9d47d1f2ab (diff)
[REFACTOR]
Improved project structure. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/CFKit')
-rw-r--r--dev/ZKA/CFKit/GUIDWizard.hxx22
-rw-r--r--dev/ZKA/CFKit/GUIDWrapper.hxx58
-rw-r--r--dev/ZKA/CFKit/LoaderUtils.hxx54
-rw-r--r--dev/ZKA/CFKit/Property.hxx47
-rw-r--r--dev/ZKA/CFKit/URL.hxx33
-rw-r--r--dev/ZKA/CFKit/compile_flags.txt5
6 files changed, 219 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..3edacc67
--- /dev/null
+++ b/dev/ZKA/CFKit/LoaderUtils.hxx
@@ -0,0 +1,54 @@
+#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) -> ExecHeaderPtr
+ {
+ if (!ptrDos)
+ return nullptr;
+
+ if (ptrDos->eMagic[0] != kMagMz0)
+ return nullptr;
+
+ if (ptrDos->eMagic[1] != kMagMz1)
+ return nullptr;
+
+ return (ExecHeaderPtr)(VoidPtr)(&ptrDos->eLfanew + 1);
+ }
+
+ /// @brief Find the PE optional header inside the blob.
+ inline auto ldr_find_opt_exec_header(DosHeaderPtr ptrDos) -> ExecOptionalHeaderPtr
+ {
+ if (!ptrDos)
+ return nullptr;
+
+ auto exec = ldr_find_exec_header(ptrDos);
+
+ if (!exec)
+ return nullptr;
+
+ return (ExecOptionalHeaderPtr)(VoidPtr)(&exec->mCharacteristics + 1);
+ }
+
+ /// @brief Find the PE header inside the blob.
+ /// @note overloaded function.
+ inline auto ldr_find_exec_header(const Char* ptrDos) -> ExecHeaderPtr
+ {
+ 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) -> ExecOptionalHeaderPtr
+ {
+ 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..602c061f
--- /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_ */
diff --git a/dev/ZKA/CFKit/compile_flags.txt b/dev/ZKA/CFKit/compile_flags.txt
new file mode 100644
index 00000000..a37ae6bf
--- /dev/null
+++ b/dev/ZKA/CFKit/compile_flags.txt
@@ -0,0 +1,5 @@
+-nostdlib
+-ffreestanding
+-std=c++20
+-I./
+-I../