From 5a59c308db5059ff2e00fc81849d0e71a4cb2671 Mon Sep 17 00:00:00 2001 From: Chloe M Date: Tue, 14 Jul 2026 16:45:28 -0400 Subject: [PATCH] ptos: ex: Add pre-boot image parser Signed-off-by: Chloe M --- service/host/hole/core/hole.c | 2 +- service/ptos/ex/pbi.c | 90 +++++++++++++++++++++++++++++++++++ service/ptos/head/ex/pbi.h | 39 +++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 service/ptos/ex/pbi.c create mode 100644 service/ptos/head/ex/pbi.h diff --git a/service/host/hole/core/hole.c b/service/host/hole/core/hole.c index de008da..8dd0846 100644 --- a/service/host/hole/core/hole.c +++ b/service/host/hole/core/hole.c @@ -20,7 +20,7 @@ #include #define REF_MAGIC "PTOS.PBI" -#define REF_MAGIC_LEN 8 +#define REF_MAGIC_LEN 9 #define REF_PATH_LEN 256 /* Set to 1 for verbose */ diff --git a/service/ptos/ex/pbi.c b/service/ptos/ex/pbi.c new file mode 100644 index 0000000..14a9106 --- /dev/null +++ b/service/ptos/ex/pbi.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Pre-boot image manager + * Author: Chloe M. + */ + +#include +#include +#include +#include + +#define REF_MAGIC "PTOS.PBI" +#define REF_MAGIC_LEN 9 +#define REF_PATH_LEN 256 + +static BPAL_MODULE Pbi; + +/* + * A reference is an entry within the table that refers + * to a block of data after the reference table. + * + * @Magic: Reference magic + * @Path: File path + * @Size: File size + * @DataOff: Data offset + */ +typedef PACKED struct { + CHAR Magic[REF_MAGIC_LEN]; + CHAR Path[REF_PATH_LEN]; + USIZE Size; + USIZE DataOff; +} HOLE_REF; + +PT_STATUS +ExPbiLookup(CHAR *Path, PBI_FILE *Result) +{ + HOLE_REF *Ref; + USIZE PathLen; + + if (Path == NULL || Result == NULL) { + return STATUS_INVALID_PARAM; + } + + if (*Path != '/') { + return STATUS_NOT_FOUND; + } + + ++Path; + Ref = Pbi.Data; + PathLen = RtlStrLen(Path); + + for (;;) { + if (RtlMemCmp(Ref->Magic, REF_MAGIC, REF_MAGIC_LEN) != 0) { + break; + } + + if (Ref->Path[0] != *Path) { + ++Ref; + continue; + } + + if (RtlMemCmp(Ref->Path, Path, PathLen) == 0) { + Result->Data = PTR_OFFSET(Pbi.Data, Ref->DataOff); + Result->Size = Ref->Size; + return STATUS_SUCCESS; + } + + ++Ref; + } + + return STATUS_NOT_FOUND; +} + +PT_STATUS +ExPbiInit(VOID) +{ + BPAL_HANDLE Bpal; + PT_STATUS Status; + + KeBpalGetHandle(&Bpal); + + Status = Bpal.ModuleLookup("/boot/pbi.hole", &Pbi); + if (Status != STATUS_SUCCESS) { + return Status; + } + + return STATUS_SUCCESS; +} diff --git a/service/ptos/head/ex/pbi.h b/service/ptos/head/ex/pbi.h new file mode 100644 index 0000000..8a9aa21 --- /dev/null +++ b/service/ptos/head/ex/pbi.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Pre-boot image manager + * Author: Chloe M. + */ + +#ifndef _EX_PBI_H_ +#define _EX_PBI_H_ 1 + +#include +#include + +/* + * Represents an BPI file + * + * @Data: Actual raw data + * @Size: Byte count + */ +typedef struct { + VOID *Data; + USIZE Size; +} PBI_FILE; + +/* + * Look up a file from the pre-boot image + * + * @Path: Path to file to lookup + * @Result: Result is written here + */ +PT_STATUS ExPbiLookup(CHAR *Path, PBI_FILE *Result); + +/* + * Initialize the pre-boot image manaer + */ +PT_STATUS ExPbiInit(VOID); + +#endif /* !_EX_PBI_H_ */