From 83d870e58457a1d335a1d9b9966a6a1887cc297b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 03:02:43 +0100 Subject: feat! breaking changes on kernel sources. Signed-off-by: Amlal El Mahrouss --- src/kernel/KernelKit/IPEFDylibObject.h | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/kernel/KernelKit/IPEFDylibObject.h (limited to 'src/kernel/KernelKit/IPEFDylibObject.h') diff --git a/src/kernel/KernelKit/IPEFDylibObject.h b/src/kernel/KernelKit/IPEFDylibObject.h new file mode 100644 index 00000000..17ef02d5 --- /dev/null +++ b/src/kernel/KernelKit/IPEFDylibObject.h @@ -0,0 +1,86 @@ +/* + * ======================================================== + * + * Kernel + * Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + * + * ======================================================== + */ + +#ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ +#define __KERNELKIT_PEF_SHARED_OBJECT_H__ + +#include +#include +#include +#include +#include + +namespace Kernel { +/** + * @brief Shared Library class + * Load library from this class + */ +class IPEFDylibObject final NE_DYLIB_OBJECT { + public: + explicit IPEFDylibObject() = default; + ~IPEFDylibObject() = default; + + public: + NE_COPY_DEFAULT(IPEFDylibObject) + + private: + DylibTraits* fMounted{nullptr}; + + public: + DylibTraits** GetAddressOf() { return &fMounted; } + + DylibTraits* Get() { return fMounted; } + + public: + void Mount(DylibTraits* to_mount) noexcept { + if (!to_mount || !to_mount->ImageObject) return; + + fMounted = to_mount; + + if (fLoader && to_mount) { + delete fLoader; + fLoader = nullptr; + } + + if (!fLoader) { + fLoader = new PEFLoader(fMounted->ImageObject); + } + } + + void Unmount() noexcept { + if (fMounted) fMounted = nullptr; + }; + + template + SymbolType Load(const Char* symbol_name, const SizeT& len, const UInt32& kind) { + if (symbol_name == nullptr || *symbol_name == 0) return nullptr; + if (len > kPathLen || len < 1) return nullptr; + + auto ret = reinterpret_cast(fLoader->FindSymbol(symbol_name, kind).Leak().Leak()); + + if (!ret) { + if (kind == kPefCode) return (VoidPtr) &__ne_pure_call; + + return nullptr; + } + + return ret; + } + + private: + PEFLoader* fLoader{nullptr}; +}; + +typedef IPEFDylibObject* IDylibRef; + +EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& header); +EXTERN_C Void rtl_fini_dylib_pef(USER_PROCESS& header, IDylibRef lib, Bool* successful); +} // namespace Kernel + +#endif /* ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ */ -- cgit v1.2.3