summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/CFKit/Utils.h
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:13 +0100
committerAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:45 +0100
commit610f91d87152cbe48d3054fcf437d8239da6ef35 (patch)
treea386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/CFKit/Utils.h
parent509fcca5986651c8ba712fb395f8498f2dea4109 (diff)
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/CFKit/Utils.h')
-rw-r--r--dev/Kernel/CFKit/Utils.h55
1 files changed, 55 insertions, 0 deletions
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