ronin-support 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +14 -0
- data/.rubocop.yml +109 -0
- data/ChangeLog.md +33 -1
- data/Gemfile +8 -4
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/examples/ssl_proxy.rb +2 -1
- data/examples/tcp_proxy.rb +6 -4
- data/lib/ronin/support/archive/core_ext/file.rb +43 -0
- data/lib/ronin/support/archive/core_ext.rb +1 -1
- data/lib/ronin/support/archive/tar/writer.rb +2 -2
- data/lib/ronin/support/archive/tar.rb +4 -4
- data/lib/ronin/support/archive/zip/reader.rb +2 -2
- data/lib/ronin/support/binary/array.rb +5 -8
- data/lib/ronin/support/binary/bit_flip.rb +7 -1
- data/lib/ronin/support/binary/buffer.rb +25 -25
- data/lib/ronin/support/binary/byte_slice.rb +17 -17
- data/lib/ronin/support/binary/core_ext.rb +2 -0
- data/lib/ronin/support/binary/cstring.rb +50 -4
- data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/arm.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/arm64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/mips.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +4 -0
- data/lib/ronin/support/binary/ctypes/arch/mips64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/ppc.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/x86.rb +3 -0
- data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +3 -0
- data/lib/ronin/support/binary/ctypes/array_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/big_endian.rb +3 -0
- data/lib/ronin/support/binary/ctypes/enum_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/little_endian.rb +3 -0
- data/lib/ronin/support/binary/ctypes/native.rb +3 -0
- data/lib/ronin/support/binary/ctypes/os/bsd.rb +1 -1
- data/lib/ronin/support/binary/ctypes/scalar_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/struct_type.rb +3 -3
- data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -8
- data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +2 -2
- data/lib/ronin/support/binary/ctypes/union_type.rb +3 -3
- data/lib/ronin/support/binary/ctypes.rb +3 -3
- data/lib/ronin/support/binary/memory.rb +2 -2
- data/lib/ronin/support/binary/packet.rb +80 -0
- data/lib/ronin/support/binary/stack.rb +6 -7
- data/lib/ronin/support/binary/struct/member.rb +5 -3
- data/lib/ronin/support/binary/struct.rb +81 -79
- data/lib/ronin/support/binary/template.rb +2 -5
- data/lib/ronin/support/binary/unhexdump/parser.rb +11 -11
- data/lib/ronin/support/binary/union.rb +22 -22
- data/lib/ronin/support/binary.rb +1 -0
- data/lib/ronin/support/cli/ansi.rb +0 -1
- data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
- data/lib/ronin/support/cli/io_shell.rb +4 -4
- data/lib/ronin/support/cli/printing.rb +3 -3
- data/lib/ronin/support/compression/core_ext/file.rb +16 -0
- data/lib/ronin/support/compression/zlib.rb +1 -1
- data/lib/ronin/support/core_ext/enumerable.rb +0 -2
- data/lib/ronin/support/core_ext/file.rb +1 -1
- data/lib/ronin/support/core_ext/kernel.rb +6 -9
- data/lib/ronin/support/core_ext/string.rb +2 -2
- data/lib/ronin/support/crypto/cert.rb +11 -15
- data/lib/ronin/support/crypto/cert_chain.rb +1 -1
- data/lib/ronin/support/crypto/cipher/aes.rb +3 -0
- data/lib/ronin/support/crypto/cipher/aes128.rb +4 -1
- data/lib/ronin/support/crypto/cipher/aes256.rb +4 -1
- data/lib/ronin/support/crypto/cipher.rb +1 -1
- data/lib/ronin/support/crypto/core_ext/file.rb +33 -1
- data/lib/ronin/support/crypto/core_ext/string.rb +34 -2
- data/lib/ronin/support/crypto/key/methods.rb +4 -1
- data/lib/ronin/support/crypto/key.rb +5 -2
- data/lib/ronin/support/crypto/openssl.rb +1 -1
- data/lib/ronin/support/crypto.rb +0 -1
- data/lib/ronin/support/encoding/base16.rb +2 -2
- data/lib/ronin/support/encoding/base32.rb +29 -18
- data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/c/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/c.rb +6 -6
- data/lib/ronin/support/encoding/core_ext/string.rb +2 -2
- data/lib/ronin/support/encoding/hex/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/hex.rb +4 -4
- data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/js.rb +5 -5
- data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +2 -2
- data/lib/ronin/support/encoding/powershell.rb +5 -6
- data/lib/ronin/support/encoding/quoted_printable.rb +3 -1
- data/lib/ronin/support/encoding/ruby.rb +5 -5
- data/lib/ronin/support/encoding/shell/core_ext/integer.rb +2 -2
- data/lib/ronin/support/encoding/shell.rb +3 -3
- data/lib/ronin/support/encoding/sql.rb +1 -1
- data/lib/ronin/support/encoding/uuencoding.rb +3 -1
- data/lib/ronin/support/encoding/xml.rb +3 -3
- data/lib/ronin/support/encoding.rb +95 -0
- data/lib/ronin/support/network/asn/list.rb +6 -1
- data/lib/ronin/support/network/asn/record.rb +3 -0
- data/lib/ronin/support/network/asn/record_set.rb +3 -0
- data/lib/ronin/support/network/asn.rb +167 -6
- data/lib/ronin/support/network/dns/mixin.rb +2 -10
- data/lib/ronin/support/network/dns/resolver.rb +3 -0
- data/lib/ronin/support/network/domain.rb +21 -21
- data/lib/ronin/support/network/email_address.rb +1 -5
- data/lib/ronin/support/network/esmtp/mixin.rb +1 -0
- data/lib/ronin/support/network/ftp/mixin.rb +1 -1
- data/lib/ronin/support/network/host.rb +75 -47
- data/lib/ronin/support/network/http/core_ext/uri/http.rb +8 -0
- data/lib/ronin/support/network/http/core_ext.rb +1 -1
- data/lib/ronin/support/network/http.rb +317 -80
- data/lib/ronin/support/network/ip.rb +49 -23
- data/lib/ronin/support/network/ip_range/cidr.rb +1 -5
- data/lib/ronin/support/network/ip_range/glob.rb +1 -0
- data/lib/ronin/support/network/ip_range/range.rb +1 -1
- data/lib/ronin/support/network/ip_range.rb +5 -7
- data/lib/ronin/support/network/proxy.rb +4 -4
- data/lib/ronin/support/network/public_suffix/list.rb +10 -8
- data/lib/ronin/support/network/public_suffix/suffix_set.rb +3 -0
- data/lib/ronin/support/network/public_suffix.rb +9 -4
- data/lib/ronin/support/network/smtp/email.rb +0 -9
- data/lib/ronin/support/network/smtp/mixin.rb +2 -2
- data/lib/ronin/support/network/ssl/local_cert.rb +1 -3
- data/lib/ronin/support/network/ssl/mixin.rb +13 -13
- data/lib/ronin/support/network/ssl/openssl.rb +1 -1
- data/lib/ronin/support/network/ssl/proxy.rb +14 -16
- data/lib/ronin/support/network/ssl.rb +4 -2
- data/lib/ronin/support/network/tcp/proxy.rb +3 -3
- data/lib/ronin/support/network/tcp.rb +10 -12
- data/lib/ronin/support/network/telnet/mixin.rb +14 -14
- data/lib/ronin/support/network/tld/list.rb +2 -1
- data/lib/ronin/support/network/tld.rb +7 -4
- data/lib/ronin/support/network/tls/proxy.rb +1 -1
- data/lib/ronin/support/network/tls.rb +0 -2
- data/lib/ronin/support/network/udp/proxy.rb +5 -5
- data/lib/ronin/support/network/udp.rb +14 -16
- data/lib/ronin/support/path.rb +4 -4
- data/lib/ronin/support/text/erb/mixin.rb +3 -0
- data/lib/ronin/support/text/homoglyph/core_ext/string.rb +33 -0
- data/lib/ronin/support/text/homoglyph/table.rb +3 -3
- data/lib/ronin/support/text/patterns/credentials.rb +2 -2
- data/lib/ronin/support/text/patterns/crypto.rb +1 -1
- data/lib/ronin/support/text/patterns/file_system.rb +3 -4
- data/lib/ronin/support/text/patterns/network.rb +21 -21
- data/lib/ronin/support/text/patterns/numeric.rb +1 -1
- data/lib/ronin/support/text/patterns/source_code.rb +2 -2
- data/lib/ronin/support/text/random/mixin.rb +17 -17
- data/lib/ronin/support/text/random.rb +25 -25
- data/lib/ronin/support/text/typo/core_ext/string.rb +24 -0
- data/lib/ronin/support/text/typo/generator.rb +2 -2
- data/lib/ronin/support/version.rb +1 -1
- data/ronin-support.gemspec +6 -5
- metadata +3 -2
@@ -69,15 +69,15 @@ module Ronin
|
|
69
69
|
|
70
70
|
case string
|
71
71
|
when ByteSlice
|
72
|
-
if (offset < 0) || (offset+length > string.bytesize)
|
72
|
+
if (offset < 0) || ((offset + length) > string.bytesize)
|
73
73
|
raise(IndexError,"offset #{offset} or length #{length} is out of bounds: 0...#{string.bytesize}")
|
74
74
|
end
|
75
75
|
|
76
76
|
@string = string.string
|
77
|
-
@offset = string.offset+offset
|
77
|
+
@offset = string.offset + offset
|
78
78
|
@length = length
|
79
79
|
when String
|
80
|
-
if (offset < 0) || (offset+length > string.bytesize)
|
80
|
+
if (offset < 0) || ((offset + length) > string.bytesize)
|
81
81
|
raise(IndexError,"offset #{offset} or length #{length} is out of bounds: 0...#{string.bytesize}")
|
82
82
|
end
|
83
83
|
|
@@ -109,17 +109,17 @@ module Ronin
|
|
109
109
|
when Range
|
110
110
|
range = index_or_range
|
111
111
|
|
112
|
-
@string[@offset+range.begin,range.end-range.begin]
|
112
|
+
@string[@offset + range.begin,range.end - range.begin]
|
113
113
|
when Integer
|
114
114
|
index = index_or_range
|
115
115
|
|
116
116
|
case length
|
117
117
|
when Integer
|
118
|
-
@string[@offset+index,length]
|
118
|
+
@string[@offset + index,length]
|
119
119
|
when nil
|
120
|
-
@string[@offset+index]
|
120
|
+
@string[@offset + index]
|
121
121
|
when Float::INFINITY
|
122
|
-
@string[@offset+index,@length-index]
|
122
|
+
@string[@offset + index,@length - index]
|
123
123
|
else
|
124
124
|
raise(ArgumentError,"invalid length (#{length.inspect}) must be an Integer, nil, or Float::INFINITY")
|
125
125
|
end
|
@@ -151,17 +151,17 @@ module Ronin
|
|
151
151
|
when Range
|
152
152
|
range = index_or_range
|
153
153
|
|
154
|
-
@string[@offset+range.begin,range.end-range.begin] = value
|
154
|
+
@string[@offset + range.begin,range.end - range.begin] = value
|
155
155
|
when Integer
|
156
156
|
index = index_or_range
|
157
157
|
|
158
158
|
case length
|
159
159
|
when Integer
|
160
|
-
@string[@offset+index,length] = value
|
160
|
+
@string[@offset + index,length] = value
|
161
161
|
when nil
|
162
|
-
@string[@offset+index] = value
|
162
|
+
@string[@offset + index] = value
|
163
163
|
when Float::INFINITY
|
164
|
-
@string[@offset+index,@length-index] = value
|
164
|
+
@string[@offset + index,@length - index] = value
|
165
165
|
else
|
166
166
|
raise(ArgumentError,"invalid length (#{length.inspect}) must be an Integer, nil, or Float::INFINITY")
|
167
167
|
end
|
@@ -200,7 +200,7 @@ module Ronin
|
|
200
200
|
# found.
|
201
201
|
#
|
202
202
|
def index(substring,offset=0)
|
203
|
-
if (index = @string.index(substring,@offset+offset))
|
203
|
+
if (index = @string.index(substring,@offset + offset))
|
204
204
|
if index < (@offset + @length)
|
205
205
|
index - @offset
|
206
206
|
end
|
@@ -211,13 +211,13 @@ module Ronin
|
|
211
211
|
# Gets the byte at the given index within the byte slice.
|
212
212
|
#
|
213
213
|
# @param [Integer] index
|
214
|
-
#
|
214
|
+
#
|
215
215
|
# @return [Integer, nil]
|
216
216
|
# The byte at the given index, or nil if the index is out of bounds.
|
217
217
|
#
|
218
218
|
def getbyte(index)
|
219
219
|
if index < @length
|
220
|
-
@string.getbyte(@offset+index)
|
220
|
+
@string.getbyte(@offset + index)
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -235,7 +235,7 @@ module Ronin
|
|
235
235
|
#
|
236
236
|
def setbyte(index,byte)
|
237
237
|
if index < @length
|
238
|
-
@string.setbyte(@offset+index,byte)
|
238
|
+
@string.setbyte(@offset + index,byte)
|
239
239
|
else
|
240
240
|
raise(IndexError,"index #{index.inspect} is out of bounds")
|
241
241
|
end
|
@@ -257,7 +257,7 @@ module Ronin
|
|
257
257
|
def each_byte
|
258
258
|
return enum_for(__method__) unless block_given?
|
259
259
|
|
260
|
-
(@offset...(@offset
|
260
|
+
(@offset...(@offset + @length)).each do |index|
|
261
261
|
yield @string.getbyte(index)
|
262
262
|
end
|
263
263
|
end
|
@@ -288,7 +288,7 @@ module Ronin
|
|
288
288
|
def each_char
|
289
289
|
return enum_for(__method__) unless block_given?
|
290
290
|
|
291
|
-
(@offset...(@offset
|
291
|
+
(@offset...(@offset + @length)).each do |index|
|
292
292
|
yield @string[index]
|
293
293
|
end
|
294
294
|
end
|
@@ -16,6 +16,8 @@
|
|
16
16
|
# along with ronin-support. If not, see <https://www.gnu.org/licenses/>.
|
17
17
|
#
|
18
18
|
|
19
|
+
require 'ronin/support/binary/core_ext/integer'
|
20
|
+
require 'ronin/support/binary/core_ext/float'
|
19
21
|
require 'ronin/support/binary/core_ext/string'
|
20
22
|
require 'ronin/support/binary/core_ext/array'
|
21
23
|
require 'ronin/support/binary/core_ext/io'
|
@@ -24,6 +24,49 @@ module Ronin
|
|
24
24
|
#
|
25
25
|
# Represents a null terminated C string.
|
26
26
|
#
|
27
|
+
# ## Examples
|
28
|
+
#
|
29
|
+
# ### Initializing C Strings
|
30
|
+
#
|
31
|
+
# From a String:
|
32
|
+
#
|
33
|
+
# str = Binary::CString.new("hello ")
|
34
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94ba577f8 @string="hello \u0000">
|
35
|
+
#
|
36
|
+
# From a binary C string:
|
37
|
+
#
|
38
|
+
# str = Binary::CString.new("world\0".b)
|
39
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94ba06f88 @string="world\u0000">
|
40
|
+
#
|
41
|
+
# From characters:
|
42
|
+
#
|
43
|
+
# str = Binary::CString['A', 'B', 'C']
|
44
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94ba6f268 @string="ABC\x00">
|
45
|
+
#
|
46
|
+
# ### Modifying C Strings
|
47
|
+
#
|
48
|
+
# Concating Strings to a C String:
|
49
|
+
#
|
50
|
+
# str = Binary::CString.new("hello ")
|
51
|
+
# str.concat("world")
|
52
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94b978df0 @string="hello world\u0000">
|
53
|
+
# str.to_s
|
54
|
+
# # => "hello world"
|
55
|
+
#
|
56
|
+
# Appending two C Strings:
|
57
|
+
#
|
58
|
+
# str1 = Binary::CString.new("hello ")
|
59
|
+
# str2 = Binary::CString.new("world\0")
|
60
|
+
# str = str1 + str2
|
61
|
+
# # => #<Ronin::Support::Binary::CString:0x00007fc94b9523f8 @string="hello world\u0000">
|
62
|
+
#
|
63
|
+
# Setting characters:
|
64
|
+
#
|
65
|
+
# str = Binary::CString.new("hello")
|
66
|
+
# str[0] = 'X'
|
67
|
+
# str.to_s
|
68
|
+
# # => "Xello"
|
69
|
+
#
|
27
70
|
# @api public
|
28
71
|
#
|
29
72
|
# @since 1.0.0
|
@@ -101,14 +144,15 @@ module Ronin
|
|
101
144
|
# @return [self]
|
102
145
|
#
|
103
146
|
def concat(value)
|
104
|
-
value
|
105
|
-
|
106
|
-
|
107
|
-
|
147
|
+
value = case value
|
148
|
+
when Integer then value.chr
|
149
|
+
else value.to_s
|
150
|
+
end
|
108
151
|
value_size = value.bytesize
|
109
152
|
|
110
153
|
unless value.include?(NULL)
|
111
154
|
value = "#{value}#{NULL}"
|
155
|
+
|
112
156
|
value_size += 1
|
113
157
|
end
|
114
158
|
|
@@ -153,6 +197,7 @@ module Ronin
|
|
153
197
|
|
154
198
|
@string.each_char do |char|
|
155
199
|
break if char == NULL
|
200
|
+
|
156
201
|
yield char
|
157
202
|
end
|
158
203
|
end
|
@@ -185,6 +230,7 @@ module Ronin
|
|
185
230
|
|
186
231
|
@string.each_byte do |byte|
|
187
232
|
break if byte == 0x00
|
233
|
+
|
188
234
|
yield byte
|
189
235
|
end
|
190
236
|
end
|
@@ -60,7 +60,7 @@ module Ronin
|
|
60
60
|
# Custom type alignment to override the type's alignment.
|
61
61
|
#
|
62
62
|
def initialize(type,length, alignment: nil)
|
63
|
-
if type.
|
63
|
+
if type.kind_of?(UnboundedArrayType)
|
64
64
|
raise(ArgumentError,"cannot initialize an #{self.class} of #{UnboundedArrayType}")
|
65
65
|
end
|
66
66
|
|
@@ -152,7 +152,7 @@ module Ronin
|
|
152
152
|
if @pack_string
|
153
153
|
super(array)
|
154
154
|
else
|
155
|
-
buffer = String.new
|
155
|
+
buffer = String.new
|
156
156
|
|
157
157
|
@length.times do |index|
|
158
158
|
value = array[index] || @type.uninitialized_value
|
@@ -82,7 +82,7 @@ module Ronin
|
|
82
82
|
@signed = signed
|
83
83
|
end
|
84
84
|
|
85
|
-
#
|
85
|
+
#
|
86
86
|
# Whether the scalar type is signed.
|
87
87
|
#
|
88
88
|
# @return [Boolean]
|
@@ -91,7 +91,7 @@ module Ronin
|
|
91
91
|
@signed
|
92
92
|
end
|
93
93
|
|
94
|
-
#
|
94
|
+
#
|
95
95
|
# Whether the scalar type is unsigned.
|
96
96
|
#
|
97
97
|
# @return [Boolean]
|
@@ -214,9 +214,9 @@ module Ronin
|
|
214
214
|
# The uninitialized values for the new struct's members.
|
215
215
|
#
|
216
216
|
def uninitialized_value
|
217
|
-
|
218
|
-
|
219
|
-
|
217
|
+
@members.transform_values do |member|
|
218
|
+
member.type.uninitialized_value
|
219
|
+
end
|
220
220
|
end
|
221
221
|
|
222
222
|
#
|
@@ -155,9 +155,9 @@ module Ronin
|
|
155
155
|
#
|
156
156
|
def resolve_struct(type_signature)
|
157
157
|
struct_class = type_signature
|
158
|
-
struct_members =
|
159
|
-
|
160
|
-
}
|
158
|
+
struct_members = struct_class.members.transform_values { |member|
|
159
|
+
resolve(member.type_signature)
|
160
|
+
}
|
161
161
|
|
162
162
|
struct_type = StructType.build(
|
163
163
|
struct_members, alignment: struct_class.alignment,
|
@@ -176,9 +176,9 @@ module Ronin
|
|
176
176
|
#
|
177
177
|
def resolve_union(type_signature)
|
178
178
|
union_class = type_signature
|
179
|
-
union_members =
|
180
|
-
|
181
|
-
}
|
179
|
+
union_members = union_class.members.transform_values { |member|
|
180
|
+
resolve(member.type_signature)
|
181
|
+
}
|
182
182
|
|
183
183
|
union_type = UnionType.build(
|
184
184
|
union_members, alignment: union_class.alignment
|
@@ -191,7 +191,7 @@ module Ronin
|
|
191
191
|
# Resolves a type name.
|
192
192
|
#
|
193
193
|
# @param [Symbol] name
|
194
|
-
#
|
194
|
+
#
|
195
195
|
# @return [Type]
|
196
196
|
#
|
197
197
|
def resolve_symbol(name)
|
@@ -203,4 +203,3 @@ module Ronin
|
|
203
203
|
end
|
204
204
|
end
|
205
205
|
end
|
206
|
-
|
@@ -47,7 +47,7 @@ module Ronin
|
|
47
47
|
# Cannot initialize a nested {UnboundedArrayType}.
|
48
48
|
#
|
49
49
|
def initialize(type, alignment: nil)
|
50
|
-
if type.
|
50
|
+
if type.kind_of?(UnboundedArrayType)
|
51
51
|
raise(ArgumentError,"cannot initialize a nested #{UnboundedArrayType}")
|
52
52
|
end
|
53
53
|
|
@@ -149,7 +149,7 @@ module Ronin
|
|
149
149
|
if @pack_string
|
150
150
|
super(array)
|
151
151
|
else
|
152
|
-
buffer = String.new
|
152
|
+
buffer = String.new
|
153
153
|
|
154
154
|
array.each do |element|
|
155
155
|
buffer << @type.pack(element)
|
@@ -162,9 +162,9 @@ module Ronin
|
|
162
162
|
# The uninitialized values for the new union's members.
|
163
163
|
#
|
164
164
|
def uninitialized_value
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
@members.transform_values do |member|
|
166
|
+
member.type.uninitialized_value
|
167
|
+
end
|
168
168
|
end
|
169
169
|
|
170
170
|
#
|
@@ -61,7 +61,7 @@ module Ronin
|
|
61
61
|
# * Floating Point Types:
|
62
62
|
# * {CTypes::Float32Type float} (`-3.40282347E+38F` -
|
63
63
|
# `3.40282347E+38F`)
|
64
|
-
# * {CTypes::Float64Type double} (`-1.79769313486231570E+308` -
|
64
|
+
# * {CTypes::Float64Type double} (`-1.79769313486231570E+308` -
|
65
65
|
# `1.79769313486231570E+308`)
|
66
66
|
# * Aggregate Types:
|
67
67
|
# * {CTypes::ArrayType Array} (ex: `{1,2,3}`)
|
@@ -182,7 +182,7 @@ module Ronin
|
|
182
182
|
UINT32_NET = Network::UINT32
|
183
183
|
UINT64_NET = Network::UINT64
|
184
184
|
|
185
|
-
WORD_NET
|
185
|
+
WORD_NET = Network::WORD
|
186
186
|
DWORD_NET = Network::DWORD
|
187
187
|
QWORD_NET = Network::QWORD
|
188
188
|
|
@@ -390,7 +390,7 @@ module Ronin
|
|
390
390
|
openbsd: OS::OpenBSD,
|
391
391
|
netbsd: OS::NetBSD,
|
392
392
|
|
393
|
-
linux: OS::
|
393
|
+
linux: OS::Linux,
|
394
394
|
macos: OS::MacOS,
|
395
395
|
windows: OS::Windows
|
396
396
|
}
|
@@ -145,7 +145,7 @@ module Ronin
|
|
145
145
|
|
146
146
|
case length
|
147
147
|
when Integer then @string[index,length] = value
|
148
|
-
when nil then @string[index]
|
148
|
+
when nil then @string[index] = value
|
149
149
|
when Float::INFINITY
|
150
150
|
@string[index,@string.length - index] = value
|
151
151
|
else
|
@@ -157,7 +157,7 @@ module Ronin
|
|
157
157
|
end
|
158
158
|
|
159
159
|
#
|
160
|
-
# Returns a byte slice of the memory at the given offset and for the
|
160
|
+
# Returns a byte slice of the memory at the given offset and for the
|
161
161
|
# remainder of the memory.
|
162
162
|
#
|
163
163
|
# @param [Integer] offset
|
@@ -21,6 +21,86 @@ require 'ronin/support/binary/struct'
|
|
21
21
|
module Ronin
|
22
22
|
module Support
|
23
23
|
module Binary
|
24
|
+
#
|
25
|
+
# Represents a network packet in network byte-order.
|
26
|
+
#
|
27
|
+
# ## Examples
|
28
|
+
#
|
29
|
+
# ### Defining Packet Fields
|
30
|
+
#
|
31
|
+
# class Packet < Ronin::Support::Binary::Packet
|
32
|
+
#
|
33
|
+
# member :flags, :uint8
|
34
|
+
# member :src, :uint32
|
35
|
+
# member :dst, :uint32
|
36
|
+
# member :length, :uint32
|
37
|
+
#
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# ### Initializing Packets
|
41
|
+
#
|
42
|
+
# From a Hash:
|
43
|
+
#
|
44
|
+
# packet = Packet.new(
|
45
|
+
# flags: 0x0c,
|
46
|
+
# src: IPAddr.new('1.2.3.4').to_i,
|
47
|
+
# dst: IPAddr.new('5.6.7.8').to_i,
|
48
|
+
# length: 1024
|
49
|
+
# )
|
50
|
+
#
|
51
|
+
# From a buffer:
|
52
|
+
#
|
53
|
+
# packet = Packet.unpack("\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00")
|
54
|
+
#
|
55
|
+
# ### Reading Fields
|
56
|
+
#
|
57
|
+
# packet = Packet.new("\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00")
|
58
|
+
# packet[:flags]
|
59
|
+
# # => 12
|
60
|
+
# packet.flags
|
61
|
+
# # => 12
|
62
|
+
#
|
63
|
+
# ### Packing Packets
|
64
|
+
#
|
65
|
+
# class Packet < Ronin::Support::Binary::Packet
|
66
|
+
#
|
67
|
+
# member :flags, :uint8
|
68
|
+
# member :src, :uint32
|
69
|
+
# member :dst, :uint32
|
70
|
+
# member :length, :uint32
|
71
|
+
#
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# packet = Packet.new(
|
75
|
+
# flags: 0x0c,
|
76
|
+
# src: IPAddr.new('1.2.3.4').to_i,
|
77
|
+
# dst: IPAddr.new('5.6.7.8').to_i,
|
78
|
+
# length: 1024
|
79
|
+
# )
|
80
|
+
# packet.pack
|
81
|
+
# # => "\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00"
|
82
|
+
#
|
83
|
+
# ### Unpacking Packets
|
84
|
+
#
|
85
|
+
# class Packet < Ronin::Support::Binary::Packet
|
86
|
+
#
|
87
|
+
# member :flags, :uint8
|
88
|
+
# member :src, :uint32
|
89
|
+
# member :dst, :uint32
|
90
|
+
# member :length, :uint32
|
91
|
+
#
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# packet = Packet.unpack("\f\x01\x02\x03\x04\x05\x06\a\b\x00\x00\x04\x00")
|
95
|
+
# packet.flags
|
96
|
+
# # => 12
|
97
|
+
# packet.src
|
98
|
+
# # => 16909060
|
99
|
+
# packet.dst
|
100
|
+
# # => 84281096
|
101
|
+
# packet.length
|
102
|
+
# # => 1024
|
103
|
+
#
|
24
104
|
class Packet < Binary::Struct
|
25
105
|
|
26
106
|
platform endian: :net
|