File: Value.pm

package info (click to toggle)
libparse-win32registry-perl 1.0-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 844 kB
  • ctags: 503
  • sloc: perl: 8,646; makefile: 8
file content (101 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package Parse::Win32Registry::Value;

use strict;
use warnings;

use base qw(Parse::Win32Registry::Entry);

use Carp;
use Parse::Win32Registry::Base qw(:all);

sub get_name {
    my $self = shift;

    return $self->{_name};
}

sub get_type {
    my $self = shift;

    return $self->{_type};
}

our @Types = qw(
    REG_NONE
    REG_SZ
    REG_EXPAND_SZ
    REG_BINARY
    REG_DWORD
    REG_DWORD_BIG_ENDIAN
    REG_LINK
    REG_MULTI_SZ
    REG_RESOURCE_LIST
    REG_FULL_RESOURCE_DESCRIPTOR
    REG_RESOURCE_REQUIREMENTS_LIST
    REG_QWORD
);

sub get_type_as_string {
    my $self = shift;

    my $type = $self->get_type;
    if (exists $Types[$type]) {
        return $Types[$type];
    }
    else {
        # Return unrecognised types as REG_<number>
        # REGEDIT displays them as formatted hex numbers, e.g. 0x1f4
        return "REG_$type";
    }
}

sub get_data_as_string {
    my $self = shift;

    my $type = $self->get_type;
    my $data = $self->get_data;
    if (!defined($data)) {
        return '(invalid data)';
    }
    elsif (length($data) == 0) {
        return '(no data)';
    }
    elsif ($type == REG_SZ || $type == REG_EXPAND_SZ) {
        return $data;
    }
    elsif ($type == REG_MULTI_SZ) {
        my @data = $self->get_data;
        my $i = 0;
        return join(' ', map { "[" . $i++ . "] $_" } @data);
    }
    elsif ($type == REG_DWORD || $type == REG_DWORD_BIG_ENDIAN) {
        return sprintf '0x%08x (%u)', $data, $data;
    }
    else {
        return join(' ', unpack('(H2)*', $data));
    }
}

sub get_raw_data {
    my $self = shift;

    return $self->{_data};
}

sub as_string {
    my $self = shift;

    my $name = $self->get_name;
    $name = '(Default)' if $name eq '';
    my $type_as_string = $self->get_type_as_string;
    my $data_as_string = $self->get_data_as_string;
    return "$name ($type_as_string) = $data_as_string";
}

sub print_summary {
    my $self = shift;

    print $self->as_string, "\n";
}

1;