forked from fusioninventory/fusioninventory-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(inventory): Add windows store inventory
Add UWP/APPX/Windows Store software inventory Add API to convert multibytes string to and from widechar strings Add API to load indirect strings Closes fusioninventory#299
- Loading branch information
Showing
4 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
lib/FusionInventory/Agent/Tools/Win32/LoadIndirectString.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package FusionInventory::Agent::Tools::Win32::LoadIndirectString; | ||
|
||
use warnings; | ||
use strict; | ||
|
||
use parent 'Exporter'; | ||
|
||
use FusionInventory::Agent::Tools::Win32::WideChar; | ||
|
||
our @EXPORT = qw( | ||
SHLoadIndirectString | ||
); | ||
|
||
my $apiSHLoadIndirectString; | ||
|
||
sub SHLoadIndirectString { | ||
my ($string) = @_; | ||
|
||
return unless $string; | ||
|
||
my $wstring = MultiByteToWideChar($string) | ||
or return; | ||
|
||
# Load Win32::API as late as possible | ||
Win32::API->require() or return; | ||
|
||
unless ($apiSHLoadIndirectString) { | ||
eval { | ||
$apiSHLoadIndirectString = Win32::API->new( | ||
'shlwapi', | ||
'SHLoadIndirectString', | ||
[ 'P', 'P', 'I', 'I' ], | ||
'N' | ||
); | ||
}; | ||
} | ||
|
||
return unless $apiSHLoadIndirectString; | ||
|
||
# Buffer size should be sufficient for our purpose | ||
my $buffer = '\0' x 4096; | ||
my $ret = $apiSHLoadIndirectString->Call( | ||
$wstring, | ||
$buffer, | ||
4096, | ||
0 | ||
); | ||
|
||
return if ($ret || !$buffer); | ||
|
||
$buffer = WideCharToMultiByte($buffer); | ||
|
||
# api returns the same string in buffer is no indirect string was found | ||
return unless ($buffer && $buffer ne $string); | ||
|
||
return $buffer ; | ||
} | ||
|
||
1; |
Oops, something went wrong.