[Libguestfs] [PATCH] inspection: Fix detection of the kernel version of Windows ≥ 10 (RHBZ#1281578).

Richard W.M. Jones rjones at redhat.com
Fri Nov 13 14:23:57 UTC 2015


See the description in the bug report:

https://bugzilla.redhat.com/show_bug.cgi?id=1281578

Thanks: Richard Tollerton for alerting me to this change in the way
that Windows version numbers are stored in the Registry starting with
Windows ≥ 10.
---
 src/inspect-fs-windows.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index f8df5e5..e800b1e 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
@@ -279,6 +280,7 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
     { "Microsoft", "Windows NT", "CurrentVersion" };
   size_t i;
   CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values = NULL;
+  bool ignore_currentversion = false;
 
   if (guestfs_hivex_open (g, software_path,
                           GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
@@ -309,7 +311,43 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
       if (!fs->product_name)
         goto out;
     }
-    else if (STRCASEEQ (key, "CurrentVersion")) {
+    else if (STRCASEEQ (key, "CurrentMajorVersionNumber")) {
+      size_t vsize;
+      int64_t vtype = guestfs_hivex_value_type (g, value);
+      CLEANUP_FREE char *vbuf = guestfs_hivex_value_value (g, value, &vsize);
+
+      if (vbuf == NULL)
+        goto out;
+      if (vtype != 4 || vsize != 4) {
+        error (g, "hivex: expected CurrentVersion\\%s to be a DWORD field",
+               "CurrentMajorVersionNumber");
+        goto out;
+      }
+
+      fs->major_version = le32toh (*(int32_t *)vbuf);
+
+      /* Ignore CurrentVersion if we see it after this key. */
+      ignore_currentversion = true;
+    }
+    else if (STRCASEEQ (key, "CurrentMinorVersionNumber")) {
+      size_t vsize;
+      int64_t vtype = guestfs_hivex_value_type (g, value);
+      CLEANUP_FREE char *vbuf = guestfs_hivex_value_value (g, value, &vsize);
+
+      if (vbuf == NULL)
+        goto out;
+      if (vtype != 4 || vsize != 4) {
+        error (g, "hivex: expected CurrentVersion\\%s to be a DWORD field",
+               "CurrentMinorVersionNumber");
+        goto out;
+      }
+
+      fs->minor_version = le32toh (*(int32_t *)vbuf);
+
+      /* Ignore CurrentVersion if we see it after this key. */
+      ignore_currentversion = true;
+    }
+    else if (!ignore_currentversion && STRCASEEQ (key, "CurrentVersion")) {
       CLEANUP_FREE char *version = guestfs_hivex_value_utf8 (g, value);
       if (!version)
         goto out;
-- 
2.6.2




More information about the Libguestfs mailing list