Class: Ronin::Support::Binary::Buffer
- Includes:
- CTypes::Mixin
- Defined in:
- lib/ronin/support/binary/buffer.rb
Overview
Represents a binary buffer of data.
Examples
Writing bytes into an empty buffer:
buffer = Binary::Buffer.new(10)
# => #<Ronin::Support::Binary::Buffer: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00">
buffer[0] = 0x41
buffer[1] = 0x42
buffer[2] = 0x43
buffer.to_s
# => "ABC\x00\x00\x00\x00\x00\x00\x00"
Writing different types of data to a buffer:
buffer = Binary::Buffer.new(16)
# => #<Ronin::Support::Binary::Buffer: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00">
buffer.put_uint32(0,0x11223344)
buffer.put_int32(4,-1)
buffer.put_string(8,"ABC")
buffer.put_float32(12,0.5)
buffer.to_s
# => "D3\"\x11\xFF\xFF\xFF\xFFABC\x00\x00\x00\x00?"
Creating a buffer from an existing String:
buffer = Binary::Buffer.new("\x41\x00\x00\x00\x42\x00\x00\x00")
# => #<Ronin::Support::Binary::Buffer: "A\u0000\u0000\u0000B\u0000\u0000\u0000">
buffer.get_uint32(0)
# => 65
buffer.get_uint32(4)
# => 66
Instance Attribute Summary
Attributes included from CTypes::Mixin
#arch, #endian, #os, #type_resolver, #type_system
Attributes inherited from Memory
Reader Methods collapse
-
#array_at(offset, type, length) ⇒ Array
Returns the array starting at the given offset, with the given length, containing the given type.
-
#buffer_at(offset, size) ⇒ Buffer
Returns the buffer starting at the given offset and with the given size.
-
#get(type, offset) ⇒ Integer, ...
Reads a value of the given type at the given offset.
-
#get_array_of(type, offset, count) ⇒ ::Array<Object>
Reads an array of the given type, starting at the given offset, with the given length.
-
#get_array_of_byte(offset, count) ⇒ ::Array<Integer>
(also: #get_bytes)
Alias to
get_array_of(:byte,offset,count)
. -
#get_array_of_char(offset, count) ⇒ ::Array<Integer>
(also: #get_chars)
Alias to
get_array_of(:char,offset,count)
. -
#get_array_of_double(offset, count) ⇒ ::Array<Float>
(also: #get_doubles)
Alias to
get_array_of(:double,offset,count)
. -
#get_array_of_float(offset, count) ⇒ ::Array<Float>
(also: #get_floats)
Alias to
get_array_of(:float,offset,count)
. -
#get_array_of_float32(offset, count) ⇒ ::Array<Float>
Alias to
get_array_of(:float32,offset,count)
. -
#get_array_of_float64(offset, count) ⇒ ::Array<Float>
Alias to
get_array_of(:float64,offset,count)
. -
#get_array_of_int(offset, count) ⇒ ::Array<Integer>
(also: #get_ints)
Alias to
get_array_of(:int,offset,count)
. -
#get_array_of_int16(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:int16,offset,count)
. -
#get_array_of_int32(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:int32,offset,count)
. -
#get_array_of_int64(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:int64,offset,count)
. -
#get_array_of_int8(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:int8,offset,count)
. -
#get_array_of_long(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:long,offset,count)
. -
#get_array_of_long_long(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:long_long,offset,count)
. -
#get_array_of_short(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:short,offset,count)
. -
#get_array_of_uchar(offset, count) ⇒ ::Array<Integer>
(also: #get_uchars)
Alias to
get_array_of(:uchar,offset,count)
. -
#get_array_of_uint(offset, count) ⇒ ::Array<Integer>
(also: #get_uints)
Alias to
get_array_of(:uint,offset,count)
. -
#get_array_of_uint16(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:uint16,offset,count)
. -
#get_array_of_uint32(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:uint32,offset,count)
. -
#get_array_of_uint64(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:uint64,offset,count)
. -
#get_array_of_uint8(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:uint8,offset,count)
. -
#get_array_of_ulong(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:ulong,offset,count)
. -
#get_array_of_ulong_long(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:ulong_long,offset,count)
. -
#get_array_of_ushort(offset, count) ⇒ ::Array<Integer>
Alias to
get_array_of(:ushort,offset,count)
. -
#get_byte(offset) ⇒ Integer
Alias for
get(:byte,offset)
. -
#get_char(offset) ⇒ String
Alias for
get(:char,offset)
. -
#get_double(offset) ⇒ Float
Alias for
get(:double,offset)
. -
#get_float(offset) ⇒ Float
Alias for
get(:float,offset)
. -
#get_float32(offset) ⇒ Float
Alias for
get(:float32,offset)
. -
#get_float64(offset) ⇒ Float
Alias for
get(:float64,offset)
. -
#get_int(offset) ⇒ Integer
Alias for
get(:int,offset)
. -
#get_int16(offset) ⇒ Integer
Alias for
get(:int16,offset)
. -
#get_int32(offset) ⇒ Integer
Alias for
get(:int32,offset)
. -
#get_int64(offset) ⇒ Integer
Alias for
get(:int64,offset)
. -
#get_int8(offset) ⇒ Integer
Alias for
get(:int8,offset)
. -
#get_long(offset) ⇒ Integer
Alias for
get(:long,offset)
. -
#get_long_long(offset) ⇒ Integer
Alias for
get(:long_long,offset)
. -
#get_short(offset) ⇒ Integer
Alias for
get(:short,offset)
. -
#get_string(offset, length = nil) ⇒ String
Reads a null-byte terminated C string from the buffer, at the given offset.
-
#get_uchar(offset) ⇒ String
Alias for
get(:uchar,offset)
. -
#get_uint(offset) ⇒ Integer
Alias for
get(:uint,offset)
. -
#get_uint16(offset) ⇒ Integer
Alias for
get(:uint16,offset)
. -
#get_uint32(offset) ⇒ Integer
Alias for
get(:uint32,offset)
. -
#get_uint64(offset) ⇒ Integer
Alias for
get(:uint64,offset)
. -
#get_uint8(offset) ⇒ Integer
Alias for
get(:uint8,offset)
. -
#get_ulong(offset) ⇒ Integer
Alias for
get(:ulong,offset)
. -
#get_ulong_long(offset) ⇒ Integer
Alias for
get(:ulong_long,offset)
. -
#get_ushort(offset) ⇒ Integer
Alias for
get(:ushort,offset)
. -
#struct_at(offset, struct_class) ⇒ Binary::Struct
Returns a new Struct instance starting at the given offset.
-
#union_at(offset, union_class) ⇒ Union
Returns a new Union instance starting at the given offset.
Writer Methods collapse
-
#put(type, offset, value) ⇒ Object
Writes a value of the given type to the given offset.
-
#put_array_of(type, offset, array) ⇒ self
Writes an array of the given type, to the given offset within the buffer.
-
#put_array_of_byte(offset, bytes) ⇒ self
(also: #put_bytes)
Alias to
put_array_of(:byte,offset,bytes)
. -
#put_array_of_char(offset, chars) ⇒ self
(also: #put_chars)
Alias to
put_array_of(:char,offset,bytes)
. -
#put_array_of_double(offset, floats) ⇒ self
(also: #put_doubles)
Alias to
put_array_of(:double,offset,floats)
. -
#put_array_of_float(offset, floats) ⇒ self
(also: #put_floats)
Alias to
put_array_of(:float,offset,floats)
. -
#put_array_of_float32(offset, floats) ⇒ self
Alias to
put_array_of(:float32,offset,floats)
. -
#put_array_of_float64(offset, floats) ⇒ self
Alias to
put_array_of(:float64,offset,floats)
. -
#put_array_of_int(offset, ints) ⇒ self
(also: #put_ints)
Alias to
put_array_of(:int,offset,ints)
. -
#put_array_of_int16(offset, ints) ⇒ self
Alias to
put_array_of(:int16,offset,ints)
. -
#put_array_of_int32(offset, ints) ⇒ self
Alias to
put_array_of(:int32,offset,ints)
. -
#put_array_of_int64(offset, ints) ⇒ self
Alias to
put_array_of(:int64,offset,ints)
. -
#put_array_of_int8(offset, ints) ⇒ self
Alias to
put_array_of(:int8,offset,ints)
. -
#put_array_of_long(offset, ints) ⇒ self
Alias to
put_array_of(:long,offset,ints)
. -
#put_array_of_long_long(offset, ints) ⇒ self
Alias to
put_array_of(:long_long,offset,ints)
. -
#put_array_of_short(offset, ints) ⇒ self
Alias to
put_array_of(:short,offset,ints)
. -
#put_array_of_uchar(offset, chars) ⇒ self
(also: #put_uchars)
Alias to
put_array_of(:uchar,offset,bytes)
. -
#put_array_of_uint(offset, uints) ⇒ self
(also: #put_uints)
Alias to
put_array_of(:uint,offset,uints)
. -
#put_array_of_uint16(offset, uints) ⇒ self
Alias to
put_array_of(:uint16,offset,uints)
. -
#put_array_of_uint32(offset, uints) ⇒ self
Alias to
put_array_of(:uint32,offset,uints)
. -
#put_array_of_uint64(offset, uints) ⇒ self
Alias to
put_array_of(:uint64,offset,uints)
. -
#put_array_of_uint8(offset, uints) ⇒ self
Alias to
put_array_of(:uint8,offset,uints)
. -
#put_array_of_ulong(offset, uints) ⇒ self
Alias to
put_array_of(:ulong,offset,uints)
. -
#put_array_of_ulong_long(offset, uints) ⇒ self
Alias to
put_array_of(:ulong_long,offset,uints)
. -
#put_array_of_ushort(offset, uints) ⇒ self
Alias to
put_array_of(:ushort,offset,uints)
. -
#put_byte(offset, value) ⇒ self
Alias for
put(:byte,offset,value)
. -
#put_char(offset, value) ⇒ self
Alias for
put(:char,offset,value)
. -
#put_double(offset, value) ⇒ self
Alias for
put(:double,offset,value)
. -
#put_float(offset, value) ⇒ self
Alias for
put(:float,offset,value)
. -
#put_float32(offset, value) ⇒ self
Alias for
put(:float32,offset,value)
. -
#put_float64(offset, value) ⇒ self
Alias for
put(:float64,offset,value)
. -
#put_int(offset, value) ⇒ self
Alias for
put(:int,offset,value)
. -
#put_int16(offset, value) ⇒ self
Alias for
put(:int16,offset,value)
. -
#put_int32(offset, value) ⇒ self
Alias for
put(:int32,offset,value)
. -
#put_int64(offset, value) ⇒ self
Alias for
put(:int64,offset,value)
. -
#put_int8(offset, value) ⇒ self
Alias for
put(:int8,offset,value)
. -
#put_long(offset, value) ⇒ self
Alias for
put(:long,offset,value)
. -
#put_long_long(offset, value) ⇒ self
Alias for
put(:long_long,offset,value)
. -
#put_short(offset, value) ⇒ self
Alias for
put(:short,offset,value)
. -
#put_string(offset, string) ⇒ self
Writes a null-terminated C string into the buffer at the given offset.
-
#put_uchar(offset, value) ⇒ self
Alias for
put(:uchar,offset,value)
. -
#put_uint(offset, value) ⇒ self
Alias for
put(:uint,offset,value)
. -
#put_uint16(offset, value) ⇒ self
Alias for
put(:uint16,offset,value)
. -
#put_uint32(offset, value) ⇒ self
Alias for
put(:uint32,offset,value)
. -
#put_uint64(offset, value) ⇒ self
Alias for
put(:uint64,offset,value)
. -
#put_uint8(offset, value) ⇒ self
Alias for
put(:uint8,offset,value)
. -
#put_ulong(offset, value) ⇒ self
Alias for
put(:ulong,offset,value)
. -
#put_ulong_long(offset, value) ⇒ self
Alias for
put(:ulong_long,offset,value)
. -
#put_ushort(offset, value) ⇒ self
Alias for
put(:ushort,offset,value)
.
Class Method Summary collapse
-
.read_from(io, size) ⇒ Buffer
Reads from the IO stream and returns a buffer.
Instance Method Summary collapse
-
#[]=(index_or_range, length = nil, value) ⇒ String
Writes a value to the buffer at the given index.
-
#initialize(length_or_string, **kwargs) ⇒ Buffer
constructor
Initializes the buffer.
-
#to_s ⇒ String
(also: #to_str)
Converts the buffer to a String.
Methods included from CTypes::Mixin
Methods inherited from Memory
#+, #[], #byteslice, #clear, #copy_from, #copy_to, #pack, #read_from, #size
Constructor Details
#initialize(length_or_string, **kwargs) ⇒ Buffer
Initializes the buffer.
The desired architecture for the values within the buffer.
94 95 96 97 98 |
# File 'lib/ronin/support/binary/buffer.rb', line 94 def initialize(length_or_string, **kwargs) initialize_type_system(**kwargs) super(length_or_string) end |
Class Method Details
.read_from(io, size) ⇒ Buffer
Reads from the IO stream and returns a buffer.
116 117 118 |
# File 'lib/ronin/support/binary/buffer.rb', line 116 def self.read_from(io,size) new(io.read(size)) end |
Instance Method Details
#[]=(index_or_range, length = nil, value) ⇒ String
Writes a value to the buffer at the given index.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ronin/support/binary/buffer.rb', line 155 def []=(index_or_range,length=nil,value) value = case value when Integer value.chr(Encoding::ASCII_8BIT) when ::Array value.map { |char_or_byte| case char_or_byte when Integer char_or_byte.chr(Encoding::ASCII_8BIT) else char_or_byte end }.join else value end super(index_or_range,length,value) end |
#array_at(offset, type, length) ⇒ Array
Returns the array starting at the given offset, with the given length, containing the given type.
635 636 637 638 639 640 |
# File 'lib/ronin/support/binary/buffer.rb', line 635 def array_at(offset,type,length) type = @type_system[type] size = type.size * length return Array.new(type,byteslice(offset,size)) end |
#buffer_at(offset, size) ⇒ Buffer
Returns the buffer starting at the given offset and with the given size.
612 613 614 |
# File 'lib/ronin/support/binary/buffer.rb', line 612 def buffer_at(offset,size) Buffer.new(byteslice(offset,size)) end |
#get(type, offset) ⇒ Integer, ...
Reads a value of the given type at the given offset.
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/ronin/support/binary/buffer.rb', line 203 def get(type,offset) type = @type_system[type] if (offset < 0) || ((offset + type.size) > size) raise(IndexError,"offset #{offset} is out of bounds: 0...#{size - type.size}") end data = @string[offset,type.size] return type.unpack(data) end |
#get_array_of(type, offset, count) ⇒ ::Array<Object>
Reads an array of the given type, starting at the given offset, with the given length.
706 707 708 709 710 711 712 713 714 715 716 |
# File 'lib/ronin/support/binary/buffer.rb', line 706 def get_array_of(type,offset,count) type = @type_system[type] array_type = type[count] if (offset < 0) || ((offset + array_type.size) > size) raise(IndexError,"offset #{offset} or size #{array_type.size} is out of bounds: 0...#{size - type.size}") end slice = @string[offset,array_type.size] return array_type.unpack(slice) end |
#get_array_of_byte(offset, count) ⇒ ::Array<Integer> Also known as: get_bytes
Alias to get_array_of(:byte,offset,count)
.
732 733 734 |
# File 'lib/ronin/support/binary/buffer.rb', line 732 def get_array_of_byte(offset,count) get_array_of(:byte,offset,count) end |
#get_array_of_char(offset, count) ⇒ ::Array<Integer> Also known as: get_chars
Alias to get_array_of(:char,offset,count)
.
752 753 754 |
# File 'lib/ronin/support/binary/buffer.rb', line 752 def get_array_of_char(offset,count) get_array_of(:char,offset,count) end |
#get_array_of_double(offset, count) ⇒ ::Array<Float> Also known as: get_doubles
Alias to get_array_of(:double,offset,count)
.
1140 1141 1142 |
# File 'lib/ronin/support/binary/buffer.rb', line 1140 def get_array_of_double(offset,count) get_array_of(:double,offset,count) end |
#get_array_of_float(offset, count) ⇒ ::Array<Float> Also known as: get_floats
Alias to get_array_of(:float,offset,count)
.
1120 1121 1122 |
# File 'lib/ronin/support/binary/buffer.rb', line 1120 def get_array_of_float(offset,count) get_array_of(:float,offset,count) end |
#get_array_of_float32(offset, count) ⇒ ::Array<Float>
Alias to get_array_of(:float32,offset,count)
.
1084 1085 1086 |
# File 'lib/ronin/support/binary/buffer.rb', line 1084 def get_array_of_float32(offset,count) get_array_of(:float32,offset,count) end |
#get_array_of_float64(offset, count) ⇒ ::Array<Float>
Alias to get_array_of(:float64,offset,count)
.
1102 1103 1104 |
# File 'lib/ronin/support/binary/buffer.rb', line 1102 def get_array_of_float64(offset,count) get_array_of(:float64,offset,count) end |
#get_array_of_int(offset, count) ⇒ ::Array<Integer> Also known as: get_ints
Alias to get_array_of(:int,offset,count)
.
954 955 956 |
# File 'lib/ronin/support/binary/buffer.rb', line 954 def get_array_of_int(offset,count) get_array_of(:int,offset,count) end |
#get_array_of_int16(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:int16,offset,count)
.
810 811 812 |
# File 'lib/ronin/support/binary/buffer.rb', line 810 def get_array_of_int16(offset,count) get_array_of(:int16,offset,count) end |
#get_array_of_int32(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:int32,offset,count)
.
828 829 830 |
# File 'lib/ronin/support/binary/buffer.rb', line 828 def get_array_of_int32(offset,count) get_array_of(:int32,offset,count) end |
#get_array_of_int64(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:int64,offset,count)
.
846 847 848 |
# File 'lib/ronin/support/binary/buffer.rb', line 846 def get_array_of_int64(offset,count) get_array_of(:int64,offset,count) end |
#get_array_of_int8(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:int8,offset,count)
.
792 793 794 |
# File 'lib/ronin/support/binary/buffer.rb', line 792 def get_array_of_int8(offset,count) get_array_of(:int8,offset,count) end |
#get_array_of_long(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:long,offset,count)
.
974 975 976 |
# File 'lib/ronin/support/binary/buffer.rb', line 974 def get_array_of_long(offset,count) get_array_of(:long,offset,count) end |
#get_array_of_long_long(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:long_long,offset,count)
.
992 993 994 |
# File 'lib/ronin/support/binary/buffer.rb', line 992 def get_array_of_long_long(offset,count) get_array_of(:long_long,offset,count) end |
#get_array_of_short(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:short,offset,count)
.
936 937 938 |
# File 'lib/ronin/support/binary/buffer.rb', line 936 def get_array_of_short(offset,count) get_array_of(:short,offset,count) end |
#get_array_of_uchar(offset, count) ⇒ ::Array<Integer> Also known as: get_uchars
Alias to get_array_of(:uchar,offset,count)
.
772 773 774 |
# File 'lib/ronin/support/binary/buffer.rb', line 772 def get_array_of_uchar(offset,count) get_array_of(:uchar,offset,count) end |
#get_array_of_uint(offset, count) ⇒ ::Array<Integer> Also known as: get_uints
Alias to get_array_of(:uint,offset,count)
.
1028 1029 1030 |
# File 'lib/ronin/support/binary/buffer.rb', line 1028 def get_array_of_uint(offset,count) get_array_of(:uint,offset,count) end |
#get_array_of_uint16(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:uint16,offset,count)
.
882 883 884 |
# File 'lib/ronin/support/binary/buffer.rb', line 882 def get_array_of_uint16(offset,count) get_array_of(:uint16,offset,count) end |
#get_array_of_uint32(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:uint32,offset,count)
.
900 901 902 |
# File 'lib/ronin/support/binary/buffer.rb', line 900 def get_array_of_uint32(offset,count) get_array_of(:uint32,offset,count) end |
#get_array_of_uint64(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:uint64,offset,count)
.
918 919 920 |
# File 'lib/ronin/support/binary/buffer.rb', line 918 def get_array_of_uint64(offset,count) get_array_of(:uint64,offset,count) end |
#get_array_of_uint8(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:uint8,offset,count)
.
864 865 866 |
# File 'lib/ronin/support/binary/buffer.rb', line 864 def get_array_of_uint8(offset,count) get_array_of(:uint8,offset,count) end |
#get_array_of_ulong(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:ulong,offset,count)
.
1048 1049 1050 |
# File 'lib/ronin/support/binary/buffer.rb', line 1048 def get_array_of_ulong(offset,count) get_array_of(:ulong,offset,count) end |
#get_array_of_ulong_long(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:ulong_long,offset,count)
.
1066 1067 1068 |
# File 'lib/ronin/support/binary/buffer.rb', line 1066 def get_array_of_ulong_long(offset,count) get_array_of(:ulong_long,offset,count) end |
#get_array_of_ushort(offset, count) ⇒ ::Array<Integer>
Alias to get_array_of(:ushort,offset,count)
.
1010 1011 1012 |
# File 'lib/ronin/support/binary/buffer.rb', line 1010 def get_array_of_ushort(offset,count) get_array_of(:ushort,offset,count) end |
#get_byte(offset) ⇒ Integer
Alias for get(:byte,offset)
.
225 226 227 |
# File 'lib/ronin/support/binary/buffer.rb', line 225 def get_byte(offset) get(:byte,offset) end |
#get_char(offset) ⇒ String
Alias for get(:char,offset)
.
240 241 242 |
# File 'lib/ronin/support/binary/buffer.rb', line 240 def get_char(offset) get(:char,offset) end |
#get_double(offset) ⇒ Float
Alias for get(:double,offset)
.
592 593 594 |
# File 'lib/ronin/support/binary/buffer.rb', line 592 def get_double(offset) get(:double,offset) end |
#get_float(offset) ⇒ Float
Alias for get(:float,offset)
.
577 578 579 |
# File 'lib/ronin/support/binary/buffer.rb', line 577 def get_float(offset) get(:float,offset) end |
#get_float32(offset) ⇒ Float
Alias for get(:float32,offset)
.
547 548 549 |
# File 'lib/ronin/support/binary/buffer.rb', line 547 def get_float32(offset) get(:float32,offset) end |
#get_float64(offset) ⇒ Float
Alias for get(:float64,offset)
.
562 563 564 |
# File 'lib/ronin/support/binary/buffer.rb', line 562 def get_float64(offset) get(:float64,offset) end |
#get_int(offset) ⇒ Integer
Alias for get(:int,offset)
.
442 443 444 |
# File 'lib/ronin/support/binary/buffer.rb', line 442 def get_int(offset) get(:int,offset) end |
#get_int16(offset) ⇒ Integer
Alias for get(:int16,offset)
.
322 323 324 |
# File 'lib/ronin/support/binary/buffer.rb', line 322 def get_int16(offset) get(:int16,offset) end |
#get_int32(offset) ⇒ Integer
Alias for get(:int32,offset)
.
337 338 339 |
# File 'lib/ronin/support/binary/buffer.rb', line 337 def get_int32(offset) get(:int32,offset) end |
#get_int64(offset) ⇒ Integer
Alias for get(:int64,offset)
.
352 353 354 |
# File 'lib/ronin/support/binary/buffer.rb', line 352 def get_int64(offset) get(:int64,offset) end |
#get_int8(offset) ⇒ Integer
Alias for get(:int8,offset)
.
307 308 309 |
# File 'lib/ronin/support/binary/buffer.rb', line 307 def get_int8(offset) get(:int8,offset) end |
#get_long(offset) ⇒ Integer
Alias for get(:long,offset)
.
457 458 459 |
# File 'lib/ronin/support/binary/buffer.rb', line 457 def get_long(offset) get(:long,offset) end |
#get_long_long(offset) ⇒ Integer
Alias for get(:long_long,offset)
.
472 473 474 |
# File 'lib/ronin/support/binary/buffer.rb', line 472 def get_long_long(offset) get(:long_long,offset) end |
#get_short(offset) ⇒ Integer
Alias for get(:short,offset)
.
427 428 429 |
# File 'lib/ronin/support/binary/buffer.rb', line 427 def get_short(offset) get(:short,offset) end |
#get_string(offset, length = nil) ⇒ String
Reads a null-byte terminated C string from the buffer, at the given offset.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/ronin/support/binary/buffer.rb', line 272 def get_string(offset,length=nil) if (offset < 0) || (offset >= size) raise(IndexError,"offset #{offset} is out of bounds: 0...#{size - 1}") elsif (length && (offset + length) > size) raise(IndexError,"offset #{offset} or length #{length} is out of bounds: 0...#{size - 1}") end if length substring = @string[offset,length] if (null_byte_index = substring.index("\0")) substring[0...null_byte_index] else substring end else if (null_byte_index = @string.index("\0",offset)) @string[offset...null_byte_index] else @string[offset..] end end end |
#get_uchar(offset) ⇒ String
Alias for get(:uchar,offset)
.
255 256 257 |
# File 'lib/ronin/support/binary/buffer.rb', line 255 def get_uchar(offset) get(:uchar,offset) end |
#get_uint(offset) ⇒ Integer
Alias for get(:uint,offset)
.
502 503 504 |
# File 'lib/ronin/support/binary/buffer.rb', line 502 def get_uint(offset) get(:uint,offset) end |
#get_uint16(offset) ⇒ Integer
Alias for get(:uint16,offset)
.
382 383 384 |
# File 'lib/ronin/support/binary/buffer.rb', line 382 def get_uint16(offset) get(:uint16,offset) end |
#get_uint32(offset) ⇒ Integer
Alias for get(:uint32,offset)
.
397 398 399 |
# File 'lib/ronin/support/binary/buffer.rb', line 397 def get_uint32(offset) get(:uint32,offset) end |
#get_uint64(offset) ⇒ Integer
Alias for get(:uint64,offset)
.
412 413 414 |
# File 'lib/ronin/support/binary/buffer.rb', line 412 def get_uint64(offset) get(:uint64,offset) end |
#get_uint8(offset) ⇒ Integer
Alias for get(:uint8,offset)
.
367 368 369 |
# File 'lib/ronin/support/binary/buffer.rb', line 367 def get_uint8(offset) get(:uint8,offset) end |
#get_ulong(offset) ⇒ Integer
Alias for get(:ulong,offset)
.
517 518 519 |
# File 'lib/ronin/support/binary/buffer.rb', line 517 def get_ulong(offset) get(:ulong,offset) end |
#get_ulong_long(offset) ⇒ Integer
Alias for get(:ulong_long,offset)
.
532 533 534 |
# File 'lib/ronin/support/binary/buffer.rb', line 532 def get_ulong_long(offset) get(:ulong_long,offset) end |
#get_ushort(offset) ⇒ Integer
Alias for get(:ushort,offset)
.
487 488 489 |
# File 'lib/ronin/support/binary/buffer.rb', line 487 def get_ushort(offset) get(:ushort,offset) end |
#put(type, offset, value) ⇒ Object
Writes a value of the given type to the given offset.
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
# File 'lib/ronin/support/binary/buffer.rb', line 1162 def put(type,offset,value) type = @type_system[type] if (offset < 0) || ((offset + type.size) > size) raise(IndexError,"offset #{offset} is out of bounds: 0...#{size - type.size}") end data = type.pack(value) @string[offset,type.size] = data return self end |
#put_array_of(type, offset, array) ⇒ self
Writes an array of the given type, to the given offset within the buffer.
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
# File 'lib/ronin/support/binary/buffer.rb', line 1605 def put_array_of(type,offset,array) type = @type_system[type] array_type = type[array.length] if (offset < 0) || ((offset + array_type.size) > size) raise(IndexError,"offset #{offset} or size #{array_type.size} is out of bounds: 0...#{size - type.size}") end data = array_type.pack(array) @string[offset,array_type.size] = data return self end |
#put_array_of_byte(offset, bytes) ⇒ self Also known as: put_bytes
Alias to put_array_of(:byte,offset,bytes)
.
1632 1633 1634 |
# File 'lib/ronin/support/binary/buffer.rb', line 1632 def put_array_of_byte(offset,bytes) put_array_of(:byte,offset,bytes) end |
#put_array_of_char(offset, chars) ⇒ self Also known as: put_chars
Alias to put_array_of(:char,offset,bytes)
.
1651 1652 1653 |
# File 'lib/ronin/support/binary/buffer.rb', line 1651 def put_array_of_char(offset,chars) put_array_of(:char,offset,chars) end |
#put_array_of_double(offset, floats) ⇒ self Also known as: put_doubles
Alias to put_array_of(:double,offset,floats)
.
2018 2019 2020 |
# File 'lib/ronin/support/binary/buffer.rb', line 2018 def put_array_of_double(offset,floats) put_array_of(:double,offset,floats) end |
#put_array_of_float(offset, floats) ⇒ self Also known as: put_floats
Alias to put_array_of(:float,offset,floats)
.
1999 2000 2001 |
# File 'lib/ronin/support/binary/buffer.rb', line 1999 def put_array_of_float(offset,floats) put_array_of(:float,offset,floats) end |
#put_array_of_float32(offset, floats) ⇒ self
Alias to put_array_of(:float32,offset,floats)
.
1965 1966 1967 |
# File 'lib/ronin/support/binary/buffer.rb', line 1965 def put_array_of_float32(offset,floats) put_array_of(:float32,offset,floats) end |
#put_array_of_float64(offset, floats) ⇒ self
Alias to put_array_of(:float64,offset,floats)
.
1982 1983 1984 |
# File 'lib/ronin/support/binary/buffer.rb', line 1982 def put_array_of_float64(offset,floats) put_array_of(:float64,offset,floats) end |
#put_array_of_int(offset, ints) ⇒ self Also known as: put_ints
Alias to put_array_of(:int,offset,ints)
.
1842 1843 1844 |
# File 'lib/ronin/support/binary/buffer.rb', line 1842 def put_array_of_int(offset,ints) put_array_of(:int,offset,ints) end |
#put_array_of_int16(offset, ints) ⇒ self
Alias to put_array_of(:int16,offset,ints)
.
1706 1707 1708 |
# File 'lib/ronin/support/binary/buffer.rb', line 1706 def put_array_of_int16(offset,ints) put_array_of(:int16,offset,ints) end |
#put_array_of_int32(offset, ints) ⇒ self
Alias to put_array_of(:int32,offset,ints)
.
1723 1724 1725 |
# File 'lib/ronin/support/binary/buffer.rb', line 1723 def put_array_of_int32(offset,ints) put_array_of(:int32,offset,ints) end |
#put_array_of_int64(offset, ints) ⇒ self
Alias to put_array_of(:int64,offset,ints)
.
1740 1741 1742 |
# File 'lib/ronin/support/binary/buffer.rb', line 1740 def put_array_of_int64(offset,ints) put_array_of(:int64,offset,ints) end |
#put_array_of_int8(offset, ints) ⇒ self
Alias to put_array_of(:int8,offset,ints)
.
1689 1690 1691 |
# File 'lib/ronin/support/binary/buffer.rb', line 1689 def put_array_of_int8(offset,ints) put_array_of(:int8,offset,ints) end |
#put_array_of_long(offset, ints) ⇒ self
Alias to put_array_of(:long,offset,ints)
.
1861 1862 1863 |
# File 'lib/ronin/support/binary/buffer.rb', line 1861 def put_array_of_long(offset,ints) put_array_of(:long,offset,ints) end |
#put_array_of_long_long(offset, ints) ⇒ self
Alias to put_array_of(:long_long,offset,ints)
.
1878 1879 1880 |
# File 'lib/ronin/support/binary/buffer.rb', line 1878 def put_array_of_long_long(offset,ints) put_array_of(:long_long,offset,ints) end |
#put_array_of_short(offset, ints) ⇒ self
Alias to put_array_of(:short,offset,ints)
.
1825 1826 1827 |
# File 'lib/ronin/support/binary/buffer.rb', line 1825 def put_array_of_short(offset,ints) put_array_of(:short,offset,ints) end |
#put_array_of_uchar(offset, chars) ⇒ self Also known as: put_uchars
Alias to put_array_of(:uchar,offset,bytes)
.
1670 1671 1672 |
# File 'lib/ronin/support/binary/buffer.rb', line 1670 def put_array_of_uchar(offset,chars) put_array_of(:uchar,offset,chars) end |
#put_array_of_uint(offset, uints) ⇒ self Also known as: put_uints
Alias to put_array_of(:uint,offset,uints)
.
1912 1913 1914 |
# File 'lib/ronin/support/binary/buffer.rb', line 1912 def put_array_of_uint(offset,uints) put_array_of(:uint,offset,uints) end |
#put_array_of_uint16(offset, uints) ⇒ self
Alias to put_array_of(:uint16,offset,uints)
.
1774 1775 1776 |
# File 'lib/ronin/support/binary/buffer.rb', line 1774 def put_array_of_uint16(offset,uints) put_array_of(:uint16,offset,uints) end |
#put_array_of_uint32(offset, uints) ⇒ self
Alias to put_array_of(:uint32,offset,uints)
.
1791 1792 1793 |
# File 'lib/ronin/support/binary/buffer.rb', line 1791 def put_array_of_uint32(offset,uints) put_array_of(:uint32,offset,uints) end |
#put_array_of_uint64(offset, uints) ⇒ self
Alias to put_array_of(:uint64,offset,uints)
.
1808 1809 1810 |
# File 'lib/ronin/support/binary/buffer.rb', line 1808 def put_array_of_uint64(offset,uints) put_array_of(:uint64,offset,uints) end |
#put_array_of_uint8(offset, uints) ⇒ self
Alias to put_array_of(:uint8,offset,uints)
.
1757 1758 1759 |
# File 'lib/ronin/support/binary/buffer.rb', line 1757 def put_array_of_uint8(offset,uints) put_array_of(:uint8,offset,uints) end |
#put_array_of_ulong(offset, uints) ⇒ self
Alias to put_array_of(:ulong,offset,uints)
.
1931 1932 1933 |
# File 'lib/ronin/support/binary/buffer.rb', line 1931 def put_array_of_ulong(offset,uints) put_array_of(:ulong,offset,uints) end |
#put_array_of_ulong_long(offset, uints) ⇒ self
Alias to put_array_of(:ulong_long,offset,uints)
.
1948 1949 1950 |
# File 'lib/ronin/support/binary/buffer.rb', line 1948 def put_array_of_ulong_long(offset,uints) put_array_of(:ulong_long,offset,uints) end |
#put_array_of_ushort(offset, uints) ⇒ self
Alias to put_array_of(:ushort,offset,uints)
.
1895 1896 1897 |
# File 'lib/ronin/support/binary/buffer.rb', line 1895 def put_array_of_ushort(offset,uints) put_array_of(:ushort,offset,uints) end |
#put_byte(offset, value) ⇒ self
Alias for put(:byte,offset,value)
.
1188 1189 1190 |
# File 'lib/ronin/support/binary/buffer.rb', line 1188 def put_byte(offset,value) put(:byte,offset,value) end |
#put_char(offset, value) ⇒ self
Alias for put(:char,offset,value)
.
1205 1206 1207 |
# File 'lib/ronin/support/binary/buffer.rb', line 1205 def put_char(offset,value) put(:char,offset,value) end |
#put_double(offset, value) ⇒ self
Alias for put(:double,offset,value)
.
1586 1587 1588 |
# File 'lib/ronin/support/binary/buffer.rb', line 1586 def put_double(offset,value) put(:double,offset,value) end |
#put_float(offset, value) ⇒ self
Alias for put(:float,offset,value)
.
1569 1570 1571 |
# File 'lib/ronin/support/binary/buffer.rb', line 1569 def put_float(offset,value) put(:float,offset,value) end |
#put_float32(offset, value) ⇒ self
Alias for put(:float32,offset,value)
.
1535 1536 1537 |
# File 'lib/ronin/support/binary/buffer.rb', line 1535 def put_float32(offset,value) put(:float32,offset,value) end |
#put_float64(offset, value) ⇒ self
Alias for put(:float64,offset,value)
.
1552 1553 1554 |
# File 'lib/ronin/support/binary/buffer.rb', line 1552 def put_float64(offset,value) put(:float64,offset,value) end |
#put_int(offset, value) ⇒ self
Alias for put(:int,offset,value)
.
1416 1417 1418 |
# File 'lib/ronin/support/binary/buffer.rb', line 1416 def put_int(offset,value) put(:int,offset,value) end |
#put_int16(offset, value) ⇒ self
Alias for put(:int16,offset,value)
.
1280 1281 1282 |
# File 'lib/ronin/support/binary/buffer.rb', line 1280 def put_int16(offset,value) put(:int16,offset,value) end |
#put_int32(offset, value) ⇒ self
Alias for put(:int32,offset,value)
.
1297 1298 1299 |
# File 'lib/ronin/support/binary/buffer.rb', line 1297 def put_int32(offset,value) put(:int32,offset,value) end |
#put_int64(offset, value) ⇒ self
Alias for put(:int64,offset,value)
.
1314 1315 1316 |
# File 'lib/ronin/support/binary/buffer.rb', line 1314 def put_int64(offset,value) put(:int64,offset,value) end |
#put_int8(offset, value) ⇒ self
Alias for put(:int8,offset,value)
.
1263 1264 1265 |
# File 'lib/ronin/support/binary/buffer.rb', line 1263 def put_int8(offset,value) put(:int8,offset,value) end |
#put_long(offset, value) ⇒ self
Alias for put(:long,offset,value)
.
1433 1434 1435 |
# File 'lib/ronin/support/binary/buffer.rb', line 1433 def put_long(offset,value) put(:long,offset,value) end |
#put_long_long(offset, value) ⇒ self
Alias for put(:long_long,offset,value)
.
1450 1451 1452 |
# File 'lib/ronin/support/binary/buffer.rb', line 1450 def put_long_long(offset,value) put(:long_long,offset,value) end |
#put_short(offset, value) ⇒ self
Alias for put(:short,offset,value)
.
1399 1400 1401 |
# File 'lib/ronin/support/binary/buffer.rb', line 1399 def put_short(offset,value) put(:short,offset,value) end |
#put_string(offset, string) ⇒ self
Writes a null-terminated C string into the buffer at the given offset.
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 |
# File 'lib/ronin/support/binary/buffer.rb', line 1221 def put_string(offset,string) ascii_string = string.encode(Encoding::ASCII_8BIT) cstring = "#{ascii_string}\0" if (offset < 0) || ((offset + cstring.bytesize) >= size) raise(IndexError,"offset #{offset} or C string size #{cstring.bytesize} is out of bounds: 0...#{size - 1}") end @string[offset,cstring.bytesize] = cstring return self end |
#put_uchar(offset, value) ⇒ self
Alias for put(:uchar,offset,value)
.
1246 1247 1248 |
# File 'lib/ronin/support/binary/buffer.rb', line 1246 def put_uchar(offset,value) put(:uchar,offset,value) end |
#put_uint(offset, value) ⇒ self
Alias for put(:uint,offset,value)
.
1484 1485 1486 |
# File 'lib/ronin/support/binary/buffer.rb', line 1484 def put_uint(offset,value) put(:uint,offset,value) end |
#put_uint16(offset, value) ⇒ self
Alias for put(:uint16,offset,value)
.
1348 1349 1350 |
# File 'lib/ronin/support/binary/buffer.rb', line 1348 def put_uint16(offset,value) put(:uint16,offset,value) end |
#put_uint32(offset, value) ⇒ self
Alias for put(:uint32,offset,value)
.
1365 1366 1367 |
# File 'lib/ronin/support/binary/buffer.rb', line 1365 def put_uint32(offset,value) put(:uint32,offset,value) end |
#put_uint64(offset, value) ⇒ self
Alias for put(:uint64,offset,value)
.
1382 1383 1384 |
# File 'lib/ronin/support/binary/buffer.rb', line 1382 def put_uint64(offset,value) put(:uint64,offset,value) end |
#put_uint8(offset, value) ⇒ self
Alias for put(:uint8,offset,value)
.
1331 1332 1333 |
# File 'lib/ronin/support/binary/buffer.rb', line 1331 def put_uint8(offset,value) put(:uint8,offset,value) end |
#put_ulong(offset, value) ⇒ self
Alias for put(:ulong,offset,value)
.
1501 1502 1503 |
# File 'lib/ronin/support/binary/buffer.rb', line 1501 def put_ulong(offset,value) put(:ulong,offset,value) end |
#put_ulong_long(offset, value) ⇒ self
Alias for put(:ulong_long,offset,value)
.
1518 1519 1520 |
# File 'lib/ronin/support/binary/buffer.rb', line 1518 def put_ulong_long(offset,value) put(:ulong_long,offset,value) end |
#put_ushort(offset, value) ⇒ self
Alias for put(:ushort,offset,value)
.
1467 1468 1469 |
# File 'lib/ronin/support/binary/buffer.rb', line 1467 def put_ushort(offset,value) put(:ushort,offset,value) end |
#struct_at(offset, struct_class) ⇒ Binary::Struct
Returns a new Struct instance starting at the given offset.
658 659 660 661 662 663 664 |
# File 'lib/ronin/support/binary/buffer.rb', line 658 def struct_at(offset,struct_class) unless struct_class < Struct raise(ArgumentError,"the given class must be a #{Struct} subclass: #{struct_class.inspect}") end return struct_class.new(byteslice(offset,struct_class.size)) end |
#to_s ⇒ String Also known as: to_str
Converts the buffer to a String.
181 182 183 |
# File 'lib/ronin/support/binary/buffer.rb', line 181 def to_s @string.to_s end |
#union_at(offset, union_class) ⇒ Union
Returns a new Union instance starting at the given offset.
682 683 684 685 686 687 688 |
# File 'lib/ronin/support/binary/buffer.rb', line 682 def union_at(offset,union_class) unless union_class < Union raise(ArgumentError,"the given class must be a #{Union} subclass: #{union_class.inspect}") end return union_class.new(byteslice(offset,union_class.size)) end |