blob: 90175bef4bc1617791c9293af4037813197a3194 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* -------------------------------------------
Copyright Zeta Electronics Corporation
------------------------------------------- */
#include <BootKit/ProgramLoader.hxx>
#include <BootKit/Vendor/Support.hxx>
#include <BootKit/BootKit.hxx>
#include <string.h>
namespace Boot
{
ProgramLoader::ProgramLoader(VoidPtr blob)
: fBlob(blob), fStartAddress(nullptr)
{
// detect the format.
const char* firstBytes = reinterpret_cast<char*>(fBlob);
BTextWriter writer;
writer.WriteCharacter(firstBytes[0]).WriteCharacter(firstBytes[1]).WriteCharacter('\r').WriteCharacter('\n');
if (!firstBytes)
{
// failed to provide a valid pointer.
return;
}
if (firstBytes[0] == 'M' &&
firstBytes[1] == 'Z')
{
// Parse PE32+
fStartAddress = nullptr;
}
else if (firstBytes[0] == 'J' &&
firstBytes[1] == 'o' &&
firstBytes[2] == 'y' &&
firstBytes[3] == '!')
{
// Parse Non FAT PEF.
fStartAddress = nullptr;
}
else
{
// probably a binary blob.
fStartAddress = fBlob;
}
}
Void ProgramLoader::Start(HEL::HandoverInformationHeader* handover)
{
if (!fStartAddress) return;
((HEL::HandoverProc)fStartAddress)(handover);
}
const Char* ProgramLoader::GetName()
{
return fBlobName;
}
Void ProgramLoader::SetName(const Char* name)
{
CopyMem(fBlobName, name, StrLen(name));
}
} // namespace Boot
|