script/regtimeline.pl untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 99 CC 3 SCAR 16.7
CC
3
Cov
0%
traverse
12.0
usage
2.0
BEGIN
2.0
CRAP 5.3
1 #!/usr/local/bin/perl
2 use strict;
3 use warnings;
4  
5 use File::Basename;
6 use Getopt::Long;
7 use Parse::Win32Registry qw(iso8601 hexdump);
8  
9 binmode(STDOUT, ":utf8");
10  
11 Getopt::Long::Configure('bundling');
12  
13 GetOptions('last|l=f' => \my $period,
14 'values|v' => \my $show_values,
15 'hexdump|x' => \my $show_hexdump);
16  
17 my $filename = shift or die usage();
18 my $initial_key_path = shift;
19  
20 my $registry = Parse::Win32Registry->new($filename)
21 or die "'$filename' is not a registry file\n";
22 my $root_key = $registry->get_root_key
23 or die "Could not get root key of '$filename'\n";
24  
25 if (!defined($root_key->get_timestamp)) {
26 die "'$filename' needs to be an NT-based registry file\n"
27 }
28  
29 if (defined($initial_key_path)) {
30 $root_key = $root_key->get_subkey($initial_key_path);
31 if (!defined($root_key)) {
32 die "Could not locate the key '$initial_key_path' in '$filename'\n";
33 }
34 }
35  
36 warn "Ordering keys...\n";
37  
38 my $first_timestamp = 0;
39 my $last_timestamp = 0;
40 my %keys_by_timestamp = ();
41  
42 traverse($root_key);
43  
44 sub traverse {
45 my $key = shift;
46  
47 my $timestamp = $key->get_timestamp;
48 push @{$keys_by_timestamp{$timestamp}}, $key;
49 $first_timestamp = $timestamp if $timestamp < $first_timestamp;
50 $last_timestamp = $timestamp if $timestamp > $last_timestamp;
51  
52 foreach my $subkey ($key->get_list_of_subkeys) {
53 traverse($subkey);
54 }
55 }
56  
57 if ($period) {
58 $first_timestamp = $last_timestamp - $period * 86400;
59 }
60  
61 foreach my $timestamp (sort { $a <=> $b } keys %keys_by_timestamp) {
62 next if $timestamp < $first_timestamp;
63 foreach my $key (@{$keys_by_timestamp{$timestamp}}) {
64 print iso8601($timestamp), "\t", $key->get_path, "\n";
65 if ($show_values) {
66 foreach my $value ($key->get_list_of_values) {
67 if (!$show_hexdump) {
68 print "\t", $value->as_string, "\n";
69 }
70 else {
71 my $value_name = $value->get_name;
72 $value_name = "(Default)" if $value_name eq "";
73 my $value_type = $value->get_type_as_string;
74 print "\t$value_name ($value_type):\n";
75 print hexdump($value->get_raw_data);
76 }
77 }
78 print "\n";
79 }
80 }
81 }
82  
83 sub usage {
84 my $script_name = basename $0;
85 return <<USAGE;
86 $script_name for Parse::Win32Registry $Parse::Win32Registry::VERSION
87  
88 Displays the keys and values of a registry file in date order.
89  
90 $script_name <filename> [subkey] [-l <number>] [-v] [-x]
91 -l or --last display only the last <number> days
92 of registry activity
93 -v or --values display values
94 -x or --hexdump display value data as a hex dump
95 USAGE
96 }