Class: Pwnlib::Tubes::SerialTube

Inherits:
Tube
  • Object
show all
Defined in:
lib/pwnlib/tubes/serialtube.rb

Overview

Serial Connections

Constant Summary

Constants inherited from Tube

Tube::BUFSIZE

Instance Method Summary collapse

Methods inherited from Tube

#gets, #interact, #puts, #recv, #recvall, #recvline, #recvn, #recvpred, #recvregex, #recvuntil, #send, #sendline, #unrecv

Constructor Details

#initialize(port = nil, baudrate: 115_200, convert_newlines: true, bytesize: 8, parity: :none) ⇒ SerialTube

Instantiate a Pwnlib::Tubes::SerialTube object.

Parameters:

  • port (String) (defaults to: nil)

    A device name for rubyserial to open, e.g. /dev/ttypUSB0

  • baudrate (Integer) (defaults to: 115_200)

    Baud rate.

  • convert_newlines (Boolean) (defaults to: true)

    If true, convert any context.newlines to "\r\n" before sending to remote. Has no effect on bytes received.

  • bytesize (Integer) (defaults to: 8)

    Serial character byte size. The '8' in '8N1'.

  • parity (Symbol) (defaults to: :none)

    Serial character parity. The 'N' in '8N1'.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pwnlib/tubes/serialtube.rb', line 29

def initialize(port = nil, baudrate: 115_200,
               convert_newlines: true,
               bytesize: 8, parity: :none)
  super()

  # go hunting for a port
  port ||= Dir.glob('/dev/tty.usbserial*').first
  port ||= '/dev/ttyUSB0'

  @convert_newlines = convert_newlines
  @conn = Serial.new(port, baudrate, bytesize, parity)
  @serial_timer = Timer.new
end

Instance Method Details

#closeObject

Closes the active connection



44
45
46
47
# File 'lib/pwnlib/tubes/serialtube.rb', line 44

def close
  @conn.close if @conn && !@conn.closed?
  @conn = nil
end