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.
The desired Operating System (OS) for the values within the buffer.
99 100 101 102 103 |
# File 'lib/ronin/support/binary/buffer.rb', line 99 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.
121 122 123 |
# File 'lib/ronin/support/binary/buffer.rb', line 121 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.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ronin/support/binary/buffer.rb', line 160 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.
640 641 642 643 644 645 |
# File 'lib/ronin/support/binary/buffer.rb', line 640 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.
617 618 619 |
# File 'lib/ronin/support/binary/buffer.rb', line 617 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.
208 209 210 211 212 213 214 215 216 217 |
# File 'lib/ronin/support/binary/buffer.rb', line 208 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.
711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/ronin/support/binary/buffer.rb', line 711 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).
737 738 739 |
# File 'lib/ronin/support/binary/buffer.rb', line 737 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).
757 758 759 |
# File 'lib/ronin/support/binary/buffer.rb', line 757 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).
1145 1146 1147 |
# File 'lib/ronin/support/binary/buffer.rb', line 1145 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).
1125 1126 1127 |
# File 'lib/ronin/support/binary/buffer.rb', line 1125 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).
1089 1090 1091 |
# File 'lib/ronin/support/binary/buffer.rb', line 1089 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).
1107 1108 1109 |
# File 'lib/ronin/support/binary/buffer.rb', line 1107 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).
959 960 961 |
# File 'lib/ronin/support/binary/buffer.rb', line 959 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).
815 816 817 |
# File 'lib/ronin/support/binary/buffer.rb', line 815 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).
833 834 835 |
# File 'lib/ronin/support/binary/buffer.rb', line 833 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).
851 852 853 |
# File 'lib/ronin/support/binary/buffer.rb', line 851 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).
797 798 799 |
# File 'lib/ronin/support/binary/buffer.rb', line 797 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).
979 980 981 |
# File 'lib/ronin/support/binary/buffer.rb', line 979 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).
997 998 999 |
# File 'lib/ronin/support/binary/buffer.rb', line 997 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).
941 942 943 |
# File 'lib/ronin/support/binary/buffer.rb', line 941 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).
777 778 779 |
# File 'lib/ronin/support/binary/buffer.rb', line 777 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).
1033 1034 1035 |
# File 'lib/ronin/support/binary/buffer.rb', line 1033 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).
887 888 889 |
# File 'lib/ronin/support/binary/buffer.rb', line 887 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).
905 906 907 |
# File 'lib/ronin/support/binary/buffer.rb', line 905 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).
923 924 925 |
# File 'lib/ronin/support/binary/buffer.rb', line 923 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).
869 870 871 |
# File 'lib/ronin/support/binary/buffer.rb', line 869 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).
1053 1054 1055 |
# File 'lib/ronin/support/binary/buffer.rb', line 1053 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).
1071 1072 1073 |
# File 'lib/ronin/support/binary/buffer.rb', line 1071 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).
1015 1016 1017 |
# File 'lib/ronin/support/binary/buffer.rb', line 1015 def get_array_of_ushort(offset,count) get_array_of(:ushort,offset,count) end |
#get_byte(offset) ⇒ Integer
Alias for get(:byte,offset).
230 231 232 |
# File 'lib/ronin/support/binary/buffer.rb', line 230 def get_byte(offset) get(:byte,offset) end |
#get_char(offset) ⇒ String
Alias for get(:char,offset).
245 246 247 |
# File 'lib/ronin/support/binary/buffer.rb', line 245 def get_char(offset) get(:char,offset) end |
#get_double(offset) ⇒ Float
Alias for get(:double,offset).
597 598 599 |
# File 'lib/ronin/support/binary/buffer.rb', line 597 def get_double(offset) get(:double,offset) end |
#get_float(offset) ⇒ Float
Alias for get(:float,offset).
582 583 584 |
# File 'lib/ronin/support/binary/buffer.rb', line 582 def get_float(offset) get(:float,offset) end |
#get_float32(offset) ⇒ Float
Alias for get(:float32,offset).
552 553 554 |
# File 'lib/ronin/support/binary/buffer.rb', line 552 def get_float32(offset) get(:float32,offset) end |
#get_float64(offset) ⇒ Float
Alias for get(:float64,offset).
567 568 569 |
# File 'lib/ronin/support/binary/buffer.rb', line 567 def get_float64(offset) get(:float64,offset) end |
#get_int(offset) ⇒ Integer
Alias for get(:int,offset).
447 448 449 |
# File 'lib/ronin/support/binary/buffer.rb', line 447 def get_int(offset) get(:int,offset) end |
#get_int16(offset) ⇒ Integer
Alias for get(:int16,offset).
327 328 329 |
# File 'lib/ronin/support/binary/buffer.rb', line 327 def get_int16(offset) get(:int16,offset) end |
#get_int32(offset) ⇒ Integer
Alias for get(:int32,offset).
342 343 344 |
# File 'lib/ronin/support/binary/buffer.rb', line 342 def get_int32(offset) get(:int32,offset) end |
#get_int64(offset) ⇒ Integer
Alias for get(:int64,offset).
357 358 359 |
# File 'lib/ronin/support/binary/buffer.rb', line 357 def get_int64(offset) get(:int64,offset) end |
#get_int8(offset) ⇒ Integer
Alias for get(:int8,offset).
312 313 314 |
# File 'lib/ronin/support/binary/buffer.rb', line 312 def get_int8(offset) get(:int8,offset) end |
#get_long(offset) ⇒ Integer
Alias for get(:long,offset).
462 463 464 |
# File 'lib/ronin/support/binary/buffer.rb', line 462 def get_long(offset) get(:long,offset) end |
#get_long_long(offset) ⇒ Integer
Alias for get(:long_long,offset).
477 478 479 |
# File 'lib/ronin/support/binary/buffer.rb', line 477 def get_long_long(offset) get(:long_long,offset) end |
#get_short(offset) ⇒ Integer
Alias for get(:short,offset).
432 433 434 |
# File 'lib/ronin/support/binary/buffer.rb', line 432 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.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/ronin/support/binary/buffer.rb', line 277 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).
260 261 262 |
# File 'lib/ronin/support/binary/buffer.rb', line 260 def get_uchar(offset) get(:uchar,offset) end |
#get_uint(offset) ⇒ Integer
Alias for get(:uint,offset).
507 508 509 |
# File 'lib/ronin/support/binary/buffer.rb', line 507 def get_uint(offset) get(:uint,offset) end |
#get_uint16(offset) ⇒ Integer
Alias for get(:uint16,offset).
387 388 389 |
# File 'lib/ronin/support/binary/buffer.rb', line 387 def get_uint16(offset) get(:uint16,offset) end |
#get_uint32(offset) ⇒ Integer
Alias for get(:uint32,offset).
402 403 404 |
# File 'lib/ronin/support/binary/buffer.rb', line 402 def get_uint32(offset) get(:uint32,offset) end |
#get_uint64(offset) ⇒ Integer
Alias for get(:uint64,offset).
417 418 419 |
# File 'lib/ronin/support/binary/buffer.rb', line 417 def get_uint64(offset) get(:uint64,offset) end |
#get_uint8(offset) ⇒ Integer
Alias for get(:uint8,offset).
372 373 374 |
# File 'lib/ronin/support/binary/buffer.rb', line 372 def get_uint8(offset) get(:uint8,offset) end |
#get_ulong(offset) ⇒ Integer
Alias for get(:ulong,offset).
522 523 524 |
# File 'lib/ronin/support/binary/buffer.rb', line 522 def get_ulong(offset) get(:ulong,offset) end |
#get_ulong_long(offset) ⇒ Integer
Alias for get(:ulong_long,offset).
537 538 539 |
# File 'lib/ronin/support/binary/buffer.rb', line 537 def get_ulong_long(offset) get(:ulong_long,offset) end |
#get_ushort(offset) ⇒ Integer
Alias for get(:ushort,offset).
492 493 494 |
# File 'lib/ronin/support/binary/buffer.rb', line 492 def get_ushort(offset) get(:ushort,offset) end |
#put(type, offset, value) ⇒ Object
Writes a value of the given type to the given offset.
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 |
# File 'lib/ronin/support/binary/buffer.rb', line 1167 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.
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 |
# File 'lib/ronin/support/binary/buffer.rb', line 1610 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).
1637 1638 1639 |
# File 'lib/ronin/support/binary/buffer.rb', line 1637 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).
1656 1657 1658 |
# File 'lib/ronin/support/binary/buffer.rb', line 1656 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).
2023 2024 2025 |
# File 'lib/ronin/support/binary/buffer.rb', line 2023 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).
2004 2005 2006 |
# File 'lib/ronin/support/binary/buffer.rb', line 2004 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).
1970 1971 1972 |
# File 'lib/ronin/support/binary/buffer.rb', line 1970 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).
1987 1988 1989 |
# File 'lib/ronin/support/binary/buffer.rb', line 1987 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).
1847 1848 1849 |
# File 'lib/ronin/support/binary/buffer.rb', line 1847 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).
1711 1712 1713 |
# File 'lib/ronin/support/binary/buffer.rb', line 1711 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).
1728 1729 1730 |
# File 'lib/ronin/support/binary/buffer.rb', line 1728 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).
1745 1746 1747 |
# File 'lib/ronin/support/binary/buffer.rb', line 1745 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).
1694 1695 1696 |
# File 'lib/ronin/support/binary/buffer.rb', line 1694 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).
1866 1867 1868 |
# File 'lib/ronin/support/binary/buffer.rb', line 1866 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).
1883 1884 1885 |
# File 'lib/ronin/support/binary/buffer.rb', line 1883 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).
1830 1831 1832 |
# File 'lib/ronin/support/binary/buffer.rb', line 1830 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).
1675 1676 1677 |
# File 'lib/ronin/support/binary/buffer.rb', line 1675 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).
1917 1918 1919 |
# File 'lib/ronin/support/binary/buffer.rb', line 1917 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).
1779 1780 1781 |
# File 'lib/ronin/support/binary/buffer.rb', line 1779 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).
1796 1797 1798 |
# File 'lib/ronin/support/binary/buffer.rb', line 1796 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).
1813 1814 1815 |
# File 'lib/ronin/support/binary/buffer.rb', line 1813 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).
1762 1763 1764 |
# File 'lib/ronin/support/binary/buffer.rb', line 1762 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).
1936 1937 1938 |
# File 'lib/ronin/support/binary/buffer.rb', line 1936 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).
1953 1954 1955 |
# File 'lib/ronin/support/binary/buffer.rb', line 1953 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).
1900 1901 1902 |
# File 'lib/ronin/support/binary/buffer.rb', line 1900 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).
1193 1194 1195 |
# File 'lib/ronin/support/binary/buffer.rb', line 1193 def put_byte(offset,value) put(:byte,offset,value) end |
#put_char(offset, value) ⇒ self
Alias for put(:char,offset,value).
1210 1211 1212 |
# File 'lib/ronin/support/binary/buffer.rb', line 1210 def put_char(offset,value) put(:char,offset,value) end |
#put_double(offset, value) ⇒ self
Alias for put(:double,offset,value).
1591 1592 1593 |
# File 'lib/ronin/support/binary/buffer.rb', line 1591 def put_double(offset,value) put(:double,offset,value) end |
#put_float(offset, value) ⇒ self
Alias for put(:float,offset,value).
1574 1575 1576 |
# File 'lib/ronin/support/binary/buffer.rb', line 1574 def put_float(offset,value) put(:float,offset,value) end |
#put_float32(offset, value) ⇒ self
Alias for put(:float32,offset,value).
1540 1541 1542 |
# File 'lib/ronin/support/binary/buffer.rb', line 1540 def put_float32(offset,value) put(:float32,offset,value) end |
#put_float64(offset, value) ⇒ self
Alias for put(:float64,offset,value).
1557 1558 1559 |
# File 'lib/ronin/support/binary/buffer.rb', line 1557 def put_float64(offset,value) put(:float64,offset,value) end |
#put_int(offset, value) ⇒ self
Alias for put(:int,offset,value).
1421 1422 1423 |
# File 'lib/ronin/support/binary/buffer.rb', line 1421 def put_int(offset,value) put(:int,offset,value) end |
#put_int16(offset, value) ⇒ self
Alias for put(:int16,offset,value).
1285 1286 1287 |
# File 'lib/ronin/support/binary/buffer.rb', line 1285 def put_int16(offset,value) put(:int16,offset,value) end |
#put_int32(offset, value) ⇒ self
Alias for put(:int32,offset,value).
1302 1303 1304 |
# File 'lib/ronin/support/binary/buffer.rb', line 1302 def put_int32(offset,value) put(:int32,offset,value) end |
#put_int64(offset, value) ⇒ self
Alias for put(:int64,offset,value).
1319 1320 1321 |
# File 'lib/ronin/support/binary/buffer.rb', line 1319 def put_int64(offset,value) put(:int64,offset,value) end |
#put_int8(offset, value) ⇒ self
Alias for put(:int8,offset,value).
1268 1269 1270 |
# File 'lib/ronin/support/binary/buffer.rb', line 1268 def put_int8(offset,value) put(:int8,offset,value) end |
#put_long(offset, value) ⇒ self
Alias for put(:long,offset,value).
1438 1439 1440 |
# File 'lib/ronin/support/binary/buffer.rb', line 1438 def put_long(offset,value) put(:long,offset,value) end |
#put_long_long(offset, value) ⇒ self
Alias for put(:long_long,offset,value).
1455 1456 1457 |
# File 'lib/ronin/support/binary/buffer.rb', line 1455 def put_long_long(offset,value) put(:long_long,offset,value) end |
#put_short(offset, value) ⇒ self
Alias for put(:short,offset,value).
1404 1405 1406 |
# File 'lib/ronin/support/binary/buffer.rb', line 1404 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.
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 |
# File 'lib/ronin/support/binary/buffer.rb', line 1226 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).
1251 1252 1253 |
# File 'lib/ronin/support/binary/buffer.rb', line 1251 def put_uchar(offset,value) put(:uchar,offset,value) end |
#put_uint(offset, value) ⇒ self
Alias for put(:uint,offset,value).
1489 1490 1491 |
# File 'lib/ronin/support/binary/buffer.rb', line 1489 def put_uint(offset,value) put(:uint,offset,value) end |
#put_uint16(offset, value) ⇒ self
Alias for put(:uint16,offset,value).
1353 1354 1355 |
# File 'lib/ronin/support/binary/buffer.rb', line 1353 def put_uint16(offset,value) put(:uint16,offset,value) end |
#put_uint32(offset, value) ⇒ self
Alias for put(:uint32,offset,value).
1370 1371 1372 |
# File 'lib/ronin/support/binary/buffer.rb', line 1370 def put_uint32(offset,value) put(:uint32,offset,value) end |
#put_uint64(offset, value) ⇒ self
Alias for put(:uint64,offset,value).
1387 1388 1389 |
# File 'lib/ronin/support/binary/buffer.rb', line 1387 def put_uint64(offset,value) put(:uint64,offset,value) end |
#put_uint8(offset, value) ⇒ self
Alias for put(:uint8,offset,value).
1336 1337 1338 |
# File 'lib/ronin/support/binary/buffer.rb', line 1336 def put_uint8(offset,value) put(:uint8,offset,value) end |
#put_ulong(offset, value) ⇒ self
Alias for put(:ulong,offset,value).
1506 1507 1508 |
# File 'lib/ronin/support/binary/buffer.rb', line 1506 def put_ulong(offset,value) put(:ulong,offset,value) end |
#put_ulong_long(offset, value) ⇒ self
Alias for put(:ulong_long,offset,value).
1523 1524 1525 |
# File 'lib/ronin/support/binary/buffer.rb', line 1523 def put_ulong_long(offset,value) put(:ulong_long,offset,value) end |
#put_ushort(offset, value) ⇒ self
Alias for put(:ushort,offset,value).
1472 1473 1474 |
# File 'lib/ronin/support/binary/buffer.rb', line 1472 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.
663 664 665 666 667 668 669 |
# File 'lib/ronin/support/binary/buffer.rb', line 663 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.
186 187 188 |
# File 'lib/ronin/support/binary/buffer.rb', line 186 def to_s @string.to_s end |
#union_at(offset, union_class) ⇒ Union
Returns a new Union instance starting at the given offset.
687 688 689 690 691 692 693 |
# File 'lib/ronin/support/binary/buffer.rb', line 687 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 |