From 2c0cdab5295f64e157d00408224174e7b5e6cd0f Mon Sep 17 00:00:00 2001 From: Valko Laszlo Date: Wed, 9 Nov 2022 00:49:55 +0100 Subject: [PATCH] Improved logging by including registry path for packages found. --- pkgtool.pm | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/pkgtool.pm b/pkgtool.pm index 9afd97b..40f509d 100644 --- a/pkgtool.pm +++ b/pkgtool.pm @@ -836,13 +836,14 @@ sub read_pkg_patches ($$$) } } -sub read_packages ($$$$) +sub read_packages ($$$$$) { - my ($packages, $registry, $wow6432, $userdata) = @_; + my ($packages, $key, $registry, $wow6432, $userdata) = @_; foreach my $name ($registry->SubKeyNames) { my $sub = $registry->{$name}; next unless defined $sub; + my $regname = $key.$name; if ($userdata) { $sub = $sub->{'InstallProperties'}; next unless defined $sub; @@ -867,7 +868,8 @@ sub read_packages ($$$$) $winid = $8.$7.$6.$5.$4.$3.$2.$1.$12.$11.$10.$9.$16.$15.$14.$13.$18.$17.$20.$19.$22.$21.$24.$23.$26.$25.$28.$27.$30.$29.$32.$31; } my $inst = { - Name => $name, + Name => $name, + RegName => $regname, WinID => $winid, Publisher => $pub, DisplayName => $dispname, @@ -948,32 +950,38 @@ sub read_installed_packages ($) delete $$db{Changed}; my $packages = {}; - my $uninst = $Registry->Open('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\', { Access => 'KEY_READ' }); + my $key = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\'; + my $uninst = $Registry->Open($key, { Access => 'KEY_READ' }); if (! defined $uninst) { print_log('global', ERROR, 'Cannot find registry entry: %s', 'HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall'); return undef; } - read_packages($packages, $uninst, 0, 0); - $uninst = $Registry->Open('HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\', { Access => 'KEY_READ' }); + read_packages($packages, $key, $uninst, 0, 0); + $key = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\'; + $uninst = $Registry->Open($key, { Access => 'KEY_READ' }); if (defined $uninst) { - read_packages($packages, $uninst, 1, 0); + read_packages($packages, $key, $uninst, 1, 0); } - $uninst = $Registry->Open('HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\', { Access => 'KEY_READ' }); + $key = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\'; + $uninst = $Registry->Open($key, { Access => 'KEY_READ' }); if (defined $uninst) { - read_packages($packages, $uninst, 0, 0); + read_packages($packages, $key, $uninst, 0, 0); } - $uninst = $Registry->Open('HKEY_CURRENT_USER\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\', { Access => 'KEY_READ' }); + $key = 'HKEY_CURRENT_USER\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\'; + $uninst = $Registry->Open($key, { Access => 'KEY_READ' }); if (defined $uninst) { - read_packages($packages, $uninst, 1, 0); + read_packages($packages, $key, $uninst, 1, 0); } my $specpackages = {}; - my $products = $Registry->Open('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\', { Access => 'KEY_READ' }); + $key = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\'; + my $products = $Registry->Open($key, { Access => 'KEY_READ' }); if (defined $products) { - read_packages($specpackages, $products, 0, 1); + read_packages($specpackages, $key, $products, 0, 1); } - $products = $Registry->Open('HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\', { Access => 'KEY_READ' }); + $key = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\'; + $products = $Registry->Open($key, { Access => 'KEY_READ' }); if (defined $products) { - read_packages($specpackages, $products, 1, 1); + read_packages($specpackages, $key, $products, 1, 1); } $$db{Installed} = $packages; $$db{InstalledSpec} = $specpackages; @@ -1491,11 +1499,13 @@ sub match_package_def ($$$) my $dispver = $$inst{DisplayVersion}; $dispver = defined $dispver && $dispver ne '' ? ' ('.$dispver.')' : ''; - print_log('global', DEBUG4, 'Trying to match package %s%s%s%s to definition %s', + print_log('global', DEBUG4, 'Trying definition %s for package %s%s%s%s at %s', + $$def{description}, $dispname, defined $$inst{SystemComponent} ? ' SC='.$$inst{SystemComponent} : '', defined $$inst{WindowsInstaller} ? ' WI='.$$inst{WindowsInstaller} : '', - $dispver, $$def{description}); + $dispver, + $$inst{RegName}); my $matchlist = $$def{'match'}; foreach my $matchentry (@$matchlist) { my $expression = $$matchentry{expression};