File Coverage

lib/SMB/v2/Command/Ioctl.pm
Criterion Covered Total %
statement 12 40 30.0
branch 0 4 0.0
condition 0 6 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 16 60 26.6


line stmt bran cond sub pod time code
1             # SMB Perl library, Copyright (C) 2014-2018 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 .
15              
16             package SMB::v2::Command::Ioctl;
17              
18 1     1   9 use strict;
  1         3  
  1         36  
19 1     1   7 use warnings;
  1         3  
  1         39  
20              
21 1     1   8 use parent 'SMB::v2::Command';
  1         3  
  1         6  
22              
23             use constant {
24 1         591 FSCTL_DFS_GET_REFERRALS => 0x00060194,
25             FSCTL_PIPE_WAIT => 0x00110018,
26             FSCTL_PIPE_TRANSCEIVE => 0x0011c017,
27 1     1   87 };
  1         3  
28              
29             sub init ($) {
30 0     0 0   $_[0]->set(
31             function => 0,
32             flags => 0,
33             length => 0, # in on request, out on response
34             offset => 0, # in on request, out on response
35             max_size => 0, # out only
36             fid => 0,
37             openfile => undef,
38             buffer => undef,
39             )
40             }
41              
42             sub parse ($$) {
43 0     0 0   my $self = shift;
44 0           my $parser = shift;
45              
46 0           $parser->skip(2); # unknown
47 0           $self->function($parser->uint32);
48 0           $self->fid($parser->fid2);
49 0 0         if ($self->is_response) {
50 0           $parser->uint32; # in offset, ignore
51 0           $parser->uint32; # in length, ignore
52 0           $self->offset($parser->uint32); # out offset
53 0           $self->length($parser->uint32); # out length
54             } else {
55 0           $self->offset($parser->uint32); # in offset
56 0           $self->length($parser->uint32); # in length
57 0           $parser->uint32; # in max_size, ignore
58 0           $parser->uint32; # out offset, ignore
59 0           $parser->uint32; # out length, ignore
60 0           $self->max_size($parser->uint32); # out max_size
61 0           $self->flags($parser->uint32);
62             }
63 0           $self->buffer($parser->reset($self->offset)->bytes($self->length));
64              
65 0           return $self;
66             }
67              
68             sub pack ($$) {
69 0     0 0   my $self = shift;
70 0           my $packer = shift;
71              
72 0   0       my $buffer = $self->buffer // die "No buffer";
73              
74 0   0       $packer
      0        
75             ->skip(2) # unknown
76             ->uint32($self->function // FSCTL_PIPE_TRANSCEIVE)
77             ->fid2($self->fid || die "No fid set")
78             ;
79 0 0         if ($self->is_response) {
80 0           $packer
81             ->uint32(0) # in offset
82             ->uint32(0) # in length
83             ->stub('buffer-offset', 'uint32') # out offset
84             ->uint32(length $buffer) # out length
85             ;
86             } else {
87 0           $packer
88             ->stub('buffer-offset', 'uint32') # in offset
89             ->uint32(length $buffer) # in length
90             ->uint32(0) # in max_size
91             ->uint32(0) # out offset
92             ->uint32(0) # out length
93             ->uint32(1024) # out max_size
94             ->uint32($self->flags)
95             ;
96             }
97 0           $packer
98             ->fill('buffer-offset', $packer->diff('smb-header'))
99             ->bytes($buffer)
100             ;
101             }
102              
103             1;