efiencrypt 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +7 -0
- package/README.md +98 -0
- package/build-laCVTTyp.js +2438 -0
- package/build.d.ts +2 -0
- package/codeBuilder.d.ts +15 -0
- package/efiencrypt +3474 -0
- package/extract-BW1V8DVW.js +12186 -0
- package/extract.d.ts +1 -0
- package/genCode.d.ts +5 -0
- package/handlers.d.ts +17 -0
- package/hexTransform.d.ts +14 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/package.json +1 -0
- package/schema.json +1 -0
- package/smbios.d.ts +196 -0
- package/smbios.js +199 -0
- package/stringBuilder.d.ts +7 -0
- package/type.d.ts +103 -0
package/extract.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const extract: (outputFolder: string) => Promise<void>;
|
package/genCode.d.ts
ADDED
package/handlers.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Hash } from "node:crypto";
|
|
2
|
+
import { CodeBuilder } from "./codeBuilder";
|
|
3
|
+
import { SmbiosTables } from "./smbios";
|
|
4
|
+
import type { Config, HashComponent } from "./type";
|
|
5
|
+
export type HashComponentHandler<T> = (params: {
|
|
6
|
+
hash: Hash;
|
|
7
|
+
codeBuilder: CodeBuilder;
|
|
8
|
+
config: Config;
|
|
9
|
+
hashComponent: T;
|
|
10
|
+
smbios?: SmbiosTables;
|
|
11
|
+
}) => void | Promise<void>;
|
|
12
|
+
export declare const reorderHash: (hash: Buffer) => Buffer<ArrayBufferLike>;
|
|
13
|
+
export declare const handlers: {
|
|
14
|
+
[T in HashComponent["type"]]: HashComponentHandler<HashComponent & {
|
|
15
|
+
type: T;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Transform, type TransformCallback } from "node:stream";
|
|
2
|
+
export declare class CountTransform extends Transform {
|
|
3
|
+
length: number;
|
|
4
|
+
constructor();
|
|
5
|
+
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class HexTransform extends CountTransform {
|
|
8
|
+
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class HexCVarTransform extends HexTransform {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(varName: string, isStatic: boolean);
|
|
13
|
+
_flush(callback: TransformCallback): void;
|
|
14
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"efiencrypt","version":"0.0.0","description":"Encrypts an EFI binary using a hash derived from user-defined data (random data, disk sectors, SMBIOS fields, ...)","type":"module","license":"MIT","bin":{"efiencrypt":"efiencrypt"},"repository":{"url":"https://github.com/davdiv/efiencrypt"},"exports":{".":{"types":"./index.d.ts","default":"./index.js"},"./smbios":{"types":"./smbios.d.ts","default":"./smbios.js"},"./schema.json":"./schema.json"}}
|
package/schema.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"object","properties":{"$schema":{"type":"string"},"inputFile":{"description":"Path to the input efi file to embed.","type":"string"},"outputFile":{"description":"Path to the output efi file to write.","type":"string"},"skipGenCode":{"description":"Whether to skip generating code","type":"boolean"},"skipExtract":{"description":"Whether to skip extracting source code\n(can be useful if the extraction was already done)","type":"boolean"},"skipMake":{"description":"Whether to skip calling make\n(can be useful to change the code before calling make)","type":"boolean"},"buildFolder":{"description":"Folder where to build the code.\nDefaults to a temporary folder that is removed when the build is finished.","type":"string"},"hashComponents":{"description":"Data to include in the hash for encryption.","type":"array","items":{"$ref":"#/definitions/HashComponent"}},"smbios":{"description":"Path to the input smbios dump file.\nCan be produced by: dmidecode --dump-bin <filePath>","type":"string"}},"additionalProperties":false,"required":["inputFile"],"definitions":{"HashComponent":{"anyOf":[{"$ref":"#/definitions/HashComponentRandom"},{"$ref":"#/definitions/HashComponentSmbios"},{"$ref":"#/definitions/HashComponentHardDiskData"},{"$ref":"#/definitions/HashComponentHardDiskSize"},{"$ref":"#/definitions/HashComponentFileData"},{"$ref":"#/definitions/HashComponentFileSize"},{"$ref":"#/definitions/HashComponentMiscStringData"}]},"HashComponentRandom":{"type":"object","properties":{"type":{"type":"string","const":"random"},"length":{"type":"number"}},"additionalProperties":false,"required":["length","type"]},"HashComponentSmbios":{"type":"object","properties":{"type":{"type":"string","const":"smbios"},"ref":{"$ref":"#/definitions/SmbiosFieldRef"},"value":{"type":"string"}},"additionalProperties":false,"required":["ref","type"]},"SmbiosFieldRef":{"anyOf":[{"type":"object","properties":{"table":{"$ref":"#/definitions/SmbiosTableRef"},"offset":{"type":"number"},"type":{"enum":["byte","dword","qword","string","uuid","word"],"type":"string"}},"additionalProperties":false,"required":["offset","table","type"]},{"enum":["baseboard-asset-tag","baseboard-manufacturer","baseboard-product-name","baseboard-serial-number","baseboard-version","bios-release-date","bios-revision","bios-vendor","bios-version","chassis-asset-tag","chassis-manufacturer","chassis-serial-number","chassis-version","processor-manufacturer","processor-version","system-family","system-manufacturer","system-product-name","system-serial-number","system-sku-number","system-uuid","system-version"],"type":"string"}]},"SmbiosTableRef":{"anyOf":[{"type":"object","properties":{"handle":{"type":"number"}},"additionalProperties":false,"required":["handle"]},{"type":"object","properties":{"type":{"type":"number"},"index":{"type":"number"}},"additionalProperties":false,"required":["type"]},{"enum":["32-bit Memory Error","64-bit Memory Error","Additional Information","Baseboard","Boot Integrity Services","Built-in Pointing Device","Cache","Chassis","Cooling Device","Electrical Current Probe","Firmware Inventory","Firmware Language","Group Associations","Hardware Security","IPMI Device","Management Controller Host Interface","Management Device","Management Device Component","Management Device Threshold Data","Memory Array Mapped Address","Memory Channel","Memory Controller","Memory Device","Memory Device Mapped Address","Memory Module","OEM Strings","Onboard Devices","Onboard Devices Extended Information","Out-of-band Remote Access","Physical Memory Array","Platform Firmware","Port Connector","Portable Battery","Power Supply","Processor","Processor Additional Information","String Property","System","System Boot","System Configuration Options","System Event Log","System Power Controls","System Reset","System Slots","TPM Device","Temperature Probe","Voltage Probe"],"type":"string"},{"type":"number"}]},"HashComponentHardDiskData":{"type":"object","properties":{"type":{"type":"string","const":"hd-data"},"device":{"type":"string"},"offsetRef":{"enum":["end","start"],"type":"string"},"offset":{"$ref":"#/definitions/BigNumber"},"value":{"anyOf":[{"$ref":"#/definitions/BinaryDataFromFile"},{"$ref":"#/definitions/BinaryDataFromLiteral"},{"$ref":"#/definitions/BinaryDataFromBuffer"},{"$ref":"#/definitions/BinaryMissingData"}]}},"additionalProperties":false,"required":["offset","offsetRef","type","value"]},"BigNumber":{"type":["string","number"]},"BinaryDataFromFile":{"type":"object","properties":{"type":{"type":"string","const":"file"},"file":{"type":"string"},"offset":{"type":"number"},"size":{"type":"number"}},"additionalProperties":false,"required":["file","type"]},"BinaryDataFromLiteral":{"type":"object","properties":{"type":{"$ref":"#/definitions/global.BufferEncoding"},"buffer":{"type":"string"}},"additionalProperties":false,"required":["buffer","type"]},"global.BufferEncoding":{"enum":["ascii","base64","base64url","binary","hex","latin1","ucs-2","ucs2","utf-16le","utf-8","utf16le","utf8"],"type":"string"},"BinaryDataFromBuffer":{"type":"object","properties":{"type":{"type":"string","const":"buffer"},"buffer":{"type":"object"}},"additionalProperties":false,"required":["buffer","type"]},"BinaryMissingData":{"type":"object","properties":{"type":{"type":"string","const":"missing"},"size":{"type":"number"}},"additionalProperties":false,"required":["type"]},"HashComponentHardDiskSize":{"type":"object","properties":{"type":{"type":"string","const":"hd-size"},"device":{"type":"string"},"value":{"$ref":"#/definitions/BigNumber"}},"additionalProperties":false,"required":["type","value"]},"HashComponentFileData":{"type":"object","properties":{"type":{"type":"string","const":"file-data"},"device":{"type":"string"},"file":{"type":"string"},"offsetRef":{"enum":["end","full","start"],"type":"string"},"offset":{"type":["string","number"]},"value":{"anyOf":[{"$ref":"#/definitions/BinaryDataFromFile"},{"$ref":"#/definitions/BinaryDataFromLiteral"},{"$ref":"#/definitions/BinaryDataFromBuffer"},{"$ref":"#/definitions/BinaryMissingData"}]}},"additionalProperties":false,"required":["file","type","value"]},"HashComponentFileSize":{"type":"object","properties":{"type":{"type":"string","const":"file-size"},"device":{"type":"string"},"file":{"type":"string"},"value":{"$ref":"#/definitions/BigNumber"}},"additionalProperties":false,"required":["file","type","value"]},"HashComponentMiscStringData":{"type":"object","properties":{"type":{"enum":["boot-file","boot-hd-device","boot-partition-device"],"type":"string"},"value":{"type":"string"}},"additionalProperties":false,"required":["type","value"]}},"$schema":"http://json-schema.org/draft-07/schema#"}
|
package/smbios.d.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
export interface SmbiosTable {
|
|
2
|
+
type: number;
|
|
3
|
+
handle: number;
|
|
4
|
+
structure: Buffer;
|
|
5
|
+
strings: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface SmbiosTables {
|
|
8
|
+
buffer: Buffer;
|
|
9
|
+
offset: number;
|
|
10
|
+
tables: SmbiosTable[];
|
|
11
|
+
byType: Record<number, SmbiosTable[]>;
|
|
12
|
+
byHandle: Record<number, SmbiosTable>;
|
|
13
|
+
}
|
|
14
|
+
export type SmbiosTableRefDetails = {
|
|
15
|
+
handle: number;
|
|
16
|
+
} | {
|
|
17
|
+
type: number;
|
|
18
|
+
index?: number;
|
|
19
|
+
};
|
|
20
|
+
export type SmbiosTableRef = number | keyof typeof SmbiosTableNames | SmbiosTableRefDetails;
|
|
21
|
+
export type SmbiosFieldRefDetails = {
|
|
22
|
+
table: SmbiosTableRef;
|
|
23
|
+
offset: number;
|
|
24
|
+
type: "byte" | "word" | "dword" | "qword" | "string" | "uuid";
|
|
25
|
+
};
|
|
26
|
+
export declare const smbiosDataTypeSize: Record<SmbiosFieldRefDetails["type"], number>;
|
|
27
|
+
export type SmbiosFieldRef = SmbiosFieldRefDetails | keyof typeof SmbiosFieldNames;
|
|
28
|
+
export declare const SmbiosTableNames: {
|
|
29
|
+
"Platform Firmware": number;
|
|
30
|
+
System: number;
|
|
31
|
+
Baseboard: number;
|
|
32
|
+
Chassis: number;
|
|
33
|
+
Processor: number;
|
|
34
|
+
"Memory Controller": number;
|
|
35
|
+
"Memory Module": number;
|
|
36
|
+
Cache: number;
|
|
37
|
+
"Port Connector": number;
|
|
38
|
+
"System Slots": number;
|
|
39
|
+
"Onboard Devices": number;
|
|
40
|
+
"OEM Strings": number;
|
|
41
|
+
"System Configuration Options": number;
|
|
42
|
+
"Firmware Language": number;
|
|
43
|
+
"Group Associations": number;
|
|
44
|
+
"System Event Log": number;
|
|
45
|
+
"Physical Memory Array": number;
|
|
46
|
+
"Memory Device": number;
|
|
47
|
+
"32-bit Memory Error": number;
|
|
48
|
+
"Memory Array Mapped Address": number;
|
|
49
|
+
"Memory Device Mapped Address": number;
|
|
50
|
+
"Built-in Pointing Device": number;
|
|
51
|
+
"Portable Battery": number;
|
|
52
|
+
"System Reset": number;
|
|
53
|
+
"Hardware Security": number;
|
|
54
|
+
"System Power Controls": number;
|
|
55
|
+
"Voltage Probe": number;
|
|
56
|
+
"Cooling Device": number;
|
|
57
|
+
"Temperature Probe": number;
|
|
58
|
+
"Electrical Current Probe": number;
|
|
59
|
+
"Out-of-band Remote Access": number;
|
|
60
|
+
"Boot Integrity Services": number;
|
|
61
|
+
"System Boot": number;
|
|
62
|
+
"64-bit Memory Error": number;
|
|
63
|
+
"Management Device": number;
|
|
64
|
+
"Management Device Component": number;
|
|
65
|
+
"Management Device Threshold Data": number;
|
|
66
|
+
"Memory Channel": number;
|
|
67
|
+
"IPMI Device": number;
|
|
68
|
+
"Power Supply": number;
|
|
69
|
+
"Additional Information": number;
|
|
70
|
+
"Onboard Devices Extended Information": number;
|
|
71
|
+
"Management Controller Host Interface": number;
|
|
72
|
+
"TPM Device": number;
|
|
73
|
+
"Processor Additional Information": number;
|
|
74
|
+
"Firmware Inventory": number;
|
|
75
|
+
"String Property": number;
|
|
76
|
+
};
|
|
77
|
+
export declare const SmbiosFieldNames: {
|
|
78
|
+
"bios-vendor": {
|
|
79
|
+
table: "Platform Firmware";
|
|
80
|
+
offset: number;
|
|
81
|
+
type: "string";
|
|
82
|
+
};
|
|
83
|
+
"bios-version": {
|
|
84
|
+
table: "Platform Firmware";
|
|
85
|
+
offset: number;
|
|
86
|
+
type: "string";
|
|
87
|
+
};
|
|
88
|
+
"bios-release-date": {
|
|
89
|
+
table: "Platform Firmware";
|
|
90
|
+
offset: number;
|
|
91
|
+
type: "string";
|
|
92
|
+
};
|
|
93
|
+
"bios-revision": {
|
|
94
|
+
table: "Platform Firmware";
|
|
95
|
+
offset: number;
|
|
96
|
+
type: "word";
|
|
97
|
+
};
|
|
98
|
+
"system-manufacturer": {
|
|
99
|
+
table: "System";
|
|
100
|
+
offset: number;
|
|
101
|
+
type: "string";
|
|
102
|
+
};
|
|
103
|
+
"system-product-name": {
|
|
104
|
+
table: "System";
|
|
105
|
+
offset: number;
|
|
106
|
+
type: "string";
|
|
107
|
+
};
|
|
108
|
+
"system-version": {
|
|
109
|
+
table: "System";
|
|
110
|
+
offset: number;
|
|
111
|
+
type: "string";
|
|
112
|
+
};
|
|
113
|
+
"system-serial-number": {
|
|
114
|
+
table: "System";
|
|
115
|
+
offset: number;
|
|
116
|
+
type: "string";
|
|
117
|
+
};
|
|
118
|
+
"system-uuid": {
|
|
119
|
+
table: "System";
|
|
120
|
+
offset: number;
|
|
121
|
+
type: "uuid";
|
|
122
|
+
};
|
|
123
|
+
"system-sku-number": {
|
|
124
|
+
table: "System";
|
|
125
|
+
offset: number;
|
|
126
|
+
type: "string";
|
|
127
|
+
};
|
|
128
|
+
"system-family": {
|
|
129
|
+
table: "System";
|
|
130
|
+
offset: number;
|
|
131
|
+
type: "string";
|
|
132
|
+
};
|
|
133
|
+
"baseboard-manufacturer": {
|
|
134
|
+
table: "Baseboard";
|
|
135
|
+
offset: number;
|
|
136
|
+
type: "string";
|
|
137
|
+
};
|
|
138
|
+
"baseboard-product-name": {
|
|
139
|
+
table: "Baseboard";
|
|
140
|
+
offset: number;
|
|
141
|
+
type: "string";
|
|
142
|
+
};
|
|
143
|
+
"baseboard-version": {
|
|
144
|
+
table: "Baseboard";
|
|
145
|
+
offset: number;
|
|
146
|
+
type: "string";
|
|
147
|
+
};
|
|
148
|
+
"baseboard-serial-number": {
|
|
149
|
+
table: "Baseboard";
|
|
150
|
+
offset: number;
|
|
151
|
+
type: "string";
|
|
152
|
+
};
|
|
153
|
+
"baseboard-asset-tag": {
|
|
154
|
+
table: "Baseboard";
|
|
155
|
+
offset: number;
|
|
156
|
+
type: "string";
|
|
157
|
+
};
|
|
158
|
+
"chassis-manufacturer": {
|
|
159
|
+
table: "Chassis";
|
|
160
|
+
offset: number;
|
|
161
|
+
type: "string";
|
|
162
|
+
};
|
|
163
|
+
"chassis-version": {
|
|
164
|
+
table: "Chassis";
|
|
165
|
+
offset: number;
|
|
166
|
+
type: "string";
|
|
167
|
+
};
|
|
168
|
+
"chassis-serial-number": {
|
|
169
|
+
table: "Chassis";
|
|
170
|
+
offset: number;
|
|
171
|
+
type: "string";
|
|
172
|
+
};
|
|
173
|
+
"chassis-asset-tag": {
|
|
174
|
+
table: "Chassis";
|
|
175
|
+
offset: number;
|
|
176
|
+
type: "string";
|
|
177
|
+
};
|
|
178
|
+
"processor-manufacturer": {
|
|
179
|
+
table: "Processor";
|
|
180
|
+
offset: number;
|
|
181
|
+
type: "string";
|
|
182
|
+
};
|
|
183
|
+
"processor-version": {
|
|
184
|
+
table: "Processor";
|
|
185
|
+
offset: number;
|
|
186
|
+
type: "string";
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
export declare const parseSmbios: (buffer: Buffer) => SmbiosTables;
|
|
190
|
+
export declare const getSmbiosString: (table: SmbiosTable, offset: number) => string;
|
|
191
|
+
export declare const resolveSmbiosTable: (ref: SmbiosTableRef) => SmbiosTableRefDetails;
|
|
192
|
+
export declare const getSmbiosTable: (tables: SmbiosTables, ref: SmbiosTableRef) => SmbiosTable;
|
|
193
|
+
export declare const resolveSmbiosField: (data: SmbiosFieldRef) => SmbiosFieldRefDetails & {
|
|
194
|
+
table: SmbiosTableRefDetails;
|
|
195
|
+
};
|
|
196
|
+
export declare const getSmbiosField: (tables: SmbiosTables, data: SmbiosFieldRef) => Buffer | null;
|
package/smbios.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const smbiosDataTypeSize = {
|
|
2
|
+
byte: 1,
|
|
3
|
+
string: 1,
|
|
4
|
+
word: 2,
|
|
5
|
+
dword: 4,
|
|
6
|
+
qword: 8,
|
|
7
|
+
uuid: 16
|
|
8
|
+
};
|
|
9
|
+
const SmbiosTableNames = {
|
|
10
|
+
"Platform Firmware": 0,
|
|
11
|
+
System: 1,
|
|
12
|
+
Baseboard: 2,
|
|
13
|
+
Chassis: 3,
|
|
14
|
+
Processor: 4,
|
|
15
|
+
"Memory Controller": 5,
|
|
16
|
+
"Memory Module": 6,
|
|
17
|
+
Cache: 7,
|
|
18
|
+
"Port Connector": 8,
|
|
19
|
+
"System Slots": 9,
|
|
20
|
+
"Onboard Devices": 10,
|
|
21
|
+
"OEM Strings": 11,
|
|
22
|
+
"System Configuration Options": 12,
|
|
23
|
+
"Firmware Language": 13,
|
|
24
|
+
"Group Associations": 14,
|
|
25
|
+
"System Event Log": 15,
|
|
26
|
+
"Physical Memory Array": 16,
|
|
27
|
+
"Memory Device": 17,
|
|
28
|
+
"32-bit Memory Error": 18,
|
|
29
|
+
"Memory Array Mapped Address": 19,
|
|
30
|
+
"Memory Device Mapped Address": 20,
|
|
31
|
+
"Built-in Pointing Device": 21,
|
|
32
|
+
"Portable Battery": 22,
|
|
33
|
+
"System Reset": 23,
|
|
34
|
+
"Hardware Security": 24,
|
|
35
|
+
"System Power Controls": 25,
|
|
36
|
+
"Voltage Probe": 26,
|
|
37
|
+
"Cooling Device": 27,
|
|
38
|
+
"Temperature Probe": 28,
|
|
39
|
+
"Electrical Current Probe": 29,
|
|
40
|
+
"Out-of-band Remote Access": 30,
|
|
41
|
+
"Boot Integrity Services": 31,
|
|
42
|
+
"System Boot": 32,
|
|
43
|
+
"64-bit Memory Error": 33,
|
|
44
|
+
"Management Device": 34,
|
|
45
|
+
"Management Device Component": 35,
|
|
46
|
+
"Management Device Threshold Data": 36,
|
|
47
|
+
"Memory Channel": 37,
|
|
48
|
+
"IPMI Device": 38,
|
|
49
|
+
"Power Supply": 39,
|
|
50
|
+
"Additional Information": 40,
|
|
51
|
+
"Onboard Devices Extended Information": 41,
|
|
52
|
+
"Management Controller Host Interface": 42,
|
|
53
|
+
"TPM Device": 43,
|
|
54
|
+
"Processor Additional Information": 44,
|
|
55
|
+
"Firmware Inventory": 45,
|
|
56
|
+
"String Property": 46
|
|
57
|
+
};
|
|
58
|
+
const SmbiosFieldNames = {
|
|
59
|
+
"bios-vendor": { table: "Platform Firmware", offset: 4, type: "string" },
|
|
60
|
+
"bios-version": { table: "Platform Firmware", offset: 5, type: "string" },
|
|
61
|
+
"bios-release-date": {
|
|
62
|
+
table: "Platform Firmware",
|
|
63
|
+
offset: 8,
|
|
64
|
+
type: "string"
|
|
65
|
+
},
|
|
66
|
+
"bios-revision": { table: "Platform Firmware", offset: 20, type: "word" },
|
|
67
|
+
"system-manufacturer": { table: "System", offset: 4, type: "string" },
|
|
68
|
+
"system-product-name": { table: "System", offset: 5, type: "string" },
|
|
69
|
+
"system-version": { table: "System", offset: 6, type: "string" },
|
|
70
|
+
"system-serial-number": { table: "System", offset: 7, type: "string" },
|
|
71
|
+
"system-uuid": { table: "System", offset: 8, type: "uuid" },
|
|
72
|
+
"system-sku-number": { table: "System", offset: 25, type: "string" },
|
|
73
|
+
"system-family": { table: "System", offset: 26, type: "string" },
|
|
74
|
+
"baseboard-manufacturer": { table: "Baseboard", offset: 4, type: "string" },
|
|
75
|
+
"baseboard-product-name": { table: "Baseboard", offset: 5, type: "string" },
|
|
76
|
+
"baseboard-version": { table: "Baseboard", offset: 6, type: "string" },
|
|
77
|
+
"baseboard-serial-number": {
|
|
78
|
+
table: "Baseboard",
|
|
79
|
+
offset: 7,
|
|
80
|
+
type: "string"
|
|
81
|
+
},
|
|
82
|
+
"baseboard-asset-tag": { table: "Baseboard", offset: 8, type: "string" },
|
|
83
|
+
"chassis-manufacturer": { table: "Chassis", offset: 4, type: "string" },
|
|
84
|
+
"chassis-version": { table: "Chassis", offset: 6, type: "string" },
|
|
85
|
+
"chassis-serial-number": { table: "Chassis", offset: 7, type: "string" },
|
|
86
|
+
"chassis-asset-tag": { table: "Chassis", offset: 8, type: "string" },
|
|
87
|
+
"processor-manufacturer": { table: "Processor", offset: 7, type: "string" },
|
|
88
|
+
"processor-version": { table: "Processor", offset: 16, type: "string" }
|
|
89
|
+
};
|
|
90
|
+
const parseSmbios = (buffer) => {
|
|
91
|
+
const v3 = buffer.subarray(0, 5).toString("ascii") === "_SM3_";
|
|
92
|
+
const v2 = !v3 && buffer.subarray(0, 4).toString("ascii") === "_SM_";
|
|
93
|
+
const rawTable = !v3 && !v2;
|
|
94
|
+
let position = 0;
|
|
95
|
+
if (!rawTable) {
|
|
96
|
+
const tableMaxSize = v3 ? buffer.readUint32LE(12) : buffer.readUint16LE(22);
|
|
97
|
+
const tableAddress = v3 ? buffer.readBigUint64LE(16) : BigInt(buffer.readUint16LE(24));
|
|
98
|
+
if (tableAddress + BigInt(tableMaxSize) !== BigInt(buffer.length)) {
|
|
99
|
+
throw new Error("Unexpected smbios file size.");
|
|
100
|
+
}
|
|
101
|
+
position = Number(tableAddress);
|
|
102
|
+
}
|
|
103
|
+
const offset = position;
|
|
104
|
+
const tables = [];
|
|
105
|
+
const byType = {};
|
|
106
|
+
const byHandle = {};
|
|
107
|
+
while (position < buffer.length) {
|
|
108
|
+
const length = buffer.readUint8(position + 1);
|
|
109
|
+
const structure = buffer.subarray(position, position + length);
|
|
110
|
+
const strings = [];
|
|
111
|
+
position += length;
|
|
112
|
+
while (true) {
|
|
113
|
+
const endPosition = buffer.indexOf(0, position);
|
|
114
|
+
if (endPosition === -1) {
|
|
115
|
+
throw new Error("Missing null character in smbios structure");
|
|
116
|
+
}
|
|
117
|
+
if (endPosition === position) {
|
|
118
|
+
if (strings.length === 0) {
|
|
119
|
+
position++;
|
|
120
|
+
if (buffer.readUInt8(position) !== 0) {
|
|
121
|
+
throw new Error("Expected null character in smbios structure");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
position++;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
strings.push(buffer.subarray(position, endPosition).toString("utf8"));
|
|
128
|
+
position = endPosition + 1;
|
|
129
|
+
}
|
|
130
|
+
const table = {
|
|
131
|
+
type: structure.readUint8(0),
|
|
132
|
+
handle: structure.readUint16LE(2),
|
|
133
|
+
structure,
|
|
134
|
+
strings
|
|
135
|
+
};
|
|
136
|
+
tables.push(table);
|
|
137
|
+
if (byHandle[table.handle] != null) {
|
|
138
|
+
throw new Error(`Duplicate handle 0x${table.handle.toString(16)} in smbios structure.`);
|
|
139
|
+
}
|
|
140
|
+
byHandle[table.handle] = table;
|
|
141
|
+
let withCurType = byType[table.type];
|
|
142
|
+
if (!withCurType) {
|
|
143
|
+
withCurType = [];
|
|
144
|
+
byType[table.type] = withCurType;
|
|
145
|
+
}
|
|
146
|
+
withCurType.push(table);
|
|
147
|
+
}
|
|
148
|
+
return { tables, byType, byHandle, offset, buffer };
|
|
149
|
+
};
|
|
150
|
+
const getSmbiosString = (table, offset) => {
|
|
151
|
+
const stringIndex = table.structure.readUint8(offset) - 1;
|
|
152
|
+
return stringIndex === -1 ? "" : table.strings[stringIndex];
|
|
153
|
+
};
|
|
154
|
+
const resolveSmbiosTable = (ref) => {
|
|
155
|
+
if (typeof ref === "string") {
|
|
156
|
+
ref = SmbiosTableNames[ref];
|
|
157
|
+
}
|
|
158
|
+
if (typeof ref === "number") {
|
|
159
|
+
ref = { type: ref };
|
|
160
|
+
}
|
|
161
|
+
return ref;
|
|
162
|
+
};
|
|
163
|
+
const getSmbiosTable = (tables, ref) => {
|
|
164
|
+
ref = resolveSmbiosTable(ref);
|
|
165
|
+
if ("handle" in ref) {
|
|
166
|
+
return tables.byHandle[ref.handle];
|
|
167
|
+
}
|
|
168
|
+
return tables.byType[ref.type]?.[ref.index ?? 0];
|
|
169
|
+
};
|
|
170
|
+
const resolveSmbiosField = (data) => {
|
|
171
|
+
if (typeof data === "string") {
|
|
172
|
+
data = SmbiosFieldNames[data];
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
...data,
|
|
176
|
+
table: resolveSmbiosTable(data.table)
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const getSmbiosField = (tables, data) => {
|
|
180
|
+
data = resolveSmbiosField(data);
|
|
181
|
+
const table = getSmbiosTable(tables, data.table);
|
|
182
|
+
if (!table) return null;
|
|
183
|
+
if (data.type === "string") {
|
|
184
|
+
return Buffer.from(getSmbiosString(table, data.offset));
|
|
185
|
+
} else {
|
|
186
|
+
return table.structure.subarray(data.offset, data.offset + smbiosDataTypeSize[data.type]);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
export {
|
|
190
|
+
SmbiosFieldNames,
|
|
191
|
+
SmbiosTableNames,
|
|
192
|
+
getSmbiosField,
|
|
193
|
+
getSmbiosString,
|
|
194
|
+
getSmbiosTable,
|
|
195
|
+
parseSmbios,
|
|
196
|
+
resolveSmbiosField,
|
|
197
|
+
resolveSmbiosTable,
|
|
198
|
+
smbiosDataTypeSize
|
|
199
|
+
};
|
package/type.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { SmbiosFieldRef } from "./smbios";
|
|
2
|
+
export type BigNumber = number | string;
|
|
3
|
+
export interface BinaryDataFromFile {
|
|
4
|
+
type: "file";
|
|
5
|
+
file: string;
|
|
6
|
+
offset?: number;
|
|
7
|
+
size?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface BinaryDataFromLiteral {
|
|
10
|
+
type: BufferEncoding;
|
|
11
|
+
buffer: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BinaryDataFromBuffer {
|
|
14
|
+
type: "buffer";
|
|
15
|
+
/**
|
|
16
|
+
* @TJS-type object
|
|
17
|
+
*/
|
|
18
|
+
buffer: Buffer;
|
|
19
|
+
}
|
|
20
|
+
export interface BinaryMissingData {
|
|
21
|
+
type: "missing";
|
|
22
|
+
size?: number;
|
|
23
|
+
}
|
|
24
|
+
export type BinaryData = BinaryDataFromFile | BinaryDataFromLiteral | BinaryDataFromBuffer;
|
|
25
|
+
export interface HashComponentRandom {
|
|
26
|
+
type: "random";
|
|
27
|
+
length: number;
|
|
28
|
+
}
|
|
29
|
+
export interface HashComponentSmbios {
|
|
30
|
+
type: "smbios";
|
|
31
|
+
ref: SmbiosFieldRef;
|
|
32
|
+
value?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface HashComponentHardDiskData {
|
|
35
|
+
type: "hd-data";
|
|
36
|
+
device?: string;
|
|
37
|
+
offsetRef: "start" | "end";
|
|
38
|
+
offset: BigNumber;
|
|
39
|
+
value: BinaryData | BinaryMissingData;
|
|
40
|
+
}
|
|
41
|
+
export interface HashComponentHardDiskSize {
|
|
42
|
+
type: "hd-size";
|
|
43
|
+
device?: string;
|
|
44
|
+
value: BigNumber | "missing";
|
|
45
|
+
}
|
|
46
|
+
export interface HashComponentFileData {
|
|
47
|
+
type: "file-data";
|
|
48
|
+
device?: string;
|
|
49
|
+
file: string;
|
|
50
|
+
offsetRef?: "start" | "end" | "full";
|
|
51
|
+
offset?: BigNumber;
|
|
52
|
+
value: BinaryData | BinaryMissingData;
|
|
53
|
+
}
|
|
54
|
+
export interface HashComponentFileSize {
|
|
55
|
+
type: "file-size";
|
|
56
|
+
device?: string;
|
|
57
|
+
file: string;
|
|
58
|
+
value: BigNumber | "missing";
|
|
59
|
+
}
|
|
60
|
+
export interface HashComponentMiscStringData {
|
|
61
|
+
type: "boot-hd-device" | "boot-partition-device" | "boot-file";
|
|
62
|
+
value: string;
|
|
63
|
+
}
|
|
64
|
+
export type HashComponent = HashComponentRandom | HashComponentSmbios | HashComponentFileData | HashComponentFileSize | HashComponentHardDiskData | HashComponentHardDiskSize | HashComponentMiscStringData;
|
|
65
|
+
export interface Config {
|
|
66
|
+
$schema?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Path to the input efi file to embed.
|
|
69
|
+
*/
|
|
70
|
+
inputFile: string;
|
|
71
|
+
/**
|
|
72
|
+
* Path to the output efi file to write.
|
|
73
|
+
*/
|
|
74
|
+
outputFile?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to skip generating code
|
|
77
|
+
*/
|
|
78
|
+
skipGenCode?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether to skip extracting source code
|
|
81
|
+
* (can be useful if the extraction was already done)
|
|
82
|
+
*/
|
|
83
|
+
skipExtract?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether to skip calling make
|
|
86
|
+
* (can be useful to change the code before calling make)
|
|
87
|
+
*/
|
|
88
|
+
skipMake?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Folder where to build the code.
|
|
91
|
+
* Defaults to a temporary folder that is removed when the build is finished.
|
|
92
|
+
*/
|
|
93
|
+
buildFolder?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Data to include in the hash for encryption.
|
|
96
|
+
*/
|
|
97
|
+
hashComponents?: HashComponent[];
|
|
98
|
+
/**
|
|
99
|
+
* Path to the input smbios dump file.
|
|
100
|
+
* Can be produced by: dmidecode --dump-bin <filePath>
|
|
101
|
+
*/
|
|
102
|
+
smbios?: string;
|
|
103
|
+
}
|