42 lines
1.8 KiB
C
42 lines
1.8 KiB
C
#pragma once
|
|
// ldr_image.h - minimal PE32+ loader
|
|
// Loads an already-mapped PE image and resolves its imports.
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include <ke_status.h>
|
|
|
|
// Map a PE32+ image from 'buffer' into the kernel virtual address space.
|
|
// On success, *baseOut receives the virtual base address.
|
|
KSTATUS LdrLoadImage(const void* buffer, size_t size, uintptr_t* baseOut, bool user);
|
|
|
|
// Return the SizeOfImage recorded in the PE header for an already-mapped image.
|
|
size_t LdrGetImageSize(uintptr_t base);
|
|
|
|
// Look up a named export in a loaded module.
|
|
// 'moduleName' must match a name in BOOT_INFO.Modules (e.g., "hal.dll").
|
|
void* LdrGetExport(const char* moduleName, const char* functionName);
|
|
|
|
// Get the entry point address of a loaded image.
|
|
uintptr_t LdrGetEntryPoint(uintptr_t base);
|
|
|
|
// Resolve the import table of an already-loaded image using the global registry.
|
|
KSTATUS LdrResolveImports(uintptr_t imageBase);
|
|
|
|
// Resolve imports using a process-local module registry.
|
|
struct PROCESS;
|
|
KSTATUS LdrResolveImportsForProcess(struct PROCESS* process, uintptr_t imageBase);
|
|
|
|
// Apply final page permissions for a loaded image after relocations/imports.
|
|
KSTATUS LdrProtectImage(uintptr_t imageBase, bool user);
|
|
|
|
// Load a DLL for a specific process, resolve it against that process's
|
|
// loaded modules, and register it in the process-local registry.
|
|
KSTATUS LdrLoadModuleForProcess(struct PROCESS* process, const char* filename, uintptr_t* baseOut);
|
|
|
|
// Called by KernelMain to register all modules from BOOT_INFO so that
|
|
// LdrGetExport can find them.
|
|
struct BOOT_INFO; // forward declare for the compiler to shut the fuck up
|
|
void LdrRegisterModulesFromBootInfo(const struct BOOT_INFO* bootInfo);
|
|
void LdrRegisterModule(const char* name, uintptr_t base);
|