inspect: Detect 32 bit applications running on WOW64 emulator (RHBZ#692545).
authorRichard W.M. Jones <rjones@redhat.com>
Thu, 31 Mar 2011 14:51:00 +0000 (15:51 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Thu, 31 Mar 2011 14:51:00 +0000 (15:51 +0100)
These applications are located along a different Registry path.  See
http://support.microsoft.com/kb/896459 for all the details.

Thanks Jinxin Zheng for finding the bug and the solution.

images/guest-aux/windows-software
images/guest-aux/windows-software.reg
inspector/example-windows.xml
src/inspect.c

index e935886..d936ea8 100755 (executable)
Binary files a/images/guest-aux/windows-software and b/images/guest-aux/windows-software differ
index e2efda6..2c0f41c 100644 (file)
 "DisplayVersion"=str(1):"1.2.5"
 "Publisher"=str(1):"Red Hat Inc."
 "InstallLocation"=str(1):"C:\\Program Files\\Red Hat\\test3"
 "DisplayVersion"=str(1):"1.2.5"
 "Publisher"=str(1):"Red Hat Inc."
 "InstallLocation"=str(1):"C:\\Program Files\\Red Hat\\test3"
+
+[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node]
+
+[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft]
+
+[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows]
+
+[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows\CurrentVersion]
+
+[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows\CurrentVersion\Uninstall]
+
+[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432node\Microsoft\Windows\CurrentVersion\Uninstall\test4]
+"DisplayName"=str(1):"Test4 is not real software"
+"DisplayVersion"=str(1):"1.2.6"
+"Publisher"=str(1):"Red Hat Inc."
+"Comments"=str(1):"WOW6432node is where 32 bit emulated apps are installed on 64 bit Windows"
index 12c6956..7b3ae74 100644 (file)
         <install_path>C:\Program Files\Red Hat\test3</install_path>
         <publisher>Red Hat Inc.</publisher>
       </application>
         <install_path>C:\Program Files\Red Hat\test3</install_path>
         <publisher>Red Hat Inc.</publisher>
       </application>
+      <application>
+        <name>test4</name>
+        <display_name>Test4 is not real software</display_name>
+        <version>1.2.6</version>
+        <publisher>Red Hat Inc.</publisher>
+        <description>WOW6432node is where 32 bit emulated apps are installed on 64 bit Windows</description>
+      </application>
     </applications>
   </operatingsystem>
 </operatingsystems>
     </applications>
   </operatingsystem>
 </operatingsystems>
index 3a8ede6..238e6e5 100644 (file)
@@ -2460,15 +2460,17 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
   return ret;
 }
 
   return ret;
 }
 
-/* XXX We already download the SOFTWARE hive when doing general
- * inspection.  We could avoid this second download of the same file
- * by caching these entries in the handle.
- */
+static void list_applications_windows_from_path (guestfs_h *g, hive_h *h, struct guestfs_application_list *apps, const char **path, size_t path_len);
+
 static struct guestfs_application_list *
 list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
 {
   TMP_TEMPLATE_ON_STACK (software_local);
 
 static struct guestfs_application_list *
 list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
 {
   TMP_TEMPLATE_ON_STACK (software_local);
 
+  /* XXX We already download the SOFTWARE hive when doing general
+   * inspection.  We could avoid this second download of the same file
+   * by caching these entries in the handle.
+   */
   size_t len = strlen (fs->windows_systemroot) + 64;
   char software[len];
   snprintf (software, len, "%s/system32/config/software",
   size_t len = strlen (fs->windows_systemroot) + 64;
   char software[len];
   snprintf (software, len, "%s/system32/config/software",
@@ -2481,45 +2483,72 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
      */
     return 0;
 
      */
     return 0;
 
-  struct guestfs_application_list *apps = NULL, *ret = NULL;
+  struct guestfs_application_list *ret = NULL;
   hive_h *h = NULL;
   hive_h *h = NULL;
-  hive_node_h *children = NULL;
 
   if (download_to_tmp (g, software_path, software_local,
                        MAX_REGISTRY_SIZE) == -1)
     goto out;
 
 
   if (download_to_tmp (g, software_path, software_local,
                        MAX_REGISTRY_SIZE) == -1)
     goto out;
 
+  free (software_path);
+  software_path = NULL;
+
   h = hivex_open (software_local, g->verbose ? HIVEX_OPEN_VERBOSE : 0);
   if (h == NULL) {
     perrorf (g, "hivex_open");
     goto out;
   }
 
   h = hivex_open (software_local, g->verbose ? HIVEX_OPEN_VERBOSE : 0);
   if (h == NULL) {
     perrorf (g, "hivex_open");
     goto out;
   }
 
-  hive_node_h node = hivex_root (h);
+  /* Allocate apps list. */
+  ret = safe_malloc (g, sizeof *ret);
+  ret->len = 0;
+  ret->val = NULL;
+
+  /* Ordinary native applications. */
   const char *hivepath[] =
     { "Microsoft", "Windows", "CurrentVersion", "Uninstall" };
   const char *hivepath[] =
     { "Microsoft", "Windows", "CurrentVersion", "Uninstall" };
+  list_applications_windows_from_path (g, h, ret, hivepath,
+                                       sizeof hivepath / sizeof hivepath[0]);
+
+  /* 32-bit emulated Windows apps running on the WOW64 emulator.
+   * http://support.microsoft.com/kb/896459 (RHBZ#692545).
+   */
+  const char *hivepath2[] =
+    { "WOW6432node", "Microsoft", "Windows", "CurrentVersion", "Uninstall" };
+  list_applications_windows_from_path (g, h, ret, hivepath2,
+                                       sizeof hivepath2 / sizeof hivepath2[0]);
+
+ out:
+  if (h) hivex_close (h);
+  free (software_path);
+
+  /* Delete the temporary file. */
+  unlink (software_local);
+#undef software_local_len
+
+  return ret;
+}
+
+static void
+list_applications_windows_from_path (guestfs_h *g, hive_h *h,
+                                     struct guestfs_application_list *apps,
+                                     const char **path, size_t path_len)
+{
+  hive_node_h *children = NULL;
+  hive_node_h node;
   size_t i;
   size_t i;
-  for (i = 0;
-       node != 0 && i < sizeof hivepath / sizeof hivepath[0];
-       ++i) {
-    node = hivex_node_get_child (h, node, hivepath[i]);
-  }
 
 
-  if (node == 0) {
-    perrorf (g, "hivex: cannot locate HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
-    goto out;
-  }
+  node = hivex_root (h);
 
 
-  children = hivex_node_children (h, node);
-  if (children == NULL) {
-    perrorf (g, "hivex_node_children");
-    goto out;
-  }
+  for (i = 0; node != 0 && i < path_len; ++i)
+    node = hivex_node_get_child (h, node, path[i]);
 
 
-  /* Allocate 'apps' list. */
-  apps = safe_malloc (g, sizeof *apps);
-  apps->len = 0;
-  apps->val = NULL;
+  if (node == 0)
+    return;
+
+  children = hivex_node_children (h, node);
+  if (children == NULL)
+    return;
 
   /* Consider any child node that has a DisplayName key.
    * See also:
 
   /* Consider any child node that has a DisplayName key.
    * See also:
@@ -2539,10 +2568,8 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
      * display name is not language-independent, so it cannot be used.
      */
     name = hivex_node_name (h, children[i]);
      * display name is not language-independent, so it cannot be used.
      */
     name = hivex_node_name (h, children[i]);
-    if (name == NULL) {
-      perrorf (g, "hivex_node_get_name");
-      goto out;
-    }
+    if (name == NULL)
+      continue;
 
     value = hivex_node_get_value (h, children[i], "DisplayName");
     if (value) {
 
     value = hivex_node_get_value (h, children[i], "DisplayName");
     if (value) {
@@ -2583,20 +2610,7 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
     free (comments);
   }
 
     free (comments);
   }
 
-  ret = apps;
-
- out:
-  if (ret == NULL && apps != NULL)
-    guestfs_free_application_list (apps);
-  if (h) hivex_close (h);
   free (children);
   free (children);
-  free (software_path);
-
-  /* Free up the temporary file. */
-  unlink (software_local);
-#undef software_local_len
-
-  return ret;
 }
 
 static void
 }
 
 static void