diff options
| author | Amlal <amlal@zka.com> | 2024-07-18 09:43:27 +0200 |
|---|---|---|
| committer | Amlal <amlal@zka.com> | 2024-07-18 09:43:27 +0200 |
| commit | 384300904e6cf9187e5e4c4d9a8fad740592cacb (patch) | |
| tree | f0a0f196f32f5a224ca529ad7d4e99dd6a95586e /Kernel/CFKit | |
| parent | e9b8d8f68bdd79907feeed9e87572ba562c213e9 (diff) | |
[IMP] BootJump has been fixed, LoaderUtils API for CFKit. (Kernel's CoreFoundation like API)
[IMP] Add Write for UChar* types. (BTextWriter)
Signed-off-by: Amlal <amlal@zka.com>
Diffstat (limited to 'Kernel/CFKit')
| -rw-r--r-- | Kernel/CFKit/LoaderUtils.hxx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Kernel/CFKit/LoaderUtils.hxx b/Kernel/CFKit/LoaderUtils.hxx new file mode 100644 index 00000000..3edacc67 --- /dev/null +++ b/Kernel/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__ |
