57 lines
2.7 KiB
C
57 lines
2.7 KiB
C
// Kernel ldr image declarations shared by implementation files and kernel clients.
|
|
|
|
#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 <ntlite/status.h>
|
|
|
|
struct PROCESS;
|
|
struct FILE_OBJECT;
|
|
struct SYS_MODULE_INFO;
|
|
|
|
// Map a PE32+ image from a bootloader/driver raw buffer into kernel space.
|
|
// User images must be loaded from FILE_OBJECTs so image sections have stable identity.
|
|
KSTATUS LdrLoadKernelImage(const void* buffer, size_t size, uintptr_t* baseOut);
|
|
KSTATUS LdrLoadImageFileForProcess(struct PROCESS* process, struct FILE_OBJECT* file, uintptr_t* baseOut);
|
|
|
|
// Return the SizeOfImage recorded in the PE header for an already-mapped image.
|
|
size_t LdrGetImageSize(uintptr_t base);
|
|
size_t LdrGetMappedImageSize(struct PROCESS* process, 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.
|
|
KSTATUS LdrResolveImportsForProcess(struct PROCESS* process, uintptr_t imageBase);
|
|
|
|
// Apply final page permissions for a loaded image after relocations/imports.
|
|
KSTATUS LdrProtectImageForProcess(struct PROCESS* process, 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.
|
|
#define LDR_MODULE_LOAD_IMPORT 0x00000001u
|
|
#define LDR_MODULE_LOAD_PUBLIC 0x00000002u
|
|
|
|
KSTATUS LdrLoadModuleForProcess(struct PROCESS* process, const char* filename, uint32_t loadFlags, uintptr_t* baseOut);
|
|
KSTATUS LdrUnloadModuleForProcess(struct PROCESS* process, uintptr_t imageBase);
|
|
KSTATUS LdrQueryModuleForProcess(struct PROCESS* process, uintptr_t imageBase, struct SYS_MODULE_INFO* infoOut);
|
|
KSTATUS LdrCopyProcessModuleInfo(struct PROCESS* process, struct SYS_MODULE_INFO* infoOut, size_t maxCount, size_t* countOut);
|
|
void* LdrGetModuleExportForProcess(struct PROCESS* process, uintptr_t imageBase, const char* functionName);
|
|
|
|
// Called by KernelMain to register all modules from BOOT_INFO so that
|
|
// LdrGetExport can find them.
|
|
struct BOOT_INFO; // forward declaration
|
|
void LdrRegisterModulesFromBootInfo(const struct BOOT_INFO* bootInfo);
|
|
void LdrRegisterModule(const char* name, uintptr_t base);
|
|
const char* LdrFindKernelModuleByAddress(uintptr_t address, uintptr_t* baseOut, size_t* sizeOut);
|