-
Notifications
You must be signed in to change notification settings - Fork 0
/
EFIHeaders.d
144 lines (125 loc) · 2.96 KB
/
EFIHeaders.d
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
module EFIHeaders;
private {
import std.bitmanip : bitfields;
import std.exception : enforce;
import std.string : format;
import Utils : toStruct;
}
abstract class EFIContainer {
EFIContainer[] containers;
size_t offset;
static EFIContainer parse(ubyte[] data, size_t offset = 0);
ubyte[] getBinary();
@property size_t length();
@property string name();
@property EFIGUID guid();
}
struct CapsuleHeader {
EFIGUID guid;
uint headerSize;
uint flags;
uint imageSize;
uint seqNum;
EFIGUID instanceID;
uint offsetToSplitInfo;
uint offsetToCapsuleBody;
uint offsetToOemHeader;
uint offsetToAuthorInfo;
uint offsetToRevInfo;
uint offsetToShortDesc;
uint offsetToLongDesc;
uint offsetToApplicableDevices;
}
struct VolumeHeader {
EFIGUID zeroes;
EFIGUID guid;
ulong volumeSize;
char[4] signature;
uint attribs;
ushort headerSize;
ushort checksum;
ubyte[3] reserved;
ubyte revision;
}
struct FileHeader {
EFIGUID guid;
ushort checksum;
FileType type;
ubyte attribs;
mixin(bitfields!(uint, "fileSize" , 24,
ubyte, "state", 8));
}
struct SectionHeader {
mixin(bitfields!(uint, "fileSize" , 24,
SectionType, "type", 8));
}
align(1)
struct CompressedSectionHeader {
uint uncompressedLength;
CompressionType type;
}
struct ExtendedSectionHeader {
EFIGUID guid;
ushort offset;
ushort attribs;
uint crc32;
}
struct EFIGUID {
uint data1;
ushort data2;
ushort data3;
ubyte[8] data4;
this(uint data1, ushort data2, ushort data3, ubyte[8] data4) {
this.data1 = data1;
this.data2 = data2;
this.data3 = data3;
this.data4 = data4;
}
this(ubyte[] data) {
enforce(data.length >= this.sizeof);
toStruct(data, &this, this.sizeof);
}
string toString() {
return format("%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X", data1, data2, data3, data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7]);
}
}
struct Block {
int numBlocks;
int blockLength;
bool isTerminator() {
return numBlocks == 0 && blockLength == 0;
}
}
enum FileType : ubyte {
Raw = 0x01,
Freeform = 0x02,
SecurityCore = 0x03,
PeiCore = 0x04,
PxeCore = 0x05,
PeiM = 0x06,
Driver = 0x07,
CombinedPeiMDriver = 0x08,
Application = 0x09,
FirmwareVolumeImage = 0x0B,
FfsPad = 0xF0,
}
enum CompressionType : ubyte{
None = 0x00,
Standard = 0x01
}
enum SectionType : ubyte {
All = 0,
Compressed = 1,
GUIDDefined = 2,
PE32 = 0x10,
PIC = 0x11,
TE = 0x12,
DxeDepex = 0x13,
Version = 0x14,
UserInterface = 0x15,
Compatibility16 = 0x16,
FirmwareVolumeImage = 0x17,
FreeformSubtypeGUID = 0x18,
Raw = 0x19,
PeiDepex = 0x1B
}