blib/lib/SMB/v2/Command/Read.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 59 SCAR 24.8
CC
3
Cov
0%
parse
6.0
pack
6.0
init
2.0
CRAP 12.0
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::Read;
17  
18 use strict;
19 use warnings;
20  
21 use parent 'SMB::v2::Command';
22  
23 use constant {
24 FLAGS_READ_UNBUFFERED => 1, # SMB 3.02
25  
26 CHANNEL_NONE => 0,
27 CHANNEL_RDMA_V1 => 1, # SMB 3.*
28 CHANNEL_RDMA_V1_INVALIDATE => 2, # SMB 3.02
29 };
30  
31 sub init ($) {
32 $_[0]->set(
33 flags => 0,
34 length => 0,
35 offset => 0,
36 minimum_count => 0,
37 channel => 0,
38 remaining_bytes => 0,
39 fid => 0,
40 openfile => undef,
41 buffer => undef,
42 )
43 }
44  
45 sub parse ($$) {
46 my $self = shift;
47 my $parser = shift;
48  
49 if ($self->is_response) {
50 my $offset = $parser->uint8;
51 $parser->uint8; # reserved
52 my $length = $parser->uint32;
53 $self->length($length);
54 $self->remaining_bytes($parser->uint32);
55 $parser->uint32; # reserved
56 $self->buffer($parser->bytes($length));
57 } else {
58 $parser->uint8; # padding
59 $self->flags($parser->uint8);
60 $self->length($parser->uint32);
61 $self->offset($parser->uint64);
62 $self->fid($parser->fid2);
63 $self->minimum_count($parser->uint32);
64 $self->channel($parser->uint32);
65 $self->remaining_bytes($parser->uint32);
66 $parser->uint16; # channel info offset
67 $parser->uint16; # channel info length
68 $parser->uint8; # channel buffer
69 }
70  
71 return $self;
72 }
73  
74 sub pack ($$) {
75 my $self = shift;
76 my $packer = shift;
77  
78 if ($self->is_response) {
79 my $buffer = $self->buffer // die "No buffer";
80  
81 $packer
82 ->uint8($packer->diff('smb-header') + 14)
83 ->uint32(length $buffer)
84 ->uint32($self->remaining_bytes)
85 ->uint32(0) # reserved
86 ->bytes ($buffer)
87 ;
88 } else {
89 $packer
90 ->uint8(0) # padding
91 ->uint8($self->flags)
92 ->uint32($self->length)
93 ->uint64($self->offset)
94 ->fid2($self->fid || die "No fid set")
95 ->uint32($self->minimum_count)
96 ->uint32($self->channel)
97 ->uint32($self->remaining_bytes)
98 ->uint16(0) # channel info offset
99 ->uint16(0) # channel info length
100 ->uint8(0) # channel buffer
101 ;
102 }
103 }
104  
105 1;