From f3d931aa7cfaf96baef8383b59a8938779541ee7 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Thu, 15 Aug 2024 18:35:34 +0200 Subject: [IMP] Moved source code into dev/ folder. Signed-off-by: Amlal EL Mahrouss --- dev/Kernel/CFKit/LoaderUtils.hxx | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 dev/Kernel/CFKit/LoaderUtils.hxx (limited to 'dev/Kernel/CFKit/LoaderUtils.hxx') diff --git a/dev/Kernel/CFKit/LoaderUtils.hxx b/dev/Kernel/CFKit/LoaderUtils.hxx new file mode 100644 index 00000000..3edacc67 --- /dev/null +++ b/dev/Kernel/CFKit/LoaderUtils.hxx @@ -0,0 +1,54 @@ +#ifndef __CFKIT_LOADER_UTILS_HXX__ +#define __CFKIT_LOADER_UTILS_HXX__ + +#include +#include + +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__ -- cgit v1.2.3