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.
Merge pull request fusioninventory#555 from TECLIB/feature/win32-uwp-…
…support Add UWP/APPX/Windows Store software inventory
- Loading branch information
Showing
5 changed files
with
448 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
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,47 @@ | ||
package FusionInventory::Agent::Tools::Win32::API; | ||
|
||
use warnings; | ||
use strict; | ||
|
||
use English qw(-no_match_vars); | ||
use UNIVERSAL::require; | ||
|
||
use FusionInventory::Agent::Logger; | ||
|
||
sub new { | ||
my ($class, %params) = @_; | ||
|
||
my $self = { | ||
logger => $params{logger} || FusionInventory::Agent::Logger->new() | ||
}; | ||
bless $self, $class; | ||
|
||
# Load Win32::API as late as possible | ||
Win32::API->require() or return; | ||
|
||
my $api; | ||
eval { | ||
$api = Win32::API->new(@{$params{win32api}}); | ||
}; | ||
$self->{logger}->debug2("win32 api load failure: $EVAL_ERROR") if $EVAL_ERROR; | ||
|
||
$self->{_api} = $api if $api; | ||
|
||
return $self; | ||
} | ||
|
||
sub Call { | ||
my $self = shift; | ||
|
||
return unless $self->{_api}; | ||
|
||
my $ret; | ||
eval { | ||
$ret = $self->{_api}->Call(@_); | ||
}; | ||
$self->{logger}->debug2("win32 api call failure: $EVAL_ERROR") if $EVAL_ERROR; | ||
|
||
return $ret; | ||
} | ||
|
||
1; |
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
package FusionInventory::Agent::Tools::Win32::LoadIndirectString; | ||
|
||
use warnings; | ||
use strict; | ||
|
||
use parent 'Exporter'; | ||
|
||
use FusionInventory::Agent::Tools::Win32::API; | ||
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; | ||
|
||
unless ($apiSHLoadIndirectString) { | ||
$apiSHLoadIndirectString = FusionInventory::Agent::Tools::Win32::API->new( | ||
win32api => [ | ||
'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.