| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use File::Basename; | ||
| 6 | use Getopt::Long; | ||
| 7 | use Parse::Win32Registry 0.50 qw(hexdump); | ||
| 8 | |||
| 9 | binmode(STDOUT, ':utf8'); | ||
| 10 | |||
| 11 | Getopt::Long::Configure('bundling'); | ||
| 12 | |||
| 13 | GetOptions('recurse|r' => \my $recurse, | ||
| 14 | 'values|v' => \my $show_values, | ||
| 15 | 'hexdump|x' => \my $show_hexdump, | ||
| 16 | 'class-name|c' => \my $show_class_name, | ||
| 17 | 'security|s' => \my $show_security, | ||
| 18 | 'owner|o' => \my $show_owner); | ||
| 19 | |||
| 20 | my $filename = shift or die usage(); | ||
| 21 | my $initial_key_path = shift; | ||
| 22 | |||
| 23 | my $registry = Parse::Win32Registry->new($filename) | ||
| 24 | or die "'$filename' is not a registry file\n"; | ||
| 25 | my $root_key = $registry->get_root_key | ||
| 26 | or die "Could not get root key of '$filename'\n"; | ||
| 27 | |||
| 28 | if (defined($initial_key_path)) { | ||
| 29 | $root_key = $root_key->get_subkey($initial_key_path); | ||
| 30 | if (!defined($root_key)) { | ||
| 31 | die "Could not locate the key '$initial_key_path' in '$filename'\n"; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | traverse($root_key); | ||
| 36 | |||
| 37 | sub traverse { | ||
| 38 | my $key = shift; | ||
| 39 | |||
| 40 | print $key->as_string; | ||
| 41 | if ($show_class_name) { | ||
| 42 | my $class_name = $key->get_class_name; | ||
| 43 | if (defined $class_name) { | ||
| 44 | print " '$class_name'"; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | if ($show_owner) { | ||
| 48 | my $security = $key->get_security; | ||
| 49 | if (defined $security) { | ||
| 50 | my $sd = $security->get_security_descriptor; | ||
| 51 | if (defined $sd) { | ||
| 52 | my $owner = $sd->get_owner; | ||
| 53 | if (defined $owner) { | ||
| 54 | print " ", $owner->as_string; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | print "\n"; | ||
| 60 | if ($show_security) { | ||
| 61 | my $security = $key->get_security; | ||
| 62 | if (defined $security) { | ||
| 63 | my $sd = $security->get_security_descriptor; | ||
| 64 | if (defined $sd) { | ||
| 65 | print $sd->as_stanza; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | # Display names of subkeys if we are not descending the tree | ||
| 71 | if (!$recurse) { | ||
| 72 | foreach my $subkey ($key->get_list_of_subkeys) { | ||
| 73 | print "..\\", $subkey->get_name, "\n"; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | if ($show_values) { | ||
| 78 | foreach my $value ($key->get_list_of_values) { | ||
| 79 | if (!$show_hexdump) { | ||
| 80 | print $value->as_string, "\n"; | ||
| 81 | } | ||
| 82 | else { | ||
| 83 | my $value_name = $value->get_name; | ||
| 84 | $value_name = "(Default)" if $value_name eq ""; | ||
| 85 | my $value_type = $value->get_type_as_string; | ||
| 86 | print "$value_name ($value_type):\n"; | ||
| 87 | print hexdump($value->get_raw_data); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | if ($show_security || $show_values) { | ||
| 93 | print "\n"; | ||
| 94 | } | ||
| 95 | |||
| 96 | if ($recurse) { | ||
| 97 | foreach my $subkey ($key->get_list_of_subkeys) { | ||
| 98 | traverse($subkey); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | sub usage { | ||
| 104 | my $script_name = basename $0; | ||
| 105 | return <<USAGE; | ||
| 106 | $script_name for Parse::Win32Registry $Parse::Win32Registry::VERSION | ||
| 107 | |||
| 108 | Dumps the keys and values of a registry file. | ||
| 109 | |||
| 110 | $script_name <filename> [subkey] [-r] [-v] [-x] [-c] [-s] [-o] | ||
| 111 | -r or --recurse traverse all child keys from the root key | ||
| 112 | or the subkey specified | ||
| 113 | -v or --values display values | ||
| 114 | -x or --hexdump display value data as a hex dump | ||
| 115 | -c or --class-name display the class name for the key (if present) | ||
| 116 | -s or --security display the security information for the key, | ||
| 117 | including the owner and group SIDs, | ||
| 118 | and the system and discretionary ACLs (if present) | ||
| 119 | -o or --owner display the owner SID for the key (if present) | ||
| 120 | USAGE | ||
| 121 | } |