File: ResourceData.pm

package info (click to toggle)
libwin32-exe-perl 0.17-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 472 kB
  • sloc: perl: 3,679; xml: 38; makefile: 11
file content (57 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (2)
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
# Copyright 2004 by Audrey Tang <cpan@audreyt.org>

package Win32::Exe::ResourceData;

use strict;
use base 'Win32::Exe::Base';
use constant FORMAT => (
    VirtualAddress  => 'V',
    Size	    => 'V',
    CodePage	    => 'V',
);

sub Data {
    my ($self) = @_;
    return $self->{data} if defined $self->{data};

    my $section = $self->first_parent('Resources');
    my $addr = $self->VirtualAddress or return;
    return $section->substr(
	$addr - $section->VirtualAddress,
	$self->Size
    );
}

sub SetData {
    my ($self, $data) = @_;
    $self->{data} = $data;
}

sub object {
    my ($self) = @_;
    return $self->{object};
}

sub path {
    my ($self) = @_;
    return $self->parent->path;
}

sub initialize {
    my ($self) = @_;

    my ($base) = $self->path or return;
    $base =~ /^#RT_(?!ICON$)(\w+)$/ or return;
    $self->VirtualAddress or return;

    my $data = $self->Data;
    my $class = ucfirst(lc($1));
    $class =~ s/_(\w)/\U$1/g;
    $class = $self->require_class("Resource::$class") or return;

    my $obj = $class->new(\$data, { parent => $self });
    $obj->initialize;
    $self->{object} = $obj;
}

1;