Module: ObjectPwnStream::ObjectInputStream

Includes:
Constants, Errors
Included in:
PwnStream
Defined in:
lib/ObjectPwnStream/ObjectInputStream.rb

Constant Summary

Constants included from Constants

Constants::BASE_WIRE_HANDLE, Constants::STREAM_MAGIC, Constants::STREAM_VERSION, Constants::TC_ARRAY, Constants::TC_BLOCKDATA, Constants::TC_BLOCKDATALONG, Constants::TC_CLASS, Constants::TC_CLASSDESC, Constants::TC_ENDBLOCKDATA, Constants::TC_ENUM, Constants::TC_EXCEPTION, Constants::TC_LONGSTRING, Constants::TC_NULL, Constants::TC_OBJECT, Constants::TC_PROXYCLASSDESC, Constants::TC_REFERENCE, Constants::TC_RESET, Constants::TC_STRING

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_stream_header(header, provided: nil) ⇒ Object



104
105
106
107
108
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 104

def check_stream_header(header, provided: nil)
  unless header.first.eql?(Constants::STREAM_MAGIC) && header.last.eql?(Constants::STREAM_VERSION)
    raise provided.nil? ? Errors::StreamHeaderError : !provided ? Errors::YsoserialPayloadCorruptedError : Errors::PayloadStreamHeaderError
  end
end

Instance Method Details

#handle_resetObject



57
58
59
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 57

def handle_reset
  check_stream_reset(@instream.getbyte)
end

#open_input_streamObject



9
10
11
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 9

def open_input_stream
  check_stream_header(read_stream_header)
end

#read_booleanObject



51
52
53
54
55
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 51

def read_boolean
  read_block_header
  bool = @instream.getbyte
  bool != 0
end

#read_byteObject



35
36
37
38
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 35

def read_byte
  read_block_header
  @instream.getbyte
end

#read_bytesObject



40
41
42
43
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 40

def read_bytes
  _, length = read_block_header
  @instream.read(length).unpack("C*")
end

#read_charObject



26
27
28
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 26

def read_char
  [read_short].pack("U")
end

#read_charsObject



30
31
32
33
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 30

def read_chars
  _, length = read_block_header
  @instream.read(length).unpack("S>*").pack("U*")
end

#read_doubleObject



66
67
68
69
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 66

def read_double
  _, length = read_block_header
  @instream.read(length).unpack("G")[0]
end

#read_floatObject



61
62
63
64
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 61

def read_float
  _, length = read_block_header
  @instream.read(length).unpack("g")[0]
end

#read_int(signed: false) ⇒ Object



13
14
15
16
17
18
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 13

def read_int(signed: false)
  _, length = read_block_header
  template = (signed ? "l>" : "L>")
  @instream.read(length).unpack(template)[0]
  # to_signed(hex.to_i(16))
end

#read_long(signed: false) ⇒ Object



71
72
73
74
75
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 71

def read_long(signed: false)
  _, length = read_block_header
  template = signed ? "q>" : "Q>"
  @instream.read(length).unpack(template)[0]
end

#read_objectObject



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 77

def read_object
  unless @file_mode
    bytes = [@instream.getbyte]
    while @instream.ready?
      bytes << @instream.getbyte
    end
  else
    bytes = @instream.each_byte.to_a
  end
  bytes.pack("C*")
end

#read_short(signed: false) ⇒ Object



20
21
22
23
24
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 20

def read_short(signed: false)
  _, length = read_block_header
  template = (signed ? "s>" : "S>")
  @instream.read(length).unpack(template)[0]
end

#read_utfObject



45
46
47
48
49
# File 'lib/ObjectPwnStream/ObjectInputStream.rb', line 45

def read_utf
  _, block_length = read_block_header
  length = @instream.read(2).unpack("S>")[0]
  @instream.read(length).unpack("U*").pack("U*")
end