Plagger::Plugin::CustomFeed::Win32Registry

IRCでなんぞおもしろげな話をしていたのでちょろっと書いてみた。レジストリをごにょって特定のディレクトリ内にあるキーをフィードに変換。diffとってどうこうというのもこのフェーズに入れた方がいいんだろうけど(assets内に前日のデータを保存しておいて比較、かな)、とりあえずproof of conceptということで。まじめにつくるなら値のタイプを見てバイナリかどうかを判定しないとマズイし、diffをとりやすいようキーとエントリの振り分けを変えた方がいいかもしれない。

ああ、PODにも書いたけど、これを使った結果、最悪マシンが動かなくなっても一切関知しませんので、何をやっているかわかる人だけ使ってくださいね。警告はしましたよ(笑)

package Plagger::Plugin::CustomFeed::Win32Registry;

use strict;
use base qw( Plagger::Plugin );

use Win32::TieRegistry;
use Encode;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'subscription.load' => \&load,
    );
}

sub load {
    my($self, $context) = @_;

    my $feed = Plagger::Feed->new;
       $feed->aggregator(sub { $self->aggregate(@_) });
    $context->subscription->add($feed);
}

sub aggregate {
    my($self, $context, $args) = @_;

    $Registry->Delimiter('/');

    my $feed = Plagger::Feed->new;
       $feed->type('registry');
       $feed->title(Plagger::Date->now(timezone => $context->conf->{timezone}));

    $context->log(info => "going to read registry");

    foreach my $key (@{ $self->conf->{key} }) {
        $context->log(debug => "reading $key");
        my $distkey = $Registry->{$key} or do {
            $context->log(warn => "Registry doesn't have $key key.");
            next;
        };

        my @loop;
        foreach my $subkey ( keys %{ $distkey } ) {
            next if ref $distkey{$subkey};

            $context->log(debug => "reading $subkey in the $key");

            push @loop, {
                key   => $subkey,
                value => decode('cp932', $distkey->{$subkey})
            };
        }
        my $body = $self->templatize('registry.tt', { loop => \@loop });

        my $entry = Plagger::Entry->new;
           $entry->title($key);
           $entry->body($body);
        $feed->add_entry($entry);
    }
    $context->update->add($feed);
}

1;

__END__

=head1 NAME

Plagger::Plugin::CustomFeed::Win32Registry - Crawl your Win32 Registry

=head1 SYNOPSIS

  - module: CustomFeed::Win32Registry
    config:
      key:
        - LMachine/SOFTWARE/Microsoft/Windows/CurrentVersion/Run
        - CUser/Software/Microsoft/Windows/CurrentVersion/Run

=head1 CAVEATS

This plugin crawls in the system registry. Though all it does is reading, 
it may be the cause of troubles including system crashes. Don't use this
unless you have confidence in what you are doing.

=head1 AUTHOR

Kenichi Ishigaki

=head1 SEE ALSO

L<Plagger>, L<Win32::TieRegistry>

=cut
  • registry.tt
[% FOREACH e IN loop %]
[% e.key %]: [% e.value %]
[% END %]