Module: Rex::Proto::Quake::Message
- Included in:
- Rex::Proto::Quake
- Defined in:
- lib/rex/proto/quake/message.rb
Constant Summary collapse
- HEADER =
0xFFFFFFFF
Instance Method Summary collapse
- #decode_info(message) ⇒ Object
- #decode_infostring(infostring) ⇒ Object
- #decode_message(message) ⇒ Object
- #decode_response(message, type) ⇒ Object
- #decode_status(message) ⇒ Object
- #encode_message(payload) ⇒ Object
- #getinfo ⇒ Object
- #getstatus ⇒ Object
Instance Method Details
#decode_info(message) ⇒ Object
68 69 70 |
# File 'lib/rex/proto/quake/message.rb', line 68 def decode_info() decode_response(, 'info') end |
#decode_infostring(infostring) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rex/proto/quake/message.rb', line 33 def decode_infostring(infostring) # decode an "infostring", which is just a (supposedly) quoted string of tokens separated # by backslashes, generally terminated with a newline token_re = /([^\\]+)\\([^\\]+)/ return nil unless infostring =~ token_re # remove possibly present leading/trailing double quote infostring.gsub!(/(?:^"|"$)/, '') # remove the trailing \n, if present infostring.gsub!(/\n$/, '') # split on backslashes and group into key value pairs infohash = {} infostring.scan(token_re).each do |kv| infohash[kv.first] = kv.last end infohash end |
#decode_message(message) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rex/proto/quake/message.rb', line 13 def () # minimum size is header (4) + <command> + <stuff> return if .length < 7 header = .unpack('N')[0] return if header != HEADER [4, .length] end |
#decode_response(message, type) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rex/proto/quake/message.rb', line 50 def decode_response(, type) resp = () if /^print\n(?<error>.*)\n?/m =~ resp # XXX: is there a better exception to throw here? fail ::ArgumentError, "#{type} error: #{error}" # why doesn't this work? # elsif /^#{type}Response\n(?<infostring>.*)/m =~ resp elsif resp =~ /^#{type}Response\n(.*)/m decode_infostring(Regexp.last_match(1)) else nil end end |
#decode_status(message) ⇒ Object
64 65 66 |
# File 'lib/rex/proto/quake/message.rb', line 64 def decode_status() decode_response(, 'status') end |
#encode_message(payload) ⇒ Object
21 22 23 |
# File 'lib/rex/proto/quake/message.rb', line 21 def (payload) [HEADER].pack('N') + payload end |
#getinfo ⇒ Object
29 30 31 |
# File 'lib/rex/proto/quake/message.rb', line 29 def getinfo ('getinfo') end |
#getstatus ⇒ Object
25 26 27 |
# File 'lib/rex/proto/quake/message.rb', line 25 def getstatus ('getstatus') end |