| 1 | package Finnigan::OLE2DirectoryEntry; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings FATAL => qw( all ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = 0.0206; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Finnigan; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base 'Finnigan::Decoder'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | my $UNUSED = 0xFFFFFFFF; # -1 | |||||||||||||||||||||||||||
| 11 | 2 | my $END_OF_CHAIN = 0xFFFFFFFE; # -2 | |||||||||||||||||||||||||||
| 12 | 2 | my $FAT_SECTOR = 0xFFFFFFFD; # -3 | |||||||||||||||||||||||||||
| 13 | 2 | my $DIF_SECTOR = 0xFFFFFFFC; # -4 | |||||||||||||||||||||||||||
| 14 | 2 | my $STORAGE = 1; | |||||||||||||||||||||||||||
| 15 | 2 | my $ROOT = 5; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | my $DEPTH = -1; # for recursive directory listing | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | my %SPECIAL = ($END_OF_CHAIN => 1, $UNUSED => 1, $FAT_SECTOR => 1, $DIF_SECTOR => 1); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 5 | my ($class, $file, $index) = @_; | |||||||||||||||||||||||||||
| 23 | 5 | my $self = {file => $file, index => $index}; | |||||||||||||||||||||||||||
| 24 | 5 | bless $self, $class; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # The directory entries are organized in a red-black tree (for | ||||||||||||||||||||||||||||
| 27 | # efficiency of access). The following piece of code does an ordered | ||||||||||||||||||||||||||||
| 28 | # traversal of such a tree and creates a new tree of | ||||||||||||||||||||||||||||
| 29 | # OLE2DirectoryEntry objects whose child lists are properly ordered, | ||||||||||||||||||||||||||||
| 30 | # to simplify the code | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | my $p = $file->{properties}->[$index]; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # copy the property's data | ||||||||||||||||||||||||||||
| 35 | 5 | $self->{name} = $p->name; | |||||||||||||||||||||||||||
| 36 | 5 | $self->{type} = $p->type; | |||||||||||||||||||||||||||
| 37 | 5 | $self->{start} = $p->start; | |||||||||||||||||||||||||||
| 38 | 5 | $self->{size} = $p->data_size; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # process child nodes, if any | ||||||||||||||||||||||||||||
| 41 | 5 | my @stack = ($index); | |||||||||||||||||||||||||||
| 42 | 5 | my ($left, $right, $child); | |||||||||||||||||||||||||||
| 43 | 5 | $index = $p->child; | |||||||||||||||||||||||||||
| 44 | 5 | ▶ | unless ( $index == $UNUSED ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | # start at the leftmost position | ||||||||||||||||||||||||||||
| 46 | 2 | $left = $file->{properties}->[$index]->left; | |||||||||||||||||||||||||||
| 47 | 2 | $right = $file->{properties}->[$index]->right; | |||||||||||||||||||||||||||
| 48 | 2 | $child = $file->{properties}->[$index]->child; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | while ( $left != $UNUSED ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 1 | push @stack, $index; | |||||||||||||||||||||||||||
| 52 | 1 | $index = $left; | |||||||||||||||||||||||||||
| 53 | 1 | $left = $file->{properties}->[$index]->left; | |||||||||||||||||||||||||||
| 54 | 1 | $right = $file->{properties}->[$index]->right; | |||||||||||||||||||||||||||
| 55 | 1 | $child = $file->{properties}->[$index]->child; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | ▶ | while ( $index != $self->{index} ) { # while sid != self.sid: | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 4 | push @{$self->{children}}, new Finnigan::OLE2DirectoryEntry($file, $index); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # try to move right | ||||||||||||||||||||||||||||
| 62 | 4 | $left = $file->{properties}->[$index]->left; | |||||||||||||||||||||||||||
| 63 | 4 | $right = $file->{properties}->[$index]->right; | |||||||||||||||||||||||||||
| 64 | 4 | $child = $file->{properties}->[$index]->child; | |||||||||||||||||||||||||||
| 65 | 4 | ▶ | if ( $right != $UNUSED ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | # and then back to the left | ||||||||||||||||||||||||||||
| 67 | 1 | $index = $right; | |||||||||||||||||||||||||||
| 68 | 1 | while ( 1 ) { | |||||||||||||||||||||||||||
| 69 | 1 | $left = $file->{properties}->[$index]->left; | |||||||||||||||||||||||||||
| 70 | 1 | $right = $file->{properties}->[$index]->right; | |||||||||||||||||||||||||||
| 71 | 1 | $child = $file->{properties}->[$index]->child; | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | last if $left == $UNUSED; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | push @stack, $index; | |||||||||||||||||||||||||||
| 74 | 0 | $index = $left; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||
| 78 | # couldn't move right; move up instead | ||||||||||||||||||||||||||||
| 79 | 3 | my $ptr; | |||||||||||||||||||||||||||
| 80 | 3 | while ( 1 ) { | |||||||||||||||||||||||||||
| 81 | 3 | $ptr = $stack[-1]; | |||||||||||||||||||||||||||
| 82 | 3 | pop @stack; | |||||||||||||||||||||||||||
| 83 | 3 | $left = $file->{properties}->[$ptr]->left; | |||||||||||||||||||||||||||
| 84 | 3 | $right = $file->{properties}->[$ptr]->right; | |||||||||||||||||||||||||||
| 85 | 3 | $child = $file->{properties}->[$ptr]->child; | |||||||||||||||||||||||||||
| 86 | 3 | ▶ | last if $right != $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | $index = $right; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 3 | $left = $file->{properties}->[$index]->left; | |||||||||||||||||||||||||||
| 90 | 3 | $right = $file->{properties}->[$index]->right; | |||||||||||||||||||||||||||
| 91 | 3 | $child = $file->{properties}->[$index]->child; | |||||||||||||||||||||||||||
| 92 | 3 | ▶ | $index = $ptr if $right != $ptr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | # in the OLE file, entries are sorted on (length, name). | ||||||||||||||||||||||||||||
| 95 | # for convenience, we sort them on name instead. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | #self.kids.sort() | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 5 | return $self; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 0 | my ( $self, $style ) = @_; | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | $self->render_list_item($style, $DEPTH) unless $self->type == $ROOT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( $self->{children} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | $DEPTH++; | |||||||||||||||||||||||||||
| 109 | 0 | $_->list($style) for @{$self->{children}}; | |||||||||||||||||||||||||||
| 110 | 0 | $DEPTH--; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 1 | ▶ | sub find { | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=9 SCAR=22.9
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 1 | my ( $self, $query) = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | die "find() must be called on the root entry" unless $self->type == $ROOT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 1 | ▶ | return $self if $query eq "/"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | $query =~ s%^/+%%; | |||||||||||||||||||||||||||
| 122 | 1 | $query =~ s%/+$%%; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | my @name = split "\/", $query; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | my $node = $self; | |||||||||||||||||||||||||||
| 127 | 1 | foreach my $i ( 0 .. $#name ) { | |||||||||||||||||||||||||||
| 128 | 2 | ▶ | if ( $node->{children} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 2 | my $match = 0; | |||||||||||||||||||||||||||
| 130 | 2 | foreach my $child ( @{$node->{children}} ) { | |||||||||||||||||||||||||||
| 131 | 3 | ▶ | if ( $child->name eq $name[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 2 | $node = $child; | |||||||||||||||||||||||||||
| 133 | 2 | $match = 1; | |||||||||||||||||||||||||||
| 134 | 2 | last; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 2 | ▶ | return undef unless $match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | else { | ||||||||||||||||||||||||||||
| 140 | 0 | return undef; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 1 | ▶ | return $node unless $node->name eq $self->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | return undef; # not found | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub render_list_item { | ||||||||||||||||||||||||||
|
Subroutine
render_list_item: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 0 | my ($self, $style) = @_; | |||||||||||||||||||||||||||
| 149 | 0 | my $size = $self->size; | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $size_text = $self->type == $STORAGE ? "" : "($size bytes)"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | print " " x $DEPTH, $self->name, " $size_text\n"; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 3 | ▶ | sub data { | ||||||||||||||||||||||||||
|
Subroutine
data: called CC=11 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 156 | 3 | my $data; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # get the data | ||||||||||||||||||||||||||||
| 159 | my $stream_size; | ||||||||||||||||||||||||||||
| 160 | 3 | ▶ | if ( $self->size ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 3 | ▶ | if ( $self->size > $self->file->header->ministream_max | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->size > $self->file->header->ministream_max or $self->type == $ROOT
MC/DC0%0/2
$self->size > $self->file->header->ministream_max or $self->type == $ROOT
$self->size > $self->file->header->ministream_max
$self->type == $ROOT
Truth table66%2/3
A or B
A= $self->size > $self->file->header->ministream_maxB= $self->type == $ROOT
| |||||||||||||||||||||||||||||
| 162 | or | ||||||||||||||||||||||||||||
| 163 | $self->type == $ROOT ) { # the data in the root entry is always in big blocks | ||||||||||||||||||||||||||||
| 164 | 3 | $stream_size = 'big'; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | else { | ||||||||||||||||||||||||||||
| 167 | 0 | $stream_size = 'mini'; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 3 | my $first = undef; | |||||||||||||||||||||||||||
| 171 | 3 | my $previous = undef; | |||||||||||||||||||||||||||
| 172 | 3 | my $size = 0; | |||||||||||||||||||||||||||
| 173 | 3 | my $fragment_group = undef; | |||||||||||||||||||||||||||
| 174 | 3 | my @chain = $self->file->get_chain($self->start, $stream_size); | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # assemble contiguous fragments | ||||||||||||||||||||||||||||
| 177 | 3 | my $contiguous; | |||||||||||||||||||||||||||
| 178 | 3 | while ( 1 ) { | |||||||||||||||||||||||||||
| 179 | 44 | my $block = shift @chain; | |||||||||||||||||||||||||||
| 180 | 44 | ▶ | if ( defined $block ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 41 | $contiguous = 0; | |||||||||||||||||||||||||||
| 182 | 41 | ▶ | if ( not defined $first ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 3 | $first = $block; | |||||||||||||||||||||||||||
| 184 | 3 | $contiguous = 1; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | 41 | ▶ | if ( defined $previous and $block == $previous + 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $previous and $block == $previous + 1
MC/DC50%1/2
defined $previous and $block == $previous + 1
defined $previous
$block == $previous + 1
Truth table66%2/3
A and B
A= defined $previousB= $block == $previous + 1
| |||||||||||||||||||||||||||||
| 187 | 38 | $contiguous = 1; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | 41 | ▶ | if ( $contiguous ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 41 | $previous = $block; | |||||||||||||||||||||||||||
| 191 | 41 | $size += $self->file->sector_size($stream_size); | |||||||||||||||||||||||||||
| 192 | 41 | next; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 3 | ▶ | last unless defined $first; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 3 | $data .= $self->file->read( | |||||||||||||||||||||||||||
| 198 | $stream_size, # which depot | ||||||||||||||||||||||||||||
| 199 | $first, # where | ||||||||||||||||||||||||||||
| 200 | $previous - $first + 1 # how many sectors | ||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | # my $desc = sprintf "$stream_size blocks %s..%s (%s)", $first, $previous, $previous-$first+1; | ||||||||||||||||||||||||||||
| 204 | # $desc .= sprintf " of %s bytes", $self->file->sector_size($stream_size); | ||||||||||||||||||||||||||||
| 205 | # print "$desc\n"; | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 3 | ▶ | last unless $block; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | $first = $block; | |||||||||||||||||||||||||||
| 210 | 0 | $previous = $block; | |||||||||||||||||||||||||||
| 211 | 0 | $size = $self->file->sector_size; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | 3 | return substr($data, 0, $self->size); | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | 0 | return undef; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 50 | ▶ | sub file { | ||||||||||||||||||||||||||
|
Subroutine
file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | 50 | shift->{file}; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 6 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 223 | 6 | shift->{name}; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 2 | ▶ | sub type { | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 227 | 2 | shift->{type}; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 9 | ▶ | sub size { | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 231 | 9 | shift->{size}; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 3 | ▶ | sub start { | ||||||||||||||||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 235 | 3 | shift->{start}; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 2 | 1; | |||||||||||||||||||||||||||
| 239 | __END__ | ||||||||||||||||||||||||||||