:: commit 94c56a030b77ae5e50fbb628ddbce02803187608

mintsuki <mintsuki@protonmail.com> — 2021-01-17 15:36

parents: fbdd709ba6

guid: Add handling of mixed endianness GUIDs

diff --git a/limine-pxe.bin b/limine-pxe.bin
index 5e98a025..511d8d4a 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index aba71294..e0c39516 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 4a0aa594..073ed65e 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/lib/guid.c b/stage2/lib/guid.c
index 0349372d..e6c635da 100644
--- a/stage2/lib/guid.c
+++ b/stage2/lib/guid.c
@@ -24,7 +24,6 @@ bool is_valid_guid(const char *s) {
     }
 }
 
-/*
 static void guid_convert_le_cluster(uint8_t *dest, const char *s, int len) {
     size_t p = 0;
     for (int i = len - 1; i >= 0; i--) {
@@ -33,7 +32,6 @@ static void guid_convert_le_cluster(uint8_t *dest, const char *s, int len) {
         i % 2 ? (dest[p] = val) : (dest[p++] |= val << 4);
     }
 }
-*/
 
 static void guid_convert_be_cluster(uint8_t *dest, const char *s, int len) {
     size_t p = 0;
@@ -44,7 +42,7 @@ static void guid_convert_be_cluster(uint8_t *dest, const char *s, int len) {
     }
 }
 
-bool string_to_guid(struct guid *guid, const char *s) {
+bool string_to_guid_be(struct guid *guid, const char *s) {
     if (!is_valid_guid(s))
         return false;
 
@@ -56,3 +54,16 @@ bool string_to_guid(struct guid *guid, const char *s) {
 
     return true;
 }
+
+bool string_to_guid_mixed(struct guid *guid, const char *s) {
+    if (!is_valid_guid(s))
+        return false;
+
+    guid_convert_le_cluster((uint8_t *)guid + 0,  s + 0,  8);
+    guid_convert_le_cluster((uint8_t *)guid + 4,  s + 9,  4);
+    guid_convert_le_cluster((uint8_t *)guid + 6,  s + 14, 4);
+    guid_convert_be_cluster((uint8_t *)guid + 8,  s + 19, 4);
+    guid_convert_be_cluster((uint8_t *)guid + 10, s + 24, 12);
+
+    return true;
+}
diff --git a/stage2/lib/guid.h b/stage2/lib/guid.h
index b1a787e3..dbb514c7 100644
--- a/stage2/lib/guid.h
+++ b/stage2/lib/guid.h
@@ -12,6 +12,7 @@ struct guid {
 } __attribute__((packed));
 
 bool is_valid_guid(const char *s);
-bool string_to_guid(struct guid *guid, const char *s);
+bool string_to_guid_be(struct guid *guid, const char *s);
+bool string_to_guid_mixed(struct guid *guid, const char *s);
 
 #endif
diff --git a/stage2/lib/uri.c b/stage2/lib/uri.c
index 6f752a55..02cad9a1 100644
--- a/stage2/lib/uri.c
+++ b/stage2/lib/uri.c
@@ -109,12 +109,17 @@ static bool uri_bios_dispatch(struct file_handle *fd, char *loc, char *path) {
 
 static bool uri_guid_dispatch(struct file_handle *fd, char *guid_str, char *path) {
     struct guid guid;
-    if (!string_to_guid(&guid, guid_str))
+    if (!string_to_guid_be(&guid, guid_str))
         return false;
 
     struct part part;
-    if (!part_get_by_guid(&part, &guid))
-        return false;
+    if (!part_get_by_guid(&part, &guid)) {
+        if (!string_to_guid_mixed(&guid, guid_str))
+            return false;
+
+        if (!part_get_by_guid(&part, &guid))
+            return false;
+    }
 
     if (fopen(fd, &part, path))
         return false;
tab: 248 wrap: offon