Richard W.M. Jones
2015-Nov-13  11:49 UTC
[Libguestfs] [PATCH] inspection: Fix detection of the kernel version of Windows ≥ 10 (RHBZ#1281578).
I wasn't able to test this patch yet, so I'm just going off the description in the bug and in an MSDN posting. Rich.
Richard W.M. Jones
2015-Nov-13  11:49 UTC
[Libguestfs] [PATCH] inspection: Fix detection of the kernel version of Windows ≥ 10 (RHBZ#1281578).
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 af28bb7..23b95fb 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 size;
+      int64_t type = guestfs_hivex_value_type (g, value);
+      CLEANUP_FREE char *buf = guestfs_hivex_value_value (g, value, &size);
+
+      if (buf == NULL)
+        goto out;
+      if (type != 4 || len != 4) {
+        error (g, "hivex: expected CurrentVersion\\%s to be a DWORD
field",
+               "CurrentMajorVersionNumber");
+        goto out;
+      }
+
+      fs->major_version = le32toh (*(int32_t *)buf);
+
+      /* Ignore CurrentVersion if we see it after this key. */
+      ignore_currentversion = true;
+    }
+    else if (STRCASEEQ (key, "CurrentMinorVersionNumber")) {
+      size_t size;
+      int64_t type = guestfs_hivex_value_type (g, value);
+      CLEANUP_FREE char *buf = guestfs_hivex_value_value (g, value, &size);
+
+      if (buf == NULL)
+        goto out;
+      if (type != 4 || len != 4) {
+        error (g, "hivex: expected CurrentVersion\\%s to be a DWORD
field",
+               "CurrentMinorVersionNumber");
+        goto out;
+      }
+
+      fs->minor_version = le32toh (*(int32_t *)buf);
+
+      /* 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.5.0
Richard W.M. Jones
2015-Nov-13  14:20 UTC
Re: [Libguestfs] [PATCH] inspection: Fix detection of the kernel version of Windows ≥ 10 (RHBZ#1281578).
On Fri, Nov 13, 2015 at 11:49:46AM +0000, Richard W.M. Jones wrote:> I wasn't able to test this patch yet, so I'm just going off the > description in the bug and in an MSDN posting.I did now manage to test it, and ... it doesn't work. So ignore this patch for the moment. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Reasonably Related Threads
- [PATCH v2] inspection: Fix detection of the kernel version of Windows ≥ 10 (RHBZ#1281578).
- [PATCH] inspect: get windows drive letters for GPT disks.
- [PATCHv2] inspect: get windows drive letters for GPT disks.
- [PATCH 0/4] Add hivex APIs into the libguestfs API (RHBZ#852394)
- [PATCH 0/3] Use __attribute__((cleanup(...)))