From d5cf80c085c67aed598df06e3c5dc94fdcfbde6c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 11 Jul 2024 12:35:24 +0200 Subject: [IMPROVEMENT] Program loader checks magic according to specs. Signed-off-by: Amlal El Mahrouss --- Boot/Sources/ProgramLoader.cxx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'Boot/Sources/ProgramLoader.cxx') diff --git a/Boot/Sources/ProgramLoader.cxx b/Boot/Sources/ProgramLoader.cxx index 0603fb9c..62dd8d8e 100644 --- a/Boot/Sources/ProgramLoader.cxx +++ b/Boot/Sources/ProgramLoader.cxx @@ -8,6 +8,8 @@ #include #include +#include + EXTERN_C { #include @@ -29,17 +31,17 @@ namespace Boot return; } - if (firstBytes[0] == 'M' && - firstBytes[1] == 'Z') + if (firstBytes[0] == kMagMz0 && + firstBytes[1] == kMagMz1) { // Parse PE32+ fStartAddress = nullptr; writer.Write("newosldr: MZ executable detected.\r"); } - else if (firstBytes[0] == 'J' && - firstBytes[1] == 'o' && - firstBytes[2] == 'y' && - firstBytes[3] == '!') + else if (firstBytes[0] == kPefMagic[0] && + firstBytes[1] == kPefMagic[1] && + firstBytes[2] == kPefMagic[2] && + firstBytes[3] == kPefMagic[3]) { // Parse Non FAT PEF. fStartAddress = nullptr; @@ -52,14 +54,17 @@ namespace Boot } } + /// @note handover header has to be valid! Void ProgramLoader::Start(HEL::HandoverInformationHeader* handover) { + MUST_PASS(handover); + BTextWriter writer; - writer.Write("newosldr: running: ").Write(fBlobName).Write("\r"); + writer.Write("newosldr: Trying to run: ").Write(fBlobName).Write("\r"); if (!fStartAddress) { - writer.Write("newosldr: exec error.\r"); + writer.Write("newosldr: Exec format error.\r"); return; } -- cgit v1.2.3