| 1 |
|
| 2 |
|
| 3 |
#include "guids.h" |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
#include <commonlib/bsd/helpers.h> |
| 9 |
|
| 10 |
#include "udk2017.h" |
| 11 |
#include "utils.h" |
| 12 |
|
| 13 |
const struct guid_alias_t known_guids[] = { |
| 14 |
{ |
| 15 |
"coreboot", |
| 16 |
{ |
| 17 |
0xceae4c1d, 0x335b, 0x4685, |
| 18 |
{ 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 } |
| 19 |
}, |
| 20 |
}, |
| 21 |
{ |
| 22 |
"dasharo", |
| 23 |
{ |
| 24 |
0xd15b327e, 0xff2d, 0x4fc1, |
| 25 |
{ 0xab, 0xf6, 0xc1, 0x2b, 0xd0, 0x8c, 0x13, 0x59 } |
| 26 |
}, |
| 27 |
}, |
| 28 |
{ |
| 29 |
"global", |
| 30 |
{ |
| 31 |
0x8be4df61, 0x93ca, 0x11d2, |
| 32 |
{ 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c } |
| 33 |
}, |
| 34 |
}, |
| 35 |
{ |
| 36 |
"secureboot", |
| 37 |
{ |
| 38 |
0xd719b2cb, 0x3d3a, 0x4596, |
| 39 |
{ 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f } |
| 40 |
}, |
| 41 |
}, |
| 42 |
{ |
| 43 |
"microsoft", |
| 44 |
{ |
| 45 |
0x77fa9abd, 0x0359, 0x4d32, |
| 46 |
{ 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b } |
| 47 |
}, |
| 48 |
}, |
| 49 |
}; |
| 50 |
|
| 51 |
const int known_guid_count = ARRAY_SIZE(known_guids); |
| 52 |
|
| 53 |
char *format_guid(const EFI_GUID *guid, bool use_alias) |
| 54 |
{ |
| 55 |
if (use_alias) { |
| 56 |
for (int i = 0; i < known_guid_count; ++i) { |
| 57 |
const struct guid_alias_t *known_guid = &known_guids[i]; |
| 58 |
if (memcmp(&known_guid->guid, guid, sizeof(*guid)) == 0) |
| 59 |
return strdup(known_guid->alias); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
char *str = xmalloc(GUID_LEN + 1); |
| 64 |
snprintf(str, GUID_LEN + 1, |
| 65 |
"%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x", |
| 66 |
guid->Data1, guid->Data2, guid->Data3, |
| 67 |
guid->Data4[0], guid->Data4[1], |
| 68 |
guid->Data4[2], guid->Data4[3], |
| 69 |
guid->Data4[4], guid->Data4[5], |
| 70 |
guid->Data4[6], guid->Data4[7]); |
| 71 |
return str; |
| 72 |
} |
| 73 |
|
| 74 |
bool parse_guid(const char str[], EFI_GUID *guid) |
| 75 |
{ |
| 76 |
for (int i = 0; i < known_guid_count; ++i) { |
| 77 |
const struct guid_alias_t *known_guid = &known_guids[i]; |
| 78 |
if (str_eq(known_guid->alias, str)) { |
| 79 |
*guid = known_guid->guid; |
| 80 |
return true; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
if (strlen(str) != GUID_LEN) |
| 85 |
return false; |
| 86 |
|
| 87 |
int n = sscanf(str, |
| 88 |
"%08x-%04hx-%04hx-" |
| 89 |
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", |
| 90 |
&guid->Data1, &guid->Data2, &guid->Data3, |
| 91 |
&guid->Data4[0], &guid->Data4[1], |
| 92 |
&guid->Data4[2], &guid->Data4[3], |
| 93 |
&guid->Data4[4], &guid->Data4[5], |
| 94 |
&guid->Data4[6], &guid->Data4[7]); |
| 95 |
return n == 11; |
| 96 |
} |