Seperate concerns of console/mic

bug/bundler_fix
dmohanty-r7 2017-06-05 10:22:16 -05:00
parent 9ca74d69f1
commit c7b71a2b32
2 changed files with 48 additions and 49 deletions

View File

@ -40,6 +40,54 @@ module Rex
request = Packet.create_request('audio_interface_start')
request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_NAME, mic)
client.send_request(request)
begin
client.mic.mic_start(index)
mic_started = true
::Timeout.timeout(duration) do
::File.open(stream_path, 'wb') do |outfd|
numchannels = 1
sampleratehz = 11025
bitspersample = 16
datasize = 2000000000
subchunk1size = 16
chunksize = 4 + (8 + subchunk1size) + (8 + datasize)
byterate = sampleratehz * numchannels * bitspersample / 8
blockalign = numchannels * bitspersample / 8
BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF"
BinData::Int32le.new(chunksize).write(outfd) # ChunkSize
BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE"
BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt "
BinData::Int32le.new(16).write(outfd) # SubChunk1Size
BinData::Int16le.new(1).write(outfd) # AudioFormat
BinData::Int16le.new(numchannels).write(outfd) # NumChannels
BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate
BinData::Int32le.new(byterate).write(outfd) # ByteRate
BinData::Int16le.new(blockalign).write(outfd) # BlockAlign
BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample
BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data"
BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size
end
stream_index = 0
while client do
if play_audio && (stream_index == start_delay)
cmd_listen(stream_path)
end
data = client.mic.mic_get_frame(quality)
if data
::File.open(stream_path, 'a') do |f|
f.write(data)
end
data = nil
end
stream_index += 1
sleep 1
end
end
rescue ::Timeout::Error
ensure
client.mic.mic_stop if mic_started
end
true
end

View File

@ -64,55 +64,6 @@ module Rex
print_status("Audio File: #{stream_path}")
print_status("Streaming...")
begin
client.mic.mic_start(index)
mic_started = true
::Timeout.timeout(duration) do
::File.open(stream_path, 'wb') do |outfd|
numchannels = 1
sampleratehz = 11025
bitspersample = 16
datasize = 2000000000
subchunk1size = 16
chunksize = 4 + (8 + subchunk1size) + (8 + datasize)
byterate = sampleratehz * numchannels * bitspersample / 8
blockalign = numchannels * bitspersample / 8
BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF"
BinData::Int32le.new(chunksize).write(outfd) # ChunkSize
BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE"
BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt "
BinData::Int32le.new(16).write(outfd) # SubChunk1Size
BinData::Int16le.new(1).write(outfd) # AudioFormat
BinData::Int16le.new(numchannels).write(outfd) # NumChannels
BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate
BinData::Int32le.new(byterate).write(outfd) # ByteRate
BinData::Int16le.new(blockalign).write(outfd) # BlockAlign
BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample
BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data"
BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size
end
stream_index = 0
while client do
if play_audio && (stream_index == start_delay)
cmd_listen(stream_path)
end
data = client.mic.mic_get_frame(quality)
if data
::File.open(stream_path, 'a') do |f|
f.write(data)
end
data = nil
end
stream_index += 1
sleep 1
end
end
rescue ::Timeout::Error
ensure
client.mic.mic_stop if mic_started
end
end
def cmd_mic_stop(index=0)