ronin-support 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +14 -0
  3. data/.rubocop.yml +109 -0
  4. data/ChangeLog.md +33 -1
  5. data/Gemfile +8 -4
  6. data/README.md +1 -1
  7. data/Rakefile +2 -2
  8. data/examples/ssl_proxy.rb +2 -1
  9. data/examples/tcp_proxy.rb +6 -4
  10. data/lib/ronin/support/archive/core_ext/file.rb +43 -0
  11. data/lib/ronin/support/archive/core_ext.rb +1 -1
  12. data/lib/ronin/support/archive/tar/writer.rb +2 -2
  13. data/lib/ronin/support/archive/tar.rb +4 -4
  14. data/lib/ronin/support/archive/zip/reader.rb +2 -2
  15. data/lib/ronin/support/binary/array.rb +5 -8
  16. data/lib/ronin/support/binary/bit_flip.rb +7 -1
  17. data/lib/ronin/support/binary/buffer.rb +25 -25
  18. data/lib/ronin/support/binary/byte_slice.rb +17 -17
  19. data/lib/ronin/support/binary/core_ext.rb +2 -0
  20. data/lib/ronin/support/binary/cstring.rb +50 -4
  21. data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +4 -0
  22. data/lib/ronin/support/binary/ctypes/arch/arm.rb +3 -0
  23. data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +4 -0
  24. data/lib/ronin/support/binary/ctypes/arch/arm64.rb +3 -0
  25. data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +4 -0
  26. data/lib/ronin/support/binary/ctypes/arch/mips.rb +3 -0
  27. data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +4 -0
  28. data/lib/ronin/support/binary/ctypes/arch/mips64.rb +3 -0
  29. data/lib/ronin/support/binary/ctypes/arch/ppc.rb +3 -0
  30. data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +3 -0
  31. data/lib/ronin/support/binary/ctypes/arch/x86.rb +3 -0
  32. data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +3 -0
  33. data/lib/ronin/support/binary/ctypes/array_type.rb +2 -2
  34. data/lib/ronin/support/binary/ctypes/big_endian.rb +3 -0
  35. data/lib/ronin/support/binary/ctypes/enum_type.rb +2 -2
  36. data/lib/ronin/support/binary/ctypes/little_endian.rb +3 -0
  37. data/lib/ronin/support/binary/ctypes/native.rb +3 -0
  38. data/lib/ronin/support/binary/ctypes/os/bsd.rb +1 -1
  39. data/lib/ronin/support/binary/ctypes/scalar_type.rb +2 -2
  40. data/lib/ronin/support/binary/ctypes/struct_type.rb +3 -3
  41. data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -8
  42. data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +2 -2
  43. data/lib/ronin/support/binary/ctypes/union_type.rb +3 -3
  44. data/lib/ronin/support/binary/ctypes.rb +3 -3
  45. data/lib/ronin/support/binary/memory.rb +2 -2
  46. data/lib/ronin/support/binary/packet.rb +80 -0
  47. data/lib/ronin/support/binary/stack.rb +6 -7
  48. data/lib/ronin/support/binary/struct/member.rb +5 -3
  49. data/lib/ronin/support/binary/struct.rb +81 -79
  50. data/lib/ronin/support/binary/template.rb +2 -5
  51. data/lib/ronin/support/binary/unhexdump/parser.rb +11 -11
  52. data/lib/ronin/support/binary/union.rb +22 -22
  53. data/lib/ronin/support/binary.rb +1 -0
  54. data/lib/ronin/support/cli/ansi.rb +0 -1
  55. data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
  56. data/lib/ronin/support/cli/io_shell.rb +4 -4
  57. data/lib/ronin/support/cli/printing.rb +3 -3
  58. data/lib/ronin/support/compression/core_ext/file.rb +16 -0
  59. data/lib/ronin/support/compression/zlib.rb +1 -1
  60. data/lib/ronin/support/core_ext/enumerable.rb +0 -2
  61. data/lib/ronin/support/core_ext/file.rb +1 -1
  62. data/lib/ronin/support/core_ext/kernel.rb +6 -9
  63. data/lib/ronin/support/core_ext/string.rb +2 -2
  64. data/lib/ronin/support/crypto/cert.rb +11 -15
  65. data/lib/ronin/support/crypto/cert_chain.rb +1 -1
  66. data/lib/ronin/support/crypto/cipher/aes.rb +3 -0
  67. data/lib/ronin/support/crypto/cipher/aes128.rb +4 -1
  68. data/lib/ronin/support/crypto/cipher/aes256.rb +4 -1
  69. data/lib/ronin/support/crypto/cipher.rb +1 -1
  70. data/lib/ronin/support/crypto/core_ext/file.rb +33 -1
  71. data/lib/ronin/support/crypto/core_ext/string.rb +34 -2
  72. data/lib/ronin/support/crypto/key/methods.rb +4 -1
  73. data/lib/ronin/support/crypto/key.rb +5 -2
  74. data/lib/ronin/support/crypto/openssl.rb +1 -1
  75. data/lib/ronin/support/crypto.rb +0 -1
  76. data/lib/ronin/support/encoding/base16.rb +2 -2
  77. data/lib/ronin/support/encoding/base32.rb +29 -18
  78. data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
  79. data/lib/ronin/support/encoding/c/core_ext/string.rb +1 -1
  80. data/lib/ronin/support/encoding/c.rb +6 -6
  81. data/lib/ronin/support/encoding/core_ext/string.rb +2 -2
  82. data/lib/ronin/support/encoding/hex/core_ext/string.rb +1 -1
  83. data/lib/ronin/support/encoding/hex.rb +4 -4
  84. data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
  85. data/lib/ronin/support/encoding/js.rb +5 -5
  86. data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +2 -2
  87. data/lib/ronin/support/encoding/powershell.rb +5 -6
  88. data/lib/ronin/support/encoding/quoted_printable.rb +3 -1
  89. data/lib/ronin/support/encoding/ruby.rb +5 -5
  90. data/lib/ronin/support/encoding/shell/core_ext/integer.rb +2 -2
  91. data/lib/ronin/support/encoding/shell.rb +3 -3
  92. data/lib/ronin/support/encoding/sql.rb +1 -1
  93. data/lib/ronin/support/encoding/uuencoding.rb +3 -1
  94. data/lib/ronin/support/encoding/xml.rb +3 -3
  95. data/lib/ronin/support/encoding.rb +95 -0
  96. data/lib/ronin/support/network/asn/list.rb +6 -1
  97. data/lib/ronin/support/network/asn/record.rb +3 -0
  98. data/lib/ronin/support/network/asn/record_set.rb +3 -0
  99. data/lib/ronin/support/network/asn.rb +167 -6
  100. data/lib/ronin/support/network/dns/mixin.rb +2 -10
  101. data/lib/ronin/support/network/dns/resolver.rb +3 -0
  102. data/lib/ronin/support/network/domain.rb +21 -21
  103. data/lib/ronin/support/network/email_address.rb +1 -5
  104. data/lib/ronin/support/network/esmtp/mixin.rb +1 -0
  105. data/lib/ronin/support/network/ftp/mixin.rb +1 -1
  106. data/lib/ronin/support/network/host.rb +75 -47
  107. data/lib/ronin/support/network/http/core_ext/uri/http.rb +8 -0
  108. data/lib/ronin/support/network/http/core_ext.rb +1 -1
  109. data/lib/ronin/support/network/http.rb +317 -80
  110. data/lib/ronin/support/network/ip.rb +49 -23
  111. data/lib/ronin/support/network/ip_range/cidr.rb +1 -5
  112. data/lib/ronin/support/network/ip_range/glob.rb +1 -0
  113. data/lib/ronin/support/network/ip_range/range.rb +1 -1
  114. data/lib/ronin/support/network/ip_range.rb +5 -7
  115. data/lib/ronin/support/network/proxy.rb +4 -4
  116. data/lib/ronin/support/network/public_suffix/list.rb +10 -8
  117. data/lib/ronin/support/network/public_suffix/suffix_set.rb +3 -0
  118. data/lib/ronin/support/network/public_suffix.rb +9 -4
  119. data/lib/ronin/support/network/smtp/email.rb +0 -9
  120. data/lib/ronin/support/network/smtp/mixin.rb +2 -2
  121. data/lib/ronin/support/network/ssl/local_cert.rb +1 -3
  122. data/lib/ronin/support/network/ssl/mixin.rb +13 -13
  123. data/lib/ronin/support/network/ssl/openssl.rb +1 -1
  124. data/lib/ronin/support/network/ssl/proxy.rb +14 -16
  125. data/lib/ronin/support/network/ssl.rb +4 -2
  126. data/lib/ronin/support/network/tcp/proxy.rb +3 -3
  127. data/lib/ronin/support/network/tcp.rb +10 -12
  128. data/lib/ronin/support/network/telnet/mixin.rb +14 -14
  129. data/lib/ronin/support/network/tld/list.rb +2 -1
  130. data/lib/ronin/support/network/tld.rb +7 -4
  131. data/lib/ronin/support/network/tls/proxy.rb +1 -1
  132. data/lib/ronin/support/network/tls.rb +0 -2
  133. data/lib/ronin/support/network/udp/proxy.rb +5 -5
  134. data/lib/ronin/support/network/udp.rb +14 -16
  135. data/lib/ronin/support/path.rb +4 -4
  136. data/lib/ronin/support/text/erb/mixin.rb +3 -0
  137. data/lib/ronin/support/text/homoglyph/core_ext/string.rb +33 -0
  138. data/lib/ronin/support/text/homoglyph/table.rb +3 -3
  139. data/lib/ronin/support/text/patterns/credentials.rb +2 -2
  140. data/lib/ronin/support/text/patterns/crypto.rb +1 -1
  141. data/lib/ronin/support/text/patterns/file_system.rb +3 -4
  142. data/lib/ronin/support/text/patterns/network.rb +21 -21
  143. data/lib/ronin/support/text/patterns/numeric.rb +1 -1
  144. data/lib/ronin/support/text/patterns/source_code.rb +2 -2
  145. data/lib/ronin/support/text/random/mixin.rb +17 -17
  146. data/lib/ronin/support/text/random.rb +25 -25
  147. data/lib/ronin/support/text/typo/core_ext/string.rb +24 -0
  148. data/lib/ronin/support/text/typo/generator.rb +2 -2
  149. data/lib/ronin/support/version.rb +1 -1
  150. data/ronin-support.gemspec +6 -5
  151. metadata +3 -2
@@ -36,7 +36,7 @@ module Ronin
36
36
  #
37
37
  # Creating a new stack:
38
38
  #
39
- # stack = Stack.new
39
+ # stack = Binary::Stack.new
40
40
  # # => #<Ronin::Support::Binary::Stack: "">
41
41
  # stack.push 0x41414141
42
42
  # # => #<Ronin::Support::Binary::Stack: "AAAA\x00\x00\x00\x00">
@@ -49,7 +49,7 @@ module Ronin
49
49
  #
50
50
  # Creating a stack from an existing String:
51
51
  #
52
- # stack = Stack.new("\x41\x00\x00\x00\x00\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00")
52
+ # stack = Binary::Stack.new("\x41\x00\x00\x00\x00\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00")
53
53
  # stack[0]
54
54
  # # => 65
55
55
  # stack[8]
@@ -125,7 +125,7 @@ module Ronin
125
125
  @size = @string.bytesize
126
126
  @length = @size / @machine_word.size
127
127
  else
128
- @string = String.new("", encoding: Encoding::ASCII_8BIT)
128
+ @string = String.new
129
129
  @size = 0
130
130
  @length = 0
131
131
  end
@@ -152,7 +152,7 @@ module Ronin
152
152
  else index
153
153
  end
154
154
 
155
- if offset+@machine_word.size > @size
155
+ if (offset + @machine_word.size) > @size
156
156
  raise(IndexError,"index #{index} is out of bounds: 0...#{@size}")
157
157
  end
158
158
 
@@ -184,12 +184,11 @@ module Ronin
184
184
  else index
185
185
  end
186
186
 
187
- if offset+@machine_word.size > @size
187
+ if (offset + @machine_word.size) > @size
188
188
  raise(IndexError,"index #{index} is out of bounds: 0...#{@size}")
189
189
  end
190
190
 
191
- data = @machine_word.pack(value)
192
- @string[offset,@machine_word.size] = data
191
+ @string[offset,@machine_word.size] = @machine_word.pack(value)
193
192
  return value
194
193
  end
195
194
 
@@ -22,6 +22,9 @@ module Ronin
22
22
  module Support
23
23
  module Binary
24
24
  class Struct < Memory
25
+ #
26
+ # Represents a member defined within a {Struct}.
27
+ #
25
28
  class Member
26
29
 
27
30
  # The name of the structure member.
@@ -51,10 +54,9 @@ module Ronin
51
54
  # The optional default value for the structure's field.
52
55
  #
53
56
  def initialize(name,type_signature, default: nil)
54
- @name = name
57
+ @name = name
55
58
  @type_signature = type_signature
56
-
57
- @default = default
59
+ @default = default
58
60
  end
59
61
 
60
62
  #
@@ -37,10 +37,10 @@ module Ronin
37
37
  # ### Defining Members
38
38
  #
39
39
  # class Point < Ronin::Support::Binary::Struct
40
- #
40
+ #
41
41
  # member :x, :int32
42
42
  # member :y, :int32
43
- #
43
+ #
44
44
  # end
45
45
  #
46
46
  # ### Initializing Structs
@@ -69,10 +69,10 @@ module Ronin
69
69
  # ### Packing Structs
70
70
  #
71
71
  # class Point < Ronin::Support::Binary::Struct
72
- #
72
+ #
73
73
  # member :x, :int32
74
74
  # member :y, :int32
75
- #
75
+ #
76
76
  # end
77
77
  #
78
78
  # point = Point.new(x: 10, y: -1)
@@ -82,12 +82,12 @@ module Ronin
82
82
  # ### Unpacking Structs
83
83
  #
84
84
  # class Point < Ronin::Support::Binary::Struct
85
- #
85
+ #
86
86
  # member :x, :int32
87
87
  # member :y, :int32
88
- #
88
+ #
89
89
  # end
90
- #
90
+ #
91
91
  # point = Point.unpack("\x00\x00\x00\x01\xFF\xFF\xFF\xFF")
92
92
  # point.x
93
93
  # # => 1
@@ -95,30 +95,30 @@ module Ronin
95
95
  # # => -1
96
96
  #
97
97
  # ### Inheriting Structs
98
- #
98
+ #
99
99
  # class Point < Ronin::Support::Binary::Struct
100
- #
100
+ #
101
101
  # member :x, :int32
102
102
  # member :y, :int32
103
- #
103
+ #
104
104
  # end
105
- #
105
+ #
106
106
  # class Point3D < Point
107
- #
107
+ #
108
108
  # member :z, :int32
109
109
  #
110
110
  # end
111
- #
111
+ #
112
112
  # point = Point.new(x: 100, y: 42)
113
113
  # point3d = Point3D.new(x: 100, y: 42, z: -1)
114
114
  #
115
115
  # ### Array Fields
116
116
  #
117
117
  # class MyStruct < Ronin::Support::Binary::Struct
118
- #
118
+ #
119
119
  # member :x, :uint32
120
120
  # member :nums, [:uint8, 10]
121
- #
121
+ #
122
122
  # end
123
123
  #
124
124
  # struct = MyStruct.new
@@ -129,12 +129,12 @@ module Ronin
129
129
  # ### Unbounded Array Fields
130
130
  #
131
131
  # class MyStruct < Ronin::Support::Binary::Struct
132
- #
132
+ #
133
133
  # member :length, :uint32
134
134
  # member :payload, (:uint8..)
135
- #
135
+ #
136
136
  # end
137
- #
137
+ #
138
138
  # struct = MyStruct.new
139
139
  # struct.payload = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]
140
140
  # struct.pack
@@ -143,14 +143,14 @@ module Ronin
143
143
  # ### Struct Endianness
144
144
  #
145
145
  # class MyStruct < Ronin::Support::Binary::Struct
146
- #
146
+ #
147
147
  # platform endian: :big
148
- #
148
+ #
149
149
  # member :x, :uint32
150
150
  # member :y, :uint32
151
- #
151
+ #
152
152
  # end
153
- #
153
+ #
154
154
  # struct = MyStruct.new
155
155
  # struct.x = 0xAABB
156
156
  # struct.y = 0xCCDD
@@ -160,13 +160,13 @@ module Ronin
160
160
  # ### Struct Architecture
161
161
  #
162
162
  # class MyStruct < Ronin::Support::Binary::Struct
163
- #
163
+ #
164
164
  # platform arch: :arm64_be
165
- #
165
+ #
166
166
  # member :x, :int
167
167
  # member :y, :int
168
168
  # member :f, :double
169
- #
169
+ #
170
170
  # end
171
171
  #
172
172
  # struct = MyStruct.new
@@ -177,16 +177,16 @@ module Ronin
177
177
  # # => "\x00\x00\x00d\xFF\xFF\xFF\x9C@<\xA5\xDC\x1Ac\xC1\xF8"
178
178
  #
179
179
  # ### Struct Operating System (OS)
180
- #
180
+ #
181
181
  # class MyStruct < Ronin::Support::Binary::Struct
182
- #
182
+ #
183
183
  # platform arch: :x86_64, os: :windows
184
- #
184
+ #
185
185
  # member :x, :long
186
186
  # member :y, :long
187
- #
187
+ #
188
188
  # end
189
- #
189
+ #
190
190
  # struct = MyStruct.new
191
191
  # struct.x = 255
192
192
  # struct.y = -1
@@ -196,20 +196,20 @@ module Ronin
196
196
  # ### Struct Alignment
197
197
  #
198
198
  # class Pixel < Ronin::Support::Binary::Struct
199
- #
199
+ #
200
200
  # align 4
201
- #
201
+ #
202
202
  # member :r, :uint8
203
203
  # member :g, :uint8
204
204
  # member :b, :uint8
205
- #
205
+ #
206
206
  # end
207
207
  #
208
208
  # class PixelBuf < Ronin::Support::Binary::Struct
209
- #
209
+ #
210
210
  # member :count, :uint8
211
211
  # member :pixels, [Pixel, 255]
212
- #
212
+ #
213
213
  # end
214
214
  #
215
215
  # pixelbuf = PixelBuf.new
@@ -226,12 +226,12 @@ module Ronin
226
226
  # ### Disable Struct Padding
227
227
  #
228
228
  # class MyStruct < Ronin::Support::Binary::Struct
229
- #
229
+ #
230
230
  # padding false
231
- #
231
+ #
232
232
  # member :c, :char
233
233
  # member :i, :int32
234
- #
234
+ #
235
235
  # end
236
236
  #
237
237
  # struct = MyStruct.new
@@ -259,13 +259,13 @@ module Ronin
259
259
  #
260
260
  # @example Initiializing a new struct from a buffer:
261
261
  # class MyStruct < Ronin::Support::Binary::Struct
262
- #
262
+ #
263
263
  # member :x, :uint32
264
264
  # member :f, :double
265
265
  # member :nums, [:uint8, 10]
266
- #
266
+ #
267
267
  # end
268
- #
268
+ #
269
269
  # struct = MyStruct.new("\x01\x00\x00\x00\x00\x00\x00\x00333333\xD3?\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00")
270
270
  # struct.x
271
271
  # # => 1
@@ -328,12 +328,12 @@ module Ronin
328
328
  #
329
329
  # @example
330
330
  # class MyStruct < Ronin::Support::Binary::Struct
331
- #
331
+ #
332
332
  # member :x, :uint32
333
333
  # member :y, :uint32
334
- #
334
+ #
335
335
  # end
336
- #
336
+ #
337
337
  # MyStruct.size
338
338
  # # => 8
339
339
  #
@@ -412,13 +412,13 @@ module Ronin
412
412
  #
413
413
  # @example
414
414
  # class MyStruct < Ronin::Support::Binary::Struct
415
- #
415
+ #
416
416
  # member :x, :uint32
417
417
  # member :f, :double
418
418
  # member :nums, [:uint8, 10]
419
- #
419
+ #
420
420
  # end
421
- #
421
+ #
422
422
  # MyStruct.pack(x: 1, f: 0.3, nums: [1,2,3])
423
423
  # # => "\x01\x00\x00\x00\x00\x00\x00\x00333333\xD3?\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00"
424
424
  #
@@ -439,13 +439,13 @@ module Ronin
439
439
  #
440
440
  # @example
441
441
  # class MyStruct < Ronin::Support::Binary::Struct
442
- #
442
+ #
443
443
  # member :x, :uint32
444
444
  # member :f, :double
445
445
  # member :nums, [:uint8, 10]
446
- #
446
+ #
447
447
  # end
448
- #
448
+ #
449
449
  # struct = MyStruct.unpack("\x01\x00\x00\x00\x00\x00\x00\x00333333\xD3?\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00")
450
450
  #
451
451
  # @api public
@@ -465,13 +465,13 @@ module Ronin
465
465
  #
466
466
  # @example
467
467
  # class MyStruct < Ronin::Support::Binary::Struct
468
- #
468
+ #
469
469
  # member :x, :uint32
470
470
  # member :f, :double
471
471
  # member :nums, [:uint8, 10]
472
- #
472
+ #
473
473
  # end
474
- #
474
+ #
475
475
  # file = File.new('binary.dat','b')
476
476
  # struct = MyStruct.read_from(file)
477
477
  #
@@ -480,7 +480,7 @@ module Ronin
480
480
  # @api public
481
481
  #
482
482
  def self.read_from(io)
483
- new().read_from(io)
483
+ new.read_from(io)
484
484
  end
485
485
 
486
486
  #
@@ -497,13 +497,13 @@ module Ronin
497
497
  #
498
498
  # @example
499
499
  # class MyStruct < Ronin::Support::Binary::Struct
500
- #
500
+ #
501
501
  # member :x, :uint32
502
502
  # member :f, :double
503
503
  # member :nums, [:uint8, 10]
504
- #
504
+ #
505
505
  # end
506
- #
506
+ #
507
507
  # struct = MyStruct.new("\x01\x00\x00\x00\x00\x00\x00\x00333333\xD3?\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00")
508
508
  # struct[:x]
509
509
  # # => 1
@@ -519,15 +519,21 @@ module Ronin
519
519
  case member.type
520
520
  when CTypes::UnboundedArrayType
521
521
  # XXX: but how do we handle an unbounded array of structs?
522
- @cache[name] ||= (
523
- slice = byteslice(member.offset,size - member.offset)
524
- Binary::Array.new(member.type.type,slice)
525
- )
522
+ @cache[name] ||= begin
523
+ offset = member.offset
524
+ length = size - member.offset
525
+ slice = byteslice(offset,length)
526
+
527
+ Binary::Array.new(member.type.type,slice)
528
+ end
526
529
  when CTypes::ObjectType
527
- @cache[name] ||= (
528
- slice = byteslice(member.offset,member.type.size)
529
- member.type.unpack(slice)
530
- )
530
+ @cache[name] ||= begin
531
+ offset = member.offset
532
+ length = member.type.size
533
+ slice = byteslice(offset,length)
534
+
535
+ member.type.unpack(slice)
536
+ end
531
537
  else
532
538
  data = super(member.offset,member.type.size)
533
539
  member.type.unpack(data)
@@ -554,13 +560,13 @@ module Ronin
554
560
  #
555
561
  # @example
556
562
  # class MyStruct < Ronin::Support::Binary::Struct
557
- #
563
+ #
558
564
  # member :x, :uint32
559
565
  # member :f, :double
560
566
  # member :nums, [:uint8, 10]
561
- #
567
+ #
562
568
  # end
563
- #
569
+ #
564
570
  # struct = MyStruct.new
565
571
  # struct[:x] = 1
566
572
  # struct[:x]
@@ -606,7 +612,7 @@ module Ronin
606
612
  def each(&block)
607
613
  return enum_for(__method__) unless block_given?
608
614
 
609
- @type.members.each_key do |name|
615
+ @type.members.each_key do |name|
610
616
  yield name, self[name]
611
617
  end
612
618
  end
@@ -620,9 +626,7 @@ module Ronin
620
626
  # @api public
621
627
  #
622
628
  def to_h
623
- Hash[@type.members.keys.map { |name|
624
- [name, self[name]]
625
- }]
629
+ each.to_h
626
630
  end
627
631
 
628
632
  #
@@ -634,9 +638,7 @@ module Ronin
634
638
  # @api public
635
639
  #
636
640
  def to_a
637
- @type.members.keys.map do |name|
638
- self[name]
639
- end
641
+ each.map { |name,value| value }
640
642
  end
641
643
 
642
644
  extend CTypes::Mixin
@@ -755,7 +757,7 @@ module Ronin
755
757
  # @api semipublic
756
758
  #
757
759
  def self.type_resolver
758
- @resolver ||= CTypes::TypeResolver.new(type_system)
760
+ @type_resolver ||= CTypes::TypeResolver.new(type_system)
759
761
  end
760
762
 
761
763
  #
@@ -771,7 +773,7 @@ module Ronin
771
773
  # class MyStruct < Ronin::Support::Binary::Struct
772
774
  # member :x, :uint32
773
775
  # end
774
- #
776
+ #
775
777
  # struct = MyStruct.new
776
778
  # struct.x = 0x11223344
777
779
  #
@@ -779,7 +781,7 @@ module Ronin
779
781
  # class MyStruct < Ronin::Support::Binary::Struct
780
782
  # member :nums, [:uint32, 10]
781
783
  # end
782
- #
784
+ #
783
785
  # struct = MyStruct.new
784
786
  # struct.x = [0x11111111, 0x22222222, 0x33333333, 0x44444444]
785
787
  #
@@ -787,7 +789,7 @@ module Ronin
787
789
  # class MyStruct < Ronin::Support::Binary::Struct
788
790
  # member :payload, :uint8..
789
791
  # end
790
- #
792
+ #
791
793
  # struct = MyStruct.new
792
794
  # struct.payloads = [0x1, 0x2, 0x3, 0x4]
793
795
  #
@@ -36,10 +36,6 @@ module Ronin
36
36
  # * `:int16` - signed 16-bit integer.
37
37
  # * `:int32` - signed 32-bit integer.
38
38
  # * `:int64` - signed 64-bit integer.
39
- # * `:uint16_le` - unsigned 16-bit integer, little endian.
40
- # * `:uint32_le` - unsigned 32-bit integer, little endian.
41
- # * `:uint16_be` - unsigned 16-bit integer, big endian.
42
- # * `:uint32_be` - unsigned 32-bit integer, big endian.
43
39
  # * `:uchar` - unsigned character.
44
40
  # * `:ushort` - unsigned short integer, native endian.
45
41
  # * `:uint` - unsigned integer, native endian.
@@ -151,6 +147,7 @@ module Ronin
151
147
 
152
148
  @fields = []
153
149
  @types = []
150
+
154
151
  @pack_string = String.new
155
152
 
156
153
  fields.each do |field|
@@ -208,7 +205,7 @@ module Ronin
208
205
 
209
206
  values.pack(@pack_string)
210
207
  else
211
- buffer = String.new('', encoding: Encoding::ASCII_8BIT)
208
+ buffer = String.new
212
209
 
213
210
  @types.each do |type|
214
211
  # shift off the next value and pack it
@@ -46,9 +46,7 @@ module Ronin
46
46
  )
47
47
 
48
48
  # Visible characters
49
- VISIBLE_CHARS = Hash[
50
- Chars::VISIBLE.chars.sort.zip(Chars::VISIBLE.bytes.sort)
51
- ]
49
+ VISIBLE_CHARS = Chars::VISIBLE.chars.sort.zip(Chars::VISIBLE.bytes.sort).to_h
52
50
 
53
51
  # Escaped characters
54
52
  CHARS = {
@@ -261,7 +259,7 @@ module Ronin
261
259
  case @type
262
260
  when CTypes::CharType
263
261
  @base = 8
264
- @chars = CHARS
262
+ @chars = CHARS
265
263
  end
266
264
  end
267
265
 
@@ -310,6 +308,8 @@ module Ronin
310
308
  starts_repeating_at = previous_address + previous_row_size
311
309
  else
312
310
  address, row = parse_line(line)
311
+
312
+ # remember the first address
313
313
  first_address ||= address
314
314
 
315
315
  if previous_row_repeats
@@ -317,8 +317,8 @@ module Ronin
317
317
  range = starts_repeating_at...address
318
318
  addresses = range.step(previous_row_size)
319
319
 
320
- addresses.each do |address|
321
- yield address, previous_row
320
+ addresses.each do |next_address|
321
+ yield next_address, previous_row
322
322
  end
323
323
 
324
324
  previous_row_repeats = false
@@ -368,7 +368,6 @@ module Ronin
368
368
  buffer = String.new(encoding: Encoding::ASCII_8BIT)
369
369
 
370
370
  length = parse(hexdump) do |address,row|
371
- first_address ||= address
372
371
  buffer << pack(row)
373
372
  end
374
373
 
@@ -385,7 +384,7 @@ module Ronin
385
384
  # The parsed address.
386
385
  #
387
386
  # @api private
388
- #
387
+ #
389
388
  def parse_address(address)
390
389
  address.to_i(@address_base)
391
390
  end
@@ -400,7 +399,7 @@ module Ronin
400
399
  # The parsed Integer.
401
400
  #
402
401
  # @api private
403
- #
402
+ #
404
403
  def parse_int(string)
405
404
  string.to_i(@base)
406
405
  end
@@ -415,7 +414,7 @@ module Ronin
415
414
  # The parsed integer or byte value of the character.
416
415
  #
417
416
  def parse_char_or_int(string)
418
- @chars.fetch(string) do |string|
417
+ @chars.fetch(string) do
419
418
  string.to_i(@base)
420
419
  end
421
420
  end
@@ -459,6 +458,7 @@ module Ronin
459
458
  end
460
459
  else
461
460
  address, *numbers = line.split
461
+
462
462
  address = parse_address(address)
463
463
  numbers.map!(&@parse_method)
464
464
 
@@ -480,7 +480,7 @@ module Ronin
480
480
  # The packed segment.
481
481
  #
482
482
  # @api private
483
- #
483
+ #
484
484
  def pack(values)
485
485
  values.pack(@type.pack_string * values.length)
486
486
  end