-
Notifications
You must be signed in to change notification settings - Fork 50
/
bin_to_oemvars
executable file
·66 lines (59 loc) · 2.33 KB
/
bin_to_oemvars
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
#!/usr/bin/python
import argparse
import re
import string
def guid_string(p):
if re.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$', p) is None:
raise argparse.ArgumentTypeError("Argument must be a GUID value")
return p
def escaped_value(value):
result = ''
for char in value:
result += "%%%02x" % ord(char)
return result
def main():
parser = argparse.ArgumentParser(epilog="""Common namespace/variable pairings:
--global/PK,
--global/KEK,
--image-security/db
""")
guid_group = parser.add_mutually_exclusive_group(required=True)
guid_group.add_argument('--guid',
dest='namespace_guid',
type=guid_string,
help="namespace GUID of the variables")
guid_group.add_argument('--global',
action='store_const',
metavar='namespace-guid',
const="8be4df61-93ca-11d2-aa0d-00e098032b8c",
dest='namespace_guid',
help='variables are in EFI global namespace')
guid_group.add_argument('--image-security',
action='store_const',
const="d719b2cb-3d3a-4596-a3bc-dad00e67656f",
dest='namespace_guid',
help='variables are in EFI image security namespace')
guid_group.add_argument('--fastboot',
action='store_const',
const="1ac80a82-4f0c-456b-9a99-debeb431fcc1",
dest='namespace_guid',
help='variables are in EFI fastboot namespace')
parser.add_argument('--var',
nargs=2,
metavar=('NAME', 'VALUE-FILENAME'),
action='append',
required=True,
help='output variable with specific value')
args = parser.parse_args()
print "GUID = %s" % (args.namespace_guid)
print
for var in args.var:
value_file = open(var[1], "r")
value = value_file.read()
print "%s @%s" % (var[0], escaped_value(value))
print
if __name__ == "__main__":
try:
main()
except Exception as e:
print e