@@ -97,8 +97,9 @@ def cmd_mic_start(*args)
97
97
::File . open ( file , 'a' ) do |f |
98
98
f . write ( data )
99
99
end
100
- data = nil
100
+ return data . length
101
101
end
102
+ return 0
102
103
end
103
104
device_id = 1
104
105
duration = 1800
@@ -138,25 +139,31 @@ def cmd_mic_start(*args)
138
139
end
139
140
140
141
print_status ( "Saving to audio file: #{ saved_audio_path } " )
142
+ total_data_len = 0
141
143
begin
142
144
channel = client . mic . mic_start ( device_id )
143
145
mic_started = true
144
146
print_status ( "Streaming started..." )
147
+ ::File . open ( saved_audio_path , 'wb' ) do |outfile |
148
+ audio_file_wave_header ( 11025 , 1 , 16 , 2000000000 ) . each { |e | e . write ( outfile ) }
149
+ end
145
150
::Timeout . timeout ( duration ) do
146
- ::File . open ( saved_audio_path , 'wb' ) do |outfd |
147
- audio_file_wave_header ( 11025 , 1 , 16 , 2000000000 ) . each { |e | e . write ( outfd ) }
148
- end
149
151
while client do
150
- get_data . call ( channel , saved_audio_path )
151
152
Rex ::sleep ( 0.5 )
153
+ total_data_len += get_data . call ( channel , saved_audio_path )
152
154
end
153
155
end
154
156
rescue ::Timeout ::Error
155
157
ensure
156
158
if mic_started
157
- get_data . call ( channel , saved_audio_path )
159
+ total_data_len += get_data . call ( channel , saved_audio_path )
158
160
client . mic . mic_stop
159
161
print_status ( "Streaming stopped." )
162
+ # Now that we know the actual length of data, update the file header.
163
+ ::File . open ( saved_audio_path , 'rb+' ) do |outfile |
164
+ outfile . seek ( 0 , ::IO ::SEEK_SET )
165
+ audio_file_wave_header ( 11025 , 1 , 16 , total_data_len ) . each { |e | e . write ( outfile ) }
166
+ end
160
167
end
161
168
end
162
169
end
0 commit comments