Skip to content

Commit 202b025

Browse files
committed
Continue code
1 parent 1b70d3a commit 202b025

File tree

6 files changed

+295
-204
lines changed

6 files changed

+295
-204
lines changed

lib/FusionInventory/Agent/Task/Inventory/Win32/AntiVirus.pm

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -461,31 +461,26 @@ sub _setNortonInfos {
461461
sub _getSoftwareRegistryKeys {
462462
my ($base, $values, $callback) = @_;
463463

464-
my $reg;
464+
my %reg;
465465
if (is64bit()) {
466-
$reg = getRegistryKey(
467-
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/'.$base,
468-
wmiopts => { # Only used for remote WMI optimization
469-
values => $values
470-
}
466+
my %reg = getNewRegistryValues(
467+
root => "HKEY_LOCAL_MACHINE",
468+
path => 'SOFTWARE/Wow6432Node/'.$base
471469
);
472-
if ($reg) {
470+
if (%reg) {
473471
if ($callback) {
474-
my $filter = &{$callback}($reg);
472+
my $filter = &{$callback}(%reg);
475473
return $filter if $filter;
476474
} else {
477-
return $reg;
475+
return %reg;
478476
}
479477
}
480478
}
481-
482-
$reg = getRegistryKey(
483-
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/'.$base,
484-
wmiopts => { # Only used for remote WMI optimization
485-
values => $values
486-
}
479+
my %reg = getNewRegistryValues(
480+
root => "HKEY_LOCAL_MACHINE",
481+
path => 'SOFTWARE/'.$base
487482
);
488-
return ($callback && $reg) ? &{$callback}($reg) : $reg;
483+
return ($callback && %reg) ? &{$callback}(%reg) : %reg;
489484
}
490485

491486
1;

lib/FusionInventory/Agent/Task/Inventory/Win32/CPU.pm

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ sub _getCPUs {
5353
my @dmidecodeInfos = $remotewmi || Win32::GetOSName() eq 'Win2003' ?
5454
() : getCpusFromDmidecode();
5555

56-
# the CPU description in WMI is false, we use the registry instead
57-
my $registryInfos = getRegistryKey(
58-
path => "HKEY_LOCAL_MACHINE/Hardware/Description/System/CentralProcessor",
59-
wmiopts => { # Only used for remote WMI optimization
60-
values => [ qw/Identifier ProcessorNameString VendorIdentifier/ ]
61-
}
56+
my %registryInfos = getNewRegistryAll(
57+
logger => $params{logger},
58+
root => "HKEY_LOCAL_MACHINE",
59+
path => "Hardware/Description/System/CentralProcessor",
60+
%params
6261
);
6362

6463
my $cpuId = 0;
@@ -77,26 +76,26 @@ sub _getCPUs {
7776
)) {
7877

7978
my $dmidecodeInfo = $dmidecodeInfos[$cpuId];
80-
my $registryInfo = $registryInfos->{"$logicalId/"};
79+
my $registryInfo = $registryInfos{"$logicalId"};
8180

8281
# Compute WMI threads for this CPU if not available in dmidecode, this is the case on win2003r2 with 932370 hotfix applied (see #2894)
8382
my $wmi_threads = !$dmidecodeInfo->{THREAD} && $object->{NumberOfCores} ? $object->{NumberOfLogicalProcessors}/$object->{NumberOfCores} : undef;
8483

8584
# Split CPUID from its value inside registry
86-
my @splitted_identifier = split(/ |\n/, $registryInfo->{'/Identifier'} || $object->{Description});
85+
my @splitted_identifier = split(/ |\n/, $registryInfo->{Identifier} || $object->{Description});
8786

8887
my $name = $dmidecodeInfo->{NAME};
8988
unless ($name) {
90-
$name = trimWhitespace($registryInfo->{'/ProcessorNameString'} || $object->{Name});
89+
$name = trimWhitespace($registryInfo->{ProcessorNameString} || $object->{Name});
9190
$name =~ s/\((R|TM)\)//gi if $name;
9291
}
9392

9493
my $cpu = {
9594
CORE => $dmidecodeInfo->{CORE} || $object->{NumberOfCores},
9695
THREAD => $dmidecodeInfo->{THREAD} || $wmi_threads,
97-
DESCRIPTION => $dmidecodeInfo->{DESCRIPTION} || $registryInfo->{'/Identifier'} || $object->{Description},
96+
DESCRIPTION => $dmidecodeInfo->{DESCRIPTION} || $registryInfo->{Identifier} || $object->{Description},
9897
NAME => $name,
99-
MANUFACTURER => $dmidecodeInfo->{MANUFACTURER} || getCanonicalManufacturer($registryInfo->{'/VendorIdentifier'} || $object->{Manufacturer}),
98+
MANUFACTURER => $dmidecodeInfo->{MANUFACTURER} || getCanonicalManufacturer($registryInfo->{VendorIdentifier} || $object->{Manufacturer}),
10099
SERIAL => $dmidecodeInfo->{SERIAL} || $object->{SerialNumber},
101100
SPEED => $dmidecodeInfo->{SPEED} || $object->{MaxClockSpeed},
102101
FAMILYNUMBER => $dmidecodeInfo->{FAMILYNUMBER} || $splitted_identifier[2],

lib/FusionInventory/Agent/Task/Inventory/Win32/License.pm

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,26 @@ sub doInventory {
3636

3737
my @licenses;
3838

39-
my $officeKey = getRegistryKey(
40-
path => "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Office"
39+
my %officeKey = getNewRegistryAll(
40+
logger => $params{logger},
41+
root => "HKEY_LOCAL_MACHINE",
42+
path => "SOFTWARE/Microsoft/Office",
43+
%params
4144
);
42-
_scanOfficeLicences($officeKey) if $officeKey;
45+
46+
_scanOfficeLicences(%officeKey) if %officeKey;
4347

4448
my $fileAdobe = 'C:\Program Files\Common Files\Adobe\Adobe PCD\cache\cache.db';
4549
if (is64bit()) {
4650
$fileAdobe = 'C:\Program Files (x86)\Common Files\Adobe\Adobe PCD\cache\cache.db';
47-
my $officeKey32 = getRegistryKey(
48-
path => "HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/Office"
51+
my %officeKey32 = getNewRegistryAll(
52+
logger => $params{logger},
53+
root => "HKEY_LOCAL_MACHINE",
54+
path => "SOFTWARE/Wow6432Node/Microsoft/Office",
55+
%params
4956
);
50-
_scanOfficeLicences($officeKey32) if $officeKey32;
57+
58+
_scanOfficeLicences(%officeKey32) if %officeKey32;
5159
}
5260

5361
push @licenses, getAdobeLicensesWithoutSqlite($fileAdobe) if (-e $fileAdobe);
@@ -128,7 +136,7 @@ sub _scanOfficeLicences {
128136
# └── ...
129137

130138
foreach my $versionKey (keys %{$key}) {
131-
my $registrationKey = $key->{$versionKey}->{'Registration/'};
139+
my $registrationKey = $key{$versionKey}->{Registration};
132140
next unless $registrationKey;
133141

134142
foreach my $uuidKey (keys %{$registrationKey}) {

lib/FusionInventory/Agent/Task/Inventory/Win32/Networks.pm

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ sub doInventory {
2727
my $inventory = $params{inventory};
2828
my (@gateways, @dns, @ips);
2929

30-
my $keys;
30+
my %keys;
3131

3232
foreach my $interface (getInterfaces()) {
3333
push @gateways, $interface->{IPGATEWAY}
@@ -44,14 +44,13 @@ sub doInventory {
4444
delete $interface->{GUID};
4545

4646
# Don't reload registry keys between interfaces checks
47-
$keys = getRegistryKey(
48-
path => "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Network/{4D36E972-E325-11CE-BFC1-08002BE10318}",
49-
wmiopts => { # Only used for remote WMI optimization
50-
values => [ qw/PnpInstanceID MediaSubType/ ]
51-
}
52-
) unless $keys;
47+
%keys = getNewRegistryAll(
48+
logger => $params{logger},
49+
root => "HKEY_LOCAL_MACHINE",
50+
path => "SYSTEM/CurrentControlSet/Control/Network/{4D36E972-E325-11CE-BFC1-08002BE10318}",
51+
) unless %keys;
5352

54-
$interface->{TYPE} = _getMediaType($interface->{PNPDEVICEID}, $keys);
53+
$interface->{TYPE} = _getMediaType($interface->{PNPDEVICEID}, %keys);
5554

5655
$inventory->addEntry(
5756
section => 'NETWORKS',
@@ -68,23 +67,23 @@ sub doInventory {
6867
}
6968

7069
sub _getMediaType {
71-
my ($deviceid, $keys) = @_;
70+
my ($deviceid, %keys) = @_;
7271

73-
return unless defined $deviceid && $keys;
72+
return unless defined $deviceid && %keys;
7473

7574
my $subtype;
7675

77-
foreach my $subkey_name (keys %{$keys}) {
76+
foreach my $subkey_name (keys %keys) {
7877
# skip variables
7978
next if $subkey_name =~ m{^/};
80-
my $subkey_connection = $keys->{$subkey_name}->{'Connection/'}
79+
my $subkey_connection = $keys{$subkey_name}->{Connection}
8180
or next;
82-
my $subkey_deviceid = $subkey_connection->{'/PnpInstanceID'}
81+
my $subkey_deviceid = $subkey_connection->{PnpInstanceID}
8382
or next;
8483
# Normalize PnpInstanceID
8584
$subkey_deviceid =~ s/\\\\/\\/g;
8685
if (lc($subkey_deviceid) eq lc($deviceid)) {
87-
$subtype = $subkey_connection->{'/MediaSubType'};
86+
$subtype = $subkey_connection->{MediaSubType};
8887
last;
8988
}
9089
}

lib/FusionInventory/Agent/Task/Inventory/Win32/Softwares.pm

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use FusionInventory::Agent::Tools;
1515
use FusionInventory::Agent::Tools::Win32;
1616
use FusionInventory::Agent::Tools::Win32::Constants;
1717
use FusionInventory::Agent::Tools::Win32::LoadIndirectString;
18+
use Data::Dumper;
1819

1920
our $runAfter = ["FusionInventory::Agent::Task::Inventory::Win32::OS"];
2021

@@ -66,7 +67,7 @@ sub doInventory {
6667

6768
if ($is64bit) {
6869
my $softwares32 = _getSoftwaresList(
69-
path => "HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/Windows/CurrentVersion/Uninstall",
70+
path => "SOFTWARE/Wow6432Node/Microsoft/Windows/CurrentVersion/Uninstall",
7071
is64bit => 0
7172
) || [];
7273
foreach my $software (@$softwares32) {
@@ -120,12 +121,13 @@ sub _loadUserSoftware {
120121
my $userName = $userList->{$profileName}
121122
or next;
122123

123-
my $profileSoft = "HKEY_USERS/$profileName/SOFTWARE/";
124+
my $profileSoft = "$profileName/SOFTWARE/";
124125
$profileSoft .= is64bit() && !$is64bit ?
125126
"Wow6432Node/Microsoft/Windows/CurrentVersion/Uninstall" :
126127
"Microsoft/Windows/CurrentVersion/Uninstall";
127128

128129
my $softwares = _getSoftwaresList(
130+
root => "HKEY_USERS",
129131
path => $profileSoft,
130132
is64bit => $is64bit,
131133
userid => $profileName,
@@ -143,22 +145,22 @@ sub _loadUserSoftware {
143145
sub _getUsersFromRegistry {
144146
my (%params) = @_;
145147

146-
my $profileList = getRegistryKey(
147-
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/ProfileList',
148-
wmiopts => { # Only used for remote WMI optimization
149-
values => [ qw/ProfileImagePath Sid/ ],
150-
}
148+
my %profileList = getNewRegistryAll(
149+
logger => $params{logger},
150+
root => "HKEY_LOCAL_MACHINE",
151+
path => "SOFTWARE/Microsoft/Windows NT/CurrentVersion/ProfileList",
152+
%params
151153
);
152154

153-
next unless $profileList;
155+
return unless %profileList;
154156

155157
my $userList;
156-
foreach my $profileName (keys %$profileList) {
158+
foreach my $profileName (keys %profileList) {
157159
next unless $profileName =~ m{/$};
158160
next unless length($profileName) > 10;
159161

160-
my $profilePath = $profileList->{$profileName}{'/ProfileImagePath'};
161-
my $sid = $profileList->{$profileName}{'/Sid'};
162+
my $profilePath = $profileList{$profileName}->{ProfileImagePath};
163+
my $sid = $profileList{$profileName}->{Sid};
162164
next unless $sid;
163165
next unless $profilePath;
164166
my $user = basename($profilePath);
@@ -196,9 +198,7 @@ sub _keyLastWriteDateString {
196198

197199
return unless ($OSNAME eq 'MSWin32');
198200

199-
return unless (ref($key) eq "Win32::TieRegistry");
200-
201-
my @lastWrite = FileTimeToSystemTime($key->Information("LastWrite"));
201+
my @lastWrite = FileTimeToSystemTime($key->{_lastWrite});
202202

203203
return unless (@lastWrite > 3);
204204

@@ -208,53 +208,52 @@ sub _keyLastWriteDateString {
208208
sub _getSoftwaresList {
209209
my (%params) = @_;
210210

211-
my $softwares = getRegistryKey(
212-
path => "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall",
213-
wmiopts => { # Only used for remote WMI optimization
214-
values => [ qw/
215-
DisplayName Comments HelpLink ReleaseType DisplayVersion
216-
Publisher URLInfoAbout UninstallString InstallDate MinorVersion
217-
MajorVersion NoRemove SystemComponent
218-
/ ]
219-
},
211+
my $path = "SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall";
212+
my $root = "HKEY_LOCAL_MACHINE";
213+
if (defined $params{path}) {
214+
$path = $params{path};
215+
}
216+
if (defined $params{root}) {
217+
$root = $params{root};
218+
}
219+
220+
my %softwares = getNewRegistryAll(
221+
logger => $params{logger},
222+
root => $root,
223+
path => $path,
220224
%params
221225
);
226+
return unless %softwares;
222227

223228
my @list;
224229

225-
return unless $softwares;
226-
227-
foreach my $rawGuid (keys %$softwares) {
230+
foreach my $rawGuid (keys %softwares) {
228231
# skip variables
229232
next if $rawGuid =~ m{^/};
230233

231234
# only keep subkeys with more than 1 value
232-
my $data = $softwares->{$rawGuid};
235+
my $data = $softwares{$rawGuid};
233236
next unless keys %$data > 1;
234237

235-
my $guid = $rawGuid;
236-
$guid =~ s/\/$//; # drop the tailing /
237-
238238
my $software = {
239239
FROM => "registry",
240-
NAME => encodeFromRegistry($data->{'/DisplayName'}) ||
241-
encodeFromRegistry($guid), # folder name
242-
COMMENTS => encodeFromRegistry($data->{'/Comments'}),
243-
HELPLINK => encodeFromRegistry($data->{'/HelpLink'}),
244-
RELEASE_TYPE => encodeFromRegistry($data->{'/ReleaseType'}),
245-
VERSION => encodeFromRegistry($data->{'/DisplayVersion'}),
246-
PUBLISHER => encodeFromRegistry($data->{'/Publisher'}),
247-
URL_INFO_ABOUT => encodeFromRegistry($data->{'/URLInfoAbout'}),
248-
UNINSTALL_STRING => encodeFromRegistry($data->{'/UninstallString'}),
249-
INSTALLDATE => _dateFormat($data->{'/InstallDate'}),
250-
VERSION_MINOR => hex2dec($data->{'/MinorVersion'}),
251-
VERSION_MAJOR => hex2dec($data->{'/MajorVersion'}),
252-
NO_REMOVE => hex2dec($data->{'/NoRemove'}),
240+
NAME => $data->{DisplayName} || $rawGuid, # folder name
241+
COMMENTS => $data->{Comments},
242+
HELPLINK => $data->{HelpLink},
243+
RELEASE_TYPE => $data->{ReleaseType},
244+
VERSION => $data->{DisplayVersion},
245+
PUBLISHER => $data->{Publisher},
246+
URL_INFO_ABOUT => $data->{URLInfoAbout},
247+
UNINSTALL_STRING => $data->{UninstallString},
248+
INSTALLDATE => _dateFormat($data->{InstallDate}),
249+
VERSION_MINOR => $data->{MinorVersion},
250+
VERSION_MAJOR => $data->{MajorVersion},
251+
NO_REMOVE => $data->{NoRemove},
253252
ARCH => $params{is64bit} ? 'x86_64' : 'i586',
254-
GUID => $guid,
253+
GUID => $rawGuid,
255254
USERNAME => $params{username},
256255
USERID => $params{userid},
257-
SYSTEM_CATEGORY => $data->{'/SystemComponent'} && hex2dec($data->{'/SystemComponent'}) ?
256+
SYSTEM_CATEGORY => $data->{SystemComponent} ?
258257
CATEGORY_SYSTEM_COMPONENT : CATEGORY_APPLICATION
259258
};
260259

@@ -347,17 +346,17 @@ sub _processMSIE {
347346
"Internet Explorer (64bit)" : "Internet Explorer";
348347

349348
# Will use key last write date as INSTALLDATE
350-
my $installedkey = getRegistryKey(
349+
my %installedkey = getNewRegistryValues(
350+
logger => $params{logger},
351+
root => "HKEY_LOCAL_MACHINE",
351352
path => is64bit() && !$params{is64bit} ?
352-
"HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/Internet Explorer" :
353-
"HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Internet Explorer",
354-
wmiopts => { # Only used for remote WMI optimization
355-
values => [ qw/svcVersion Version/ ],
356-
subkeys => 0
357-
}
353+
"SOFTWARE/Wow6432Node/Microsoft/Internet Explorer" :
354+
"SOFTWARE/Microsoft/Internet Explorer",
355+
%params
358356
);
359357

360-
my $version = $installedkey->{"/svcVersion"} || $installedkey->{"/Version"};
358+
359+
my $version = $installedkey{svcVersion} || $installedkey{Version};
361360

362361
return unless $version; # Not installed
363362

@@ -368,8 +367,8 @@ sub _processMSIE {
368367
ARCH => $params{is64bit} ? 'x86_64' : 'i586',
369368
NAME => $name,
370369
VERSION => $version,
371-
PUBLISHER => "Microsoft Corporation",
372-
INSTALLDATE => _dateFormat(_keyLastWriteDateString($installedkey))
370+
PUBLISHER => "Microsoft Corporation"
371+
# INSTALLDATE => _dateFormat(_keyLastWriteDateString(%installedkey))
373372
}
374373
);
375374

0 commit comments

Comments
 (0)