lib/SMB/v2/Command/QueryDirectory.pm

filter: Statementstmt 17.5% 13 / 74 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 3 totaltotal 12.5% 17 / 136 SCAR 58.9
CC
22
Cov
11%
pack
342.0
parse
30.0
init
2.0
CRAP 360.8
« blib/lib/SMB/v2/Commands.pm ↑ Summary blib/lib/SMB/Connection.pm »
1 # SMB Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15  
16 package SMB::v2::Command::QueryDirectory;
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use parent 'SMB::v2::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 use constant {
24 1 INFO_LEVEL_DIRECTORY => 0x1,
25 INFO_LEVEL_FULLDIRECTORY => 0x2,
26 INFO_LEVEL_BOTHDIRECTORY => 0x3,
27 INFO_LEVEL_NAMES => 0xc,
28 INFO_LEVEL_IDBOTHDIRECTORY => 0x25,
29 INFO_LEVEL_IDFULLDIRECTORY => 0x26,
30  
31 FLAGS_RESCAN => 0x1,
32 FLAGS_SINGLE => 0x2,
33 FLAGS_INDEX => 0x4,
34 FLAGS_REOPEN => 0x10,
35 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 sub init ($) {
38 0 ▶ $_[0]->set(
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
39 info_level => INFO_LEVEL_IDBOTHDIRECTORY,
40 flags => 0,
41 file_index => 0,
42 file_pattern => '*',
43 buffer_length => 65536,
44 fid => 0,
45 openfile => undef,
46 files => undef,
47 )
48 }
49  
50 sub parse ($$) {
51 0 ▶ my $self = shift;
Subroutine parse: not called CC=5 SCAR=34.0
Pod undocumented
52 0 my $parser = shift;
53  
54 0 ▶ if ($self->is_response) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_response) { } 0 0 0
55 0 my $offset = $parser->uint16;
56 0 my $length = $parser->uint32;
57  
58 0 my @files = ();
59 0 my $next_diff;
60 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$next_diff and do { do { my $current = $parser->offset; $next_diff = $parser->uint32; my $file_index = $parser->uint32; my(@values) = (map({$parser->uint64;} 1..6), $parser->uint32); my $length = $parser->uint32; my $ea_size = $parser->uint32; my $short_length = $parser->uint8; $parser->uint8; my $short_filename = $parser->utf16(26); substr($short_filename, $short_length) = "" if $short_length < length $short_filename; my $id = $parser->uint64; my $filename = $parser->utf16($length); my $file = "SMB::File"->new("index", $file_index, "name", $filename, "short_name", $short_filename, "id", $id); $file->update(@values, 1); push @files, $file; $parser->skip($current + $next_diff - $parser->offset) if $next_diff } } 0 0 0
61 0 my $current = $parser->offset;
62 0 $next_diff = $parser->uint32;
63 0 my $file_index = $parser->uint32;
64 0 my @values = ((map { $parser->uint64 } 1 .. 6), $parser->uint32);
65 0 my $length = $parser->uint32;
66 0 my $ea_size = $parser->uint32; # TODO
67 0 my $short_length = $parser->uint8;
68 0 $parser->uint8;
69 0 my $short_filename = $parser->utf16(26);
70 0 ▶ substr($short_filename, $short_length) = ''
Branch: 1 branch
BranchTrueFalseTotal
if $short_length < length $short_filename 0 0 0
71 if $short_length < length($short_filename);
72 0 my $id = $parser->uint64;
73 0 my $filename = $parser->utf16($length);
74 0 my $file = SMB::File->new(index => $file_index, name => $filename, short_name => $short_filename, id => $id);
75 0 $file->update(@values, 1);
76 0 push @files, $file;
77 0 ▶ $parser->skip($current + $next_diff - $parser->offset) if $next_diff;
Branch: 1 branch
BranchTrueFalseTotal
if $next_diff 0 0 0
78 } while $next_diff;
79  
80 0 $self->files(\@files);
81 } else {
82 0 $self->info_level($parser->uint8);
83 0 $self->flags($parser->uint8);
84 0 $self->file_index($parser->uint32);
85 0 $self->fid($parser->fid2);
86 0 my $offset = $parser->uint16;
87 0 my $length = $parser->uint16;
88 0 $self->buffer_length($parser->uint32);
89 0 $self->file_pattern($parser->utf16($length));
90 }
91  
92 0 return $self;
93 }
94  
95 sub pack ($$) {
96 0 ▶ my $self = shift;
Subroutine pack: not called CC=18 SCAR=58.3
Pod undocumented
97 0 my $packer = shift;
98  
99 0 ▶ if ($self->is_response) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_response) { } 0 0 0
100 0 ▶ my $file_index = $self->file_index || 0;
Condition0%0/2
$self->file_index || 0
l!l
00
MC/DC0%0/1
$self->file_index || 0
$self->file_index
Truth table0%0/2
A
A= $self->file_index
Aresult
11
00
101 0 ▶ my $files = $self->files || [];
Condition0%0/2
$self->files || []
l!l
00
MC/DC0%0/1
$self->files || []
$self->files
Truth table0%0/2
A
A= $self->files
Aresult
11
00
102  
103 0 ▶ return $self->abort_pack($packer, SMB::STATUS_NO_MORE_FILES)
Branch: 1 branch
BranchTrueFalseTotal
unless @$files 0 0 0
104 unless @$files;
105  
106 0 $packer
107 ->uint16(72)
108 ->stub('buffer-length', 'uint32')
109 ->mark('buffer-start')
110 ;
111  
112 0 my $level = $self->info_level;
113 0 my $length = 0;
114 0 my $i = 0;
115 0 for my $file (@$files) {
116 0 my $filename = $file->name;
117 0 ▶ my $short_filename = $file->{short_name} || '';
Condition0%0/2
$file->{'short_name'} || ''
l!l
00
MC/DC0%0/1
$file->{'short_name'} || ''
$file->{'short_name'}
Truth table0%0/2
A
A= $file->{'short_name'}
Aresult
11
00
118 # pad and cut short name to exactly 12 chars
119 0 $short_filename .= "\0" x (12 - length($short_filename));
120 0 substr($short_filename, 12) = "";
121  
122 0 $packer
123 ->mark('file-info-start')
124 ->stub('next-diff', 'uint32')
125 ->uint32($file_index + $i)
126 ;
127 0 ▶ $packer
Branch: 1 branch
BranchTrueFalseTotal
unless $level == 12 0 0 0
128 ->uint64($file->creation_time)
129 ->uint64($file->last_access_time)
130 ->uint64($file->last_write_time)
131 ->uint64($file->change_time)
132 ->uint64($file->end_of_file)
133 ->uint64($file->allocation_size)
134 ->uint32($file->attributes)
135 unless $level == INFO_LEVEL_NAMES
136 ;
137 0 $packer
138 ->uint32(length($filename) * 2)
139 ;
140 $packer
141 0 ▶ ->uint32($file->{ea_size} || 0) # TODO
Branch: 1 branch
BranchTrueFalseTotal
unless $level == 12 0 0 0
Condition0%0/2
$file->{'ea_size'} || 0
l!l
00
MC/DC0%0/1
$file->{'ea_size'} || 0
$file->{'ea_size'}
Truth table0%0/2
A
A= $file->{'ea_size'}
Aresult
11
00
142 unless $level == INFO_LEVEL_NAMES
143 ;
144 0 ▶ $packer
Branch: 1 branch
BranchTrueFalseTotal
if $level == 3 or $level == 37 0 0 0
Condition0%0/3
$level == 3 or $level == 37
l!l&&r!l&&!r
000
MC/DC0%0/2
$level == 3 or $level == 37
$level == 3 $level == 37
Truth table0%0/3
A or B
A= $level == 3B= $level == 37
ABresult
1X1
011
000
145 ->uint8 (length($short_filename) * 2)
146 ->uint8 (0)
147 ->utf16($short_filename)
148 if $level == INFO_LEVEL_BOTHDIRECTORY || $level == INFO_LEVEL_IDBOTHDIRECTORY
149 ;
150 $packer
151 ->zero($level == INFO_LEVEL_IDFULLDIRECTORY ? 4 : 2)
152 0 ▶ ->uint64($file->{id} || 0)
Branch: 2 branches
BranchTrueFalseTotal
if $level == 38 or $level == 37 0 0 0
$level == 38 ? : 0 0 0
Condition0%0/5
$level == 38 or $level == 37
l!l&&r!l&&!r
000
$file->{'id'} || 0
l!l
00
MC/DC0%0/2
$level == 38 or $level == 37
$level == 38 $level == 37
MC/DC0%0/1
$file->{'id'} || 0
$file->{'id'}
Truth table0%0/3
A or B
A= $level == 38B= $level == 37
ABresult
1X1
011
000
Truth table0%0/2
A
A= $file->{'id'}
Aresult
11
00
153 if $level == INFO_LEVEL_IDFULLDIRECTORY || $level == INFO_LEVEL_IDBOTHDIRECTORY
154 ;
155 0 ▶ $packer
Branch: 1 branch
BranchTrueFalseTotal
++$i == @$files ? : 0 0 0
156 ->utf16($filename)
157 ->fill('next-diff', ++$i == @$files ? 0 : $packer->diff('file-info-start'))
158 ;
159 }
160  
161 0 $packer->fill('buffer-length', $packer->diff('buffer-start'));
162 0 $self->openfile->last_index($file_index + $i);
163 } else {
164 0 ▶ $packer
Condition0%0/2
$self->fid || die('No fid set')
l!l
00
MC/DC0%0/1
$self->fid || die('No fid set')
$self->fid
Truth table0%0/2
A
A= $self->fid
Aresult
11
00
165 ->uint8($self->info_level)
166 ->uint8($self->flags)
167 ->uint32($self->file_index)
168 ->fid2($self->fid || die "No fid set")
169 ->uint16($packer->diff('smb-header') + 8)
170 ->uint16(length($self->file_pattern) * 2)
171 ->uint32($self->buffer_length)
172 ->utf16($self->file_pattern)
173 ;
174 }
175 }
176  
177 1 1;
« blib/lib/SMB/v2/Commands.pm ↑ Summary blib/lib/SMB/Connection.pm »