Because you are not using strict or warnings, you cannot see that DACL_SECURITY_INFORMATION is not defined. This results in $pSecDesc containing the wrong data, which cannot be decoded.
Adding this line populates $pSecDesc correctly:
use Win32 qw( DACL_SECURITY_INFORMATION );
You still need to decode the Security Descriptor; this (thrown together, barely tested) program may help:
use strict; use warnings; use Data::Dumper; $Data::Dumper::Useqq = 1; $| = 1; my $host = '127.0.0.1'; my $reg_key = 'SOFTWARE\\7-zip'; use Win32 qw( DACL_SECURITY_INFORMATION ); use Win32API::Registry 0.21 qw( :ALL ); # Get the Security Descriptor my $reg_api; RegConnectRegistry( $host, HKEY_LOCAL_MACHINE, $reg_api ) or die $^E; my $key; RegOpenKeyEx( $reg_api, $reg_key, 0, KEY_READ, $key ) or die $^E; my $pSecDesc; RegGetKeySecurity( $key, DACL_SECURITY_INFORMATION, $pSecDesc ) or die + $^E; # Print the raw DACL. print "\n", Dumper $pSecDesc; # Decode the Security Descriptor use Win32::API; use constant SDDL_REVISION_1 => 0x1; my $ConvertSDToString = Win32::API->new( 'ADVAPI32', 'ConvertSecurityDescriptorToStringSecurityDescriptor', ['P', 'N', 'N', 'P', 'N'], 'N', ); my $ptr_strSDDL = pack 'L', 0; # DWORD; my $ObjSD = $ConvertSDToString->Call( $pSecDesc, SDDL_REVISION_1, 0xF, $ptr_strSDDL, 0, ) or die $^E; my $strSDDL = unpack 'p', $ptr_strSDDL; # Print the decoded DACL. print "\n", Dumper $strSDDL;
In reply to Re: Win32API::Registry::RegGetKeySecurity how to unpack the structure of $pSecDesc?
by Util
in thread Win32API::Registry::RegGetKeySecurity how to unpack the structure of $pSecDesc?
by Sioln
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |