NeKernel dev
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1#ifndef CFKIT_UTILS_H
2#define CFKIT_UTILS_H
3
4#include <KernelKit/MSDOS.h>
5#include <KernelKit/PE.h>
6
8namespace Kernel::CF {
11 if (!ptrDos) return nullptr;
12
13 if (ptrDos->eMagic[0] != kMagMz0) return nullptr;
14
15 if (ptrDos->eMagic[1] != kMagMz1) return nullptr;
16
17#ifdef __NE_AMD64__
18 return (LDR_EXEC_HEADER_PTR) (VoidPtr) (&ptrDos->eLfanew + 1);
19#else
20 return (LDR_EXEC_HEADER_PTR) (VoidPtr) (&ptrDos->eLfanew);
21#endif
22}
23
26 if (!ptrDos) return nullptr;
27
28 auto exec = ldr_find_exec_header(ptrDos);
29
30 if (!exec) return nullptr;
31
32 return (LDR_OPTIONAL_HEADER_PTR) (VoidPtr) (&exec->Characteristics + 1);
33}
34
37inline auto ldr_find_exec_header(const Char* ptrDos) -> LDR_EXEC_HEADER_PTR {
38 return ldr_find_exec_header((DosHeaderPtr) ptrDos);
39}
40
45}
46} // namespace Kernel::CF
47
48#endif // ifndef CFKIT_UTILS_H
struct _DosHeader * DosHeaderPtr
#define kMagMz1
Definition MSDOS.h:24
#define kMagMz0
Definition MSDOS.h:23
struct LDR_EXEC_HEADER * LDR_EXEC_HEADER_PTR
struct LDR_OPTIONAL_HEADER * LDR_OPTIONAL_HEADER_PTR
CFKit.
Definition GUIDWizard.h:18
auto ldr_find_exec_header(DosHeaderPtr ptrDos) -> LDR_EXEC_HEADER_PTR
Finds the PE header inside the blob.
Definition Utils.h:10
auto ldr_find_opt_exec_header(DosHeaderPtr ptrDos) -> LDR_OPTIONAL_HEADER_PTR
Finds the PE optional header inside the blob.
Definition Utils.h:25
char Char
Definition Config.h:51
void * VoidPtr
Definition Config.h:33