| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use File::Basename; | ||
| 6 | use Parse::Win32Registry 0.50; | ||
| 7 | |||
| 8 | binmode(STDOUT, ':utf8'); | ||
| 9 | |||
| 10 | my $filename = shift or die usage(); | ||
| 11 | |||
| 12 | my $registry = Parse::Win32Registry->new($filename) | ||
| 13 | or die "'$filename' is not a registry file\n"; | ||
| 14 | my $root_key = $registry->get_root_key | ||
| 15 | or die "Could not get root key of '$filename'\n"; | ||
| 16 | |||
| 17 | # Use the root key to get the first security entry | ||
| 18 | my $security = $root_key->get_security | ||
| 19 | or die "Root key of '$filename' does not have any security information\n"; | ||
| 20 | |||
| 21 | my %offsets_seen = (); | ||
| 22 | my $offset = $security->get_offset; | ||
| 23 | while (!exists $offsets_seen{$offset}) { | ||
| 24 | $offsets_seen{$offset} = undef; # value not required | ||
| 25 | |||
| 26 | printf "Security at offset 0x%x, %d references\n", | ||
| 27 | $offset, $security->get_reference_count; | ||
| 28 | my $sd = $security->get_security_descriptor; | ||
| 29 | print $sd->as_stanza; | ||
| 30 | print "\n"; | ||
| 31 | |||
| 32 | $security = $security->get_next; | ||
| 33 | if (!defined $security) { | ||
| 34 | die "Unable to get next security entry\n"; | ||
| 35 | } | ||
| 36 | $offset = $security->get_offset; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub usage { | ||
| 40 | my $script_name = basename $0; | ||
| 41 | return <<USAGE; | ||
| 42 | $script_name for Parse::Win32Registry $Parse::Win32Registry::VERSION | ||
| 43 | |||
| 44 | Displays all the security entries in a registry file. | ||
| 45 | Each key contains a reference to one of these security entries. | ||
| 46 | Only Windows NT registry files contain security information. | ||
| 47 | |||
| 48 | $script_name <filename> | ||
| 49 | USAGE | ||
| 50 | } |