ronin-support 0.5.2 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (505) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -6
  3. data/.gitignore +7 -6
  4. data/.mailmap +1 -0
  5. data/.ruby-version +1 -1
  6. data/.yardopts +0 -1
  7. data/ChangeLog.md +516 -148
  8. data/Gemfile +17 -16
  9. data/README.md +105 -50
  10. data/Rakefile +28 -8
  11. data/data/text/homoglyphs/ascii.txt +8 -0
  12. data/data/text/homoglyphs/cyrillic.txt +33 -0
  13. data/data/text/homoglyphs/full_width.txt +81 -0
  14. data/data/text/homoglyphs/greek.txt +21 -0
  15. data/data/text/homoglyphs/latin_numbers.txt +14 -0
  16. data/data/text/homoglyphs/punctuation.txt +7 -0
  17. data/data/text/patterns/network/public_suffix.rb.erb +44 -0
  18. data/examples/ssl_proxy.rb +38 -0
  19. data/examples/tcp_proxy.rb +41 -0
  20. data/gemspec.yml +14 -13
  21. data/lib/ronin/support/archive/core_ext/file.rb +118 -0
  22. data/lib/ronin/{formatting/sql.rb → support/archive/core_ext.rb} +3 -4
  23. data/lib/ronin/support/archive/mixin.rb +213 -0
  24. data/lib/ronin/support/archive/tar/reader.rb +135 -0
  25. data/lib/ronin/support/archive/tar/writer.rb +197 -0
  26. data/lib/ronin/support/archive/tar.rb +155 -0
  27. data/lib/ronin/support/archive/zip/reader/entry.rb +134 -0
  28. data/lib/ronin/support/archive/zip/reader/statistics.rb +76 -0
  29. data/lib/ronin/support/archive/zip/reader.rb +273 -0
  30. data/lib/ronin/support/archive/zip/writer.rb +175 -0
  31. data/lib/ronin/support/archive/zip.rb +105 -0
  32. data/lib/ronin/support/archive.rb +211 -0
  33. data/lib/ronin/support/binary/array.rb +255 -0
  34. data/lib/ronin/support/binary/bit_flip.rb +147 -0
  35. data/lib/ronin/support/binary/buffer.rb +2027 -0
  36. data/lib/ronin/support/binary/byte_slice.rb +324 -0
  37. data/lib/ronin/{formatting/extensions/binary → support/binary/core_ext}/array.rb +25 -11
  38. data/lib/ronin/support/binary/core_ext/float.rb +80 -0
  39. data/lib/ronin/support/binary/core_ext/integer.rb +305 -0
  40. data/lib/ronin/support/binary/core_ext/io.rb +38 -0
  41. data/lib/ronin/support/binary/core_ext/string.rb +115 -0
  42. data/lib/ronin/{formatting/extensions/text.rb → support/binary/core_ext.rb} +6 -6
  43. data/lib/ronin/support/binary/cstring.rb +259 -0
  44. data/lib/ronin/support/binary/ctypes/aggregate_type.rb +98 -0
  45. data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +77 -0
  46. data/lib/ronin/support/binary/ctypes/arch/arm.rb +75 -0
  47. data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +77 -0
  48. data/lib/ronin/support/binary/ctypes/arch/arm64.rb +75 -0
  49. data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +77 -0
  50. data/lib/ronin/support/binary/ctypes/arch/mips.rb +75 -0
  51. data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +77 -0
  52. data/lib/ronin/support/binary/ctypes/arch/mips64.rb +75 -0
  53. data/lib/ronin/support/binary/ctypes/arch/ppc.rb +75 -0
  54. data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +75 -0
  55. data/lib/ronin/support/binary/ctypes/arch/x86.rb +75 -0
  56. data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +75 -0
  57. data/lib/ronin/support/binary/ctypes/arch.rb +30 -0
  58. data/lib/ronin/support/binary/ctypes/array_object_type.rb +164 -0
  59. data/lib/ronin/support/binary/ctypes/array_type.rb +232 -0
  60. data/lib/ronin/support/binary/ctypes/big_endian.rb +195 -0
  61. data/lib/ronin/support/binary/ctypes/char_type.rb +59 -0
  62. data/lib/ronin/support/binary/ctypes/char_types.rb +39 -0
  63. data/lib/ronin/support/binary/ctypes/enum_type.rb +181 -0
  64. data/lib/ronin/support/binary/ctypes/float32_type.rb +50 -0
  65. data/lib/ronin/support/binary/ctypes/float64_type.rb +50 -0
  66. data/lib/ronin/support/binary/ctypes/float_type.rb +62 -0
  67. data/lib/ronin/support/binary/ctypes/int16_type.rb +50 -0
  68. data/lib/ronin/support/binary/ctypes/int32_type.rb +50 -0
  69. data/lib/ronin/support/binary/ctypes/int64_type.rb +50 -0
  70. data/lib/ronin/support/{support.rb → binary/ctypes/int8_type.rb} +20 -21
  71. data/lib/ronin/support/binary/ctypes/int_type.rb +62 -0
  72. data/lib/ronin/support/binary/ctypes/little_endian.rb +195 -0
  73. data/lib/ronin/support/binary/ctypes/mixin.rb +135 -0
  74. data/lib/ronin/support/binary/ctypes/native.rb +205 -0
  75. data/lib/ronin/support/binary/ctypes/network.rb +29 -0
  76. data/lib/ronin/support/binary/ctypes/object_type.rb +55 -0
  77. data/lib/ronin/support/binary/ctypes/os/bsd.rb +65 -0
  78. data/lib/ronin/support/binary/ctypes/os/freebsd.rb +215 -0
  79. data/lib/ronin/support/binary/ctypes/os/linux.rb +193 -0
  80. data/lib/ronin/support/binary/ctypes/os/macos.rb +151 -0
  81. data/lib/ronin/support/binary/ctypes/os/netbsd.rb +147 -0
  82. data/lib/ronin/support/binary/ctypes/os/openbsd.rb +168 -0
  83. data/lib/ronin/support/binary/ctypes/os/unix.rb +78 -0
  84. data/lib/ronin/support/binary/ctypes/os/windows.rb +125 -0
  85. data/lib/ronin/support/binary/ctypes/os.rb +125 -0
  86. data/lib/ronin/support/binary/ctypes/scalar_type.rb +200 -0
  87. data/lib/ronin/support/binary/ctypes/string_type.rb +143 -0
  88. data/lib/ronin/support/binary/ctypes/struct_object_type.rb +173 -0
  89. data/lib/ronin/support/binary/ctypes/struct_type.rb +359 -0
  90. data/lib/ronin/support/binary/ctypes/type.rb +193 -0
  91. data/lib/ronin/support/binary/ctypes/type_resolver.rb +206 -0
  92. data/lib/ronin/support/binary/ctypes/uint16_type.rb +50 -0
  93. data/lib/ronin/support/binary/ctypes/uint32_type.rb +50 -0
  94. data/lib/ronin/support/binary/ctypes/uint64_type.rb +50 -0
  95. data/lib/ronin/support/binary/ctypes/uint8_type.rb +41 -0
  96. data/lib/ronin/support/binary/ctypes/uint_type.rb +59 -0
  97. data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +258 -0
  98. data/lib/ronin/support/binary/ctypes/union_object_type.rb +173 -0
  99. data/lib/ronin/support/binary/ctypes/union_type.rb +261 -0
  100. data/lib/ronin/support/binary/ctypes.rb +462 -0
  101. data/lib/ronin/support/binary/hexdump/core_ext/file.rb +118 -0
  102. data/lib/ronin/support/binary/hexdump/core_ext/string.rb +115 -0
  103. data/lib/ronin/support/binary/hexdump/core_ext.rb +20 -0
  104. data/lib/ronin/support/binary/hexdump/parser.rb +492 -0
  105. data/lib/ronin/support/binary/hexdump.rb +20 -0
  106. data/lib/ronin/support/binary/memory.rb +268 -0
  107. data/lib/ronin/support/binary/packet.rb +33 -0
  108. data/lib/ronin/support/binary/stack.rb +256 -0
  109. data/lib/ronin/support/binary/stream/methods.rb +1755 -0
  110. data/lib/ronin/support/binary/stream.rb +151 -0
  111. data/lib/ronin/support/binary/struct/member.rb +86 -0
  112. data/lib/ronin/support/binary/struct.rb +830 -0
  113. data/lib/ronin/support/binary/template.rb +284 -0
  114. data/lib/ronin/support/binary/union.rb +162 -0
  115. data/lib/ronin/{formatting/extensions → support}/binary.rb +10 -10
  116. data/lib/ronin/support/cli/ansi.rb +330 -0
  117. data/lib/ronin/support/cli/io_shell/core_ext/io.rb +67 -0
  118. data/lib/ronin/{extensions/meta.rb → support/cli/io_shell/core_ext.rb} +3 -4
  119. data/lib/ronin/support/cli/io_shell.rb +161 -0
  120. data/lib/ronin/support/cli/printing.rb +216 -0
  121. data/lib/ronin/support/cli.rb +20 -0
  122. data/lib/ronin/support/compression/core_ext/file.rb +70 -0
  123. data/lib/ronin/support/compression/core_ext/string.rb +101 -0
  124. data/lib/ronin/{fuzzing/extensions.rb → support/compression/core_ext.rb} +3 -4
  125. data/lib/ronin/support/compression/gzip/reader.rb +70 -0
  126. data/lib/ronin/support/compression/gzip/writer.rb +74 -0
  127. data/lib/ronin/support/compression/gzip.rb +105 -0
  128. data/lib/ronin/support/compression/mixin.rb +180 -0
  129. data/lib/ronin/{network/extensions/esmtp/net.rb → support/compression/zlib.rb} +6 -7
  130. data/lib/ronin/support/compression.rb +174 -0
  131. data/lib/ronin/{extensions → support/core_ext}/enumerable.rb +2 -3
  132. data/lib/ronin/{extensions → support/core_ext}/file.rb +2 -31
  133. data/lib/ronin/support/core_ext/integer.rb +37 -0
  134. data/lib/ronin/support/core_ext/ipaddr.rb +65 -0
  135. data/lib/ronin/{extensions → support/core_ext}/kernel.rb +7 -6
  136. data/lib/ronin/{extensions → support/core_ext}/resolv.rb +2 -25
  137. data/lib/ronin/{extensions → support/core_ext}/string.rb +114 -54
  138. data/lib/ronin/support/core_ext.rb +33 -0
  139. data/lib/ronin/support/crypto/cert.rb +522 -0
  140. data/lib/ronin/support/crypto/cert_chain.rb +204 -0
  141. data/lib/ronin/support/crypto/cipher/aes.rb +71 -0
  142. data/lib/ronin/support/crypto/cipher/aes128.rb +54 -0
  143. data/lib/ronin/support/crypto/cipher/aes256.rb +54 -0
  144. data/lib/ronin/support/crypto/cipher.rb +194 -0
  145. data/lib/ronin/support/crypto/core_ext/file.rb +660 -0
  146. data/lib/ronin/support/crypto/core_ext/string.rb +548 -0
  147. data/lib/ronin/{binary.rb → support/crypto/core_ext.rb} +4 -5
  148. data/lib/ronin/{network/mixins/mixin.rb → support/crypto/hmac.rb} +18 -28
  149. data/lib/ronin/support/crypto/key/dh.rb +122 -0
  150. data/lib/ronin/support/crypto/key/dsa.rb +103 -0
  151. data/lib/ronin/support/crypto/key/ec.rb +99 -0
  152. data/lib/ronin/support/crypto/key/methods.rb +163 -0
  153. data/lib/ronin/support/crypto/key/rsa.rb +169 -0
  154. data/lib/ronin/support/crypto/key.rb +105 -0
  155. data/lib/ronin/support/crypto/mixin.rb +620 -0
  156. data/lib/ronin/{network/extensions/http/net.rb → support/crypto/openssl.rb} +6 -7
  157. data/lib/ronin/support/crypto.rb +779 -0
  158. data/lib/ronin/support/encoding/base16/core_ext/string.rb +63 -0
  159. data/lib/ronin/{formatting/binary.rb → support/encoding/base16/core_ext.rb} +3 -4
  160. data/lib/ronin/support/encoding/base16.rb +82 -0
  161. data/lib/ronin/support/encoding/base32/core_ext/string.rb +63 -0
  162. data/lib/ronin/support/encoding/base32/core_ext.rb +19 -0
  163. data/lib/ronin/support/encoding/base32.rb +164 -0
  164. data/lib/ronin/support/encoding/base64/core_ext/string.rb +76 -0
  165. data/lib/ronin/support/encoding/base64/core_ext.rb +19 -0
  166. data/lib/ronin/support/encoding/base64.rb +78 -0
  167. data/lib/ronin/support/encoding/c/core_ext/integer.rb +82 -0
  168. data/lib/ronin/support/encoding/c/core_ext/string.rb +125 -0
  169. data/lib/ronin/support/encoding/c/core_ext.rb +20 -0
  170. data/lib/ronin/support/encoding/c.rb +277 -0
  171. data/lib/ronin/support/encoding/core_ext/string.rb +107 -0
  172. data/lib/ronin/support/encoding/core_ext.rb +33 -0
  173. data/lib/ronin/support/encoding/hex/core_ext/integer.rb +82 -0
  174. data/lib/ronin/support/encoding/hex/core_ext/string.rb +133 -0
  175. data/lib/ronin/support/encoding/hex/core_ext.rb +22 -0
  176. data/lib/ronin/support/encoding/hex.rb +248 -0
  177. data/lib/ronin/support/encoding/html/core_ext/integer.rb +106 -0
  178. data/lib/ronin/support/encoding/html/core_ext/string.rb +130 -0
  179. data/lib/ronin/support/encoding/html/core_ext.rb +20 -0
  180. data/lib/ronin/support/encoding/html.rb +233 -0
  181. data/lib/ronin/support/encoding/http/core_ext/integer.rb +95 -0
  182. data/lib/ronin/support/encoding/http/core_ext/string.rb +129 -0
  183. data/lib/ronin/support/encoding/http/core_ext.rb +20 -0
  184. data/lib/ronin/support/encoding/http.rb +241 -0
  185. data/lib/ronin/support/encoding/js/core_ext/integer.rb +67 -0
  186. data/lib/ronin/support/encoding/js/core_ext/string.rb +125 -0
  187. data/lib/ronin/support/encoding/js/core_ext.rb +20 -0
  188. data/lib/ronin/support/encoding/js.rb +279 -0
  189. data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +87 -0
  190. data/lib/ronin/support/encoding/powershell/core_ext/string.rb +145 -0
  191. data/lib/ronin/support/encoding/powershell/core_ext.rb +20 -0
  192. data/lib/ronin/support/encoding/powershell.rb +297 -0
  193. data/lib/ronin/{formatting/extensions/http/integer.rb → support/encoding/punycode/core_ext/string.rb} +23 -29
  194. data/lib/ronin/support/encoding/punycode/core_ext.rb +19 -0
  195. data/lib/ronin/support/encoding/punycode.rb +76 -0
  196. data/lib/ronin/support/encoding/quoted_printable/core_ext/string.rb +75 -0
  197. data/lib/ronin/support/encoding/quoted_printable/core_ext.rb +19 -0
  198. data/lib/ronin/support/encoding/quoted_printable.rb +102 -0
  199. data/lib/ronin/support/encoding/ruby/core_ext/string.rb +129 -0
  200. data/lib/ronin/support/encoding/ruby/core_ext.rb +19 -0
  201. data/lib/ronin/support/encoding/ruby.rb +235 -0
  202. data/lib/ronin/support/encoding/shell/core_ext/integer.rb +89 -0
  203. data/lib/ronin/support/encoding/shell/core_ext/string.rb +134 -0
  204. data/lib/ronin/support/encoding/shell/core_ext.rb +20 -0
  205. data/lib/ronin/support/encoding/shell.rb +293 -0
  206. data/lib/ronin/{network/extensions → support/encoding}/smtp.rb +4 -4
  207. data/lib/ronin/support/encoding/sql/core_ext/string.rb +114 -0
  208. data/lib/ronin/{formatting/html.rb → support/encoding/sql/core_ext.rb} +3 -4
  209. data/lib/ronin/support/encoding/sql.rb +124 -0
  210. data/lib/ronin/support/encoding/uri/core_ext/integer.rb +149 -0
  211. data/lib/ronin/support/encoding/uri/core_ext/string.rb +195 -0
  212. data/lib/ronin/support/encoding/uri/core_ext.rb +20 -0
  213. data/lib/ronin/support/encoding/uri.rb +424 -0
  214. data/lib/ronin/support/encoding/uuencoding/core_ext/string.rb +73 -0
  215. data/lib/ronin/support/encoding/uuencoding/core_ext.rb +19 -0
  216. data/lib/ronin/support/encoding/uuencoding.rb +70 -0
  217. data/lib/ronin/support/encoding/xml/core_ext/integer.rb +100 -0
  218. data/lib/ronin/support/encoding/xml/core_ext/string.rb +124 -0
  219. data/lib/ronin/support/encoding/xml/core_ext.rb +20 -0
  220. data/lib/ronin/support/encoding/xml.rb +328 -0
  221. data/lib/ronin/support/encoding.rb +46 -0
  222. data/lib/ronin/support/home.rb +88 -0
  223. data/lib/ronin/{network/network.rb → support/mixin.rb} +17 -20
  224. data/lib/ronin/support/network/asn/dns_record.rb +112 -0
  225. data/lib/ronin/support/network/asn/list.rb +269 -0
  226. data/lib/ronin/support/network/asn/record.rb +164 -0
  227. data/lib/ronin/support/network/asn/record_set.rb +226 -0
  228. data/lib/ronin/support/network/asn.rb +88 -0
  229. data/lib/ronin/{binary/hexdump.rb → support/network/core_ext.rb} +3 -4
  230. data/lib/ronin/support/network/dns/idn.rb +38 -0
  231. data/lib/ronin/support/network/dns/mixin.rb +941 -0
  232. data/lib/ronin/support/network/dns/resolver.rb +707 -0
  233. data/lib/ronin/support/network/dns.rb +1109 -0
  234. data/lib/ronin/support/network/domain.rb +70 -0
  235. data/lib/ronin/support/network/email_address.rb +574 -0
  236. data/lib/ronin/support/network/esmtp/mixin.rb +115 -0
  237. data/lib/ronin/support/network/exceptions.rb +43 -0
  238. data/lib/ronin/support/network/ftp/mixin.rb +106 -0
  239. data/lib/ronin/support/network/host.rb +1473 -0
  240. data/lib/ronin/support/network/http/cookie.rb +245 -0
  241. data/lib/ronin/support/network/http/core_ext/uri/http.rb +63 -0
  242. data/lib/ronin/support/network/http/core_ext.rb +19 -0
  243. data/lib/ronin/support/network/http/mixin.rb +890 -0
  244. data/lib/ronin/support/network/http/request.rb +215 -0
  245. data/lib/ronin/support/network/http/set_cookie.rb +210 -0
  246. data/lib/ronin/support/network/http/user_agents.rb +115 -0
  247. data/lib/ronin/support/network/http.rb +2582 -0
  248. data/lib/ronin/support/network/imap/mixin.rb +133 -0
  249. data/lib/ronin/support/network/ip/mixin.rb +114 -0
  250. data/lib/ronin/support/network/ip.rb +540 -0
  251. data/lib/ronin/support/network/ip_range/cidr.rb +252 -0
  252. data/lib/ronin/support/network/ip_range/glob.rb +309 -0
  253. data/lib/ronin/support/network/ip_range/range.rb +249 -0
  254. data/lib/ronin/support/network/ip_range.rb +284 -0
  255. data/lib/ronin/support/network/mixin.rb +58 -0
  256. data/lib/ronin/support/network/packet.rb +27 -0
  257. data/lib/ronin/support/network/pop3/mixin.rb +113 -0
  258. data/lib/ronin/support/network/proxy.rb +602 -0
  259. data/lib/ronin/support/network/public_suffix/list.rb +339 -0
  260. data/lib/ronin/support/network/public_suffix/suffix.rb +118 -0
  261. data/lib/ronin/support/network/public_suffix/suffix_set.rb +150 -0
  262. data/lib/ronin/support/network/public_suffix.rb +41 -0
  263. data/lib/ronin/support/network/smtp/email.rb +190 -0
  264. data/lib/ronin/support/network/smtp/mixin.rb +290 -0
  265. data/lib/ronin/support/network/smtp.rb +19 -0
  266. data/lib/ronin/support/network/ssl/local_cert.rb +114 -0
  267. data/lib/ronin/support/network/ssl/local_key.rb +84 -0
  268. data/lib/ronin/support/network/ssl/mixin.rb +740 -0
  269. data/lib/ronin/{network/extensions/imap/net.rb → support/network/ssl/openssl.rb} +6 -7
  270. data/lib/ronin/support/network/ssl/proxy.rb +296 -0
  271. data/lib/ronin/support/network/ssl.rb +173 -0
  272. data/lib/ronin/support/network/tcp/mixin.rb +400 -0
  273. data/lib/ronin/support/network/tcp/proxy.rb +435 -0
  274. data/lib/ronin/support/network/tcp.rb +443 -0
  275. data/lib/ronin/support/network/telnet/mixin.rb +150 -0
  276. data/lib/ronin/support/network/telnet.rb +90 -0
  277. data/lib/ronin/support/network/tld/list.rb +266 -0
  278. data/lib/ronin/support/network/tld.rb +41 -0
  279. data/lib/ronin/support/network/tls/mixin.rb +670 -0
  280. data/lib/ronin/support/network/tls/proxy.rb +135 -0
  281. data/lib/ronin/{network/mixins/dns.rb → support/network/tls.rb} +23 -25
  282. data/lib/ronin/support/network/udp/mixin.rb +389 -0
  283. data/lib/ronin/support/network/udp/proxy.rb +192 -0
  284. data/lib/ronin/support/network/udp.rb +435 -0
  285. data/lib/ronin/support/network/unix/mixin.rb +273 -0
  286. data/lib/ronin/support/network.rb +37 -0
  287. data/lib/ronin/support/path.rb +136 -0
  288. data/lib/ronin/{network/extensions/dns/net.rb → support/text/core_ext/regexp.rb} +5 -6
  289. data/lib/ronin/support/text/core_ext/string.rb +46 -0
  290. data/lib/ronin/{formatting.rb → support/text/core_ext.rb} +7 -9
  291. data/lib/ronin/support/text/entropy/core_ext/string.rb +45 -0
  292. data/lib/ronin/{formatting/http.rb → support/text/entropy/core_ext.rb} +3 -4
  293. data/lib/ronin/support/text/entropy.rb +66 -0
  294. data/lib/ronin/support/text/erb/mixin.rb +44 -0
  295. data/lib/ronin/support/text/erb.rb +19 -0
  296. data/lib/ronin/support/text/homoglyph/core_ext/string.rb +108 -0
  297. data/lib/ronin/{formatting/digest.rb → support/text/homoglyph/core_ext.rb} +3 -4
  298. data/lib/ronin/{network/http/exceptions/unknown_request.rb → support/text/homoglyph/exceptions.rb} +7 -6
  299. data/lib/ronin/support/text/homoglyph/table.rb +228 -0
  300. data/lib/ronin/support/text/homoglyph.rb +142 -0
  301. data/lib/ronin/support/text/mixin.rb +31 -0
  302. data/lib/ronin/support/text/patterns/credentials.rb +75 -0
  303. data/lib/ronin/support/text/patterns/crypto.rb +67 -0
  304. data/lib/ronin/support/text/patterns/file_system.rb +93 -0
  305. data/lib/ronin/support/text/patterns/language.rb +37 -0
  306. data/lib/ronin/support/text/patterns/network/public_suffix.rb +44 -0
  307. data/lib/ronin/support/text/patterns/network.rb +140 -0
  308. data/lib/ronin/support/text/patterns/numeric.rb +52 -0
  309. data/lib/ronin/support/text/patterns/pii.rb +105 -0
  310. data/lib/ronin/support/text/patterns/source_code.rb +148 -0
  311. data/lib/ronin/{extensions.rb → support/text/patterns.rb} +9 -13
  312. data/lib/ronin/support/text/random/mixin.rb +437 -0
  313. data/lib/ronin/support/text/random.rb +419 -0
  314. data/lib/ronin/support/text/typo/core_ext/string.rb +123 -0
  315. data/lib/ronin/support/text/typo/core_ext.rb +19 -0
  316. data/lib/ronin/support/text/typo/exceptions.rb +28 -0
  317. data/lib/ronin/support/text/typo/generator.rb +161 -0
  318. data/lib/ronin/support/text/typo.rb +260 -0
  319. data/lib/ronin/{formatting → support}/text.rb +10 -4
  320. data/lib/ronin/support/version.rb +3 -4
  321. data/lib/ronin/support.rb +17 -12
  322. data/ronin-support.gemspec +2 -1
  323. metadata +340 -289
  324. data/lib/ronin/binary/hexdump/parser.rb +0 -403
  325. data/lib/ronin/binary/struct.rb +0 -567
  326. data/lib/ronin/binary/template.rb +0 -454
  327. data/lib/ronin/extensions/ip_addr.rb +0 -216
  328. data/lib/ronin/extensions/meta/object.rb +0 -24
  329. data/lib/ronin/extensions/regexp.rb +0 -157
  330. data/lib/ronin/formatting/extensions/binary/base64.rb +0 -106
  331. data/lib/ronin/formatting/extensions/binary/file.rb +0 -77
  332. data/lib/ronin/formatting/extensions/binary/float.rb +0 -65
  333. data/lib/ronin/formatting/extensions/binary/integer.rb +0 -180
  334. data/lib/ronin/formatting/extensions/binary/string.rb +0 -345
  335. data/lib/ronin/formatting/extensions/digest/file.rb +0 -129
  336. data/lib/ronin/formatting/extensions/digest/string.rb +0 -86
  337. data/lib/ronin/formatting/extensions/digest.rb +0 -21
  338. data/lib/ronin/formatting/extensions/html/integer.rb +0 -142
  339. data/lib/ronin/formatting/extensions/html/string.rb +0 -194
  340. data/lib/ronin/formatting/extensions/html.rb +0 -21
  341. data/lib/ronin/formatting/extensions/http/string.rb +0 -110
  342. data/lib/ronin/formatting/extensions/http.rb +0 -21
  343. data/lib/ronin/formatting/extensions/sql/string.rb +0 -130
  344. data/lib/ronin/formatting/extensions/sql.rb +0 -20
  345. data/lib/ronin/formatting/extensions/text/array.rb +0 -137
  346. data/lib/ronin/formatting/extensions/text/string.rb +0 -297
  347. data/lib/ronin/formatting/extensions.rb +0 -24
  348. data/lib/ronin/fuzzing/extensions/string.rb +0 -209
  349. data/lib/ronin/fuzzing/fuzzer.rb +0 -110
  350. data/lib/ronin/fuzzing/fuzzing.rb +0 -360
  351. data/lib/ronin/fuzzing/mutator.rb +0 -161
  352. data/lib/ronin/fuzzing/repeater.rb +0 -81
  353. data/lib/ronin/fuzzing/template.rb +0 -133
  354. data/lib/ronin/fuzzing.rb +0 -21
  355. data/lib/ronin/mixin.rb +0 -89
  356. data/lib/ronin/network/dns.rb +0 -201
  357. data/lib/ronin/network/esmtp.rb +0 -113
  358. data/lib/ronin/network/extensions/dns.rb +0 -20
  359. data/lib/ronin/network/extensions/esmtp.rb +0 -20
  360. data/lib/ronin/network/extensions/http/uri/http.rb +0 -228
  361. data/lib/ronin/network/extensions/http.rb +0 -21
  362. data/lib/ronin/network/extensions/imap.rb +0 -20
  363. data/lib/ronin/network/extensions/pop3/net.rb +0 -24
  364. data/lib/ronin/network/extensions/pop3.rb +0 -20
  365. data/lib/ronin/network/extensions/smtp/net.rb +0 -24
  366. data/lib/ronin/network/extensions/ssl/net.rb +0 -24
  367. data/lib/ronin/network/extensions/ssl.rb +0 -20
  368. data/lib/ronin/network/extensions/tcp/net.rb +0 -24
  369. data/lib/ronin/network/extensions/tcp.rb +0 -20
  370. data/lib/ronin/network/extensions/telnet/net.rb +0 -24
  371. data/lib/ronin/network/extensions/telnet.rb +0 -20
  372. data/lib/ronin/network/extensions/udp/net.rb +0 -24
  373. data/lib/ronin/network/extensions/udp.rb +0 -20
  374. data/lib/ronin/network/extensions.rb +0 -29
  375. data/lib/ronin/network/ftp.rb +0 -149
  376. data/lib/ronin/network/http/exceptions.rb +0 -20
  377. data/lib/ronin/network/http/http.rb +0 -1122
  378. data/lib/ronin/network/http/proxy.rb +0 -330
  379. data/lib/ronin/network/http.rb +0 -22
  380. data/lib/ronin/network/imap.rb +0 -158
  381. data/lib/ronin/network/mixins/esmtp.rb +0 -164
  382. data/lib/ronin/network/mixins/ftp.rb +0 -155
  383. data/lib/ronin/network/mixins/http.rb +0 -227
  384. data/lib/ronin/network/mixins/imap.rb +0 -156
  385. data/lib/ronin/network/mixins/pop3.rb +0 -149
  386. data/lib/ronin/network/mixins/smtp.rb +0 -159
  387. data/lib/ronin/network/mixins/ssl.rb +0 -148
  388. data/lib/ronin/network/mixins/tcp.rb +0 -368
  389. data/lib/ronin/network/mixins/telnet.rb +0 -208
  390. data/lib/ronin/network/mixins/udp.rb +0 -381
  391. data/lib/ronin/network/mixins/unix.rb +0 -279
  392. data/lib/ronin/network/mixins.rb +0 -29
  393. data/lib/ronin/network/pop3.rb +0 -124
  394. data/lib/ronin/network/proxy.rb +0 -578
  395. data/lib/ronin/network/smtp/email.rb +0 -174
  396. data/lib/ronin/network/smtp/smtp.rb +0 -230
  397. data/lib/ronin/network/smtp.rb +0 -22
  398. data/lib/ronin/network/ssl.rb +0 -186
  399. data/lib/ronin/network/tcp/proxy.rb +0 -417
  400. data/lib/ronin/network/tcp/tcp.rb +0 -452
  401. data/lib/ronin/network/tcp.rb +0 -21
  402. data/lib/ronin/network/telnet.rb +0 -266
  403. data/lib/ronin/network/udp/proxy.rb +0 -191
  404. data/lib/ronin/network/udp/udp.rb +0 -452
  405. data/lib/ronin/network/udp.rb +0 -21
  406. data/lib/ronin/network/unix.rb +0 -286
  407. data/lib/ronin/network.rb +0 -31
  408. data/lib/ronin/path.rb +0 -133
  409. data/lib/ronin/spec/ui/output.rb +0 -22
  410. data/lib/ronin/support/inflector.rb +0 -92
  411. data/lib/ronin/templates/erb.rb +0 -78
  412. data/lib/ronin/templates/template.rb +0 -169
  413. data/lib/ronin/templates.rb +0 -21
  414. data/lib/ronin/ui/output/helpers.rb +0 -296
  415. data/lib/ronin/ui/output/output.rb +0 -142
  416. data/lib/ronin/ui/output/terminal/color.rb +0 -124
  417. data/lib/ronin/ui/output/terminal/raw.rb +0 -103
  418. data/lib/ronin/ui/output/terminal.rb +0 -21
  419. data/lib/ronin/ui/output.rb +0 -21
  420. data/lib/ronin/ui/shell.rb +0 -286
  421. data/lib/ronin/wordlist.rb +0 -287
  422. data/spec/binary/hexdump/helpers/hexdumps/ascii.bin +0 -0
  423. data/spec/binary/hexdump/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -17
  424. data/spec/binary/hexdump/helpers/hexdumps/hexdump_hex_bytes.txt +0 -17
  425. data/spec/binary/hexdump/helpers/hexdumps/hexdump_hex_shorts.txt +0 -17
  426. data/spec/binary/hexdump/helpers/hexdumps/hexdump_octal_bytes.txt +0 -17
  427. data/spec/binary/hexdump/helpers/hexdumps/hexdump_octal_shorts.txt +0 -17
  428. data/spec/binary/hexdump/helpers/hexdumps/hexdump_repeated.txt +0 -6
  429. data/spec/binary/hexdump/helpers/hexdumps/od_decimal_bytes.txt +0 -17
  430. data/spec/binary/hexdump/helpers/hexdumps/od_decimal_ints.txt +0 -17
  431. data/spec/binary/hexdump/helpers/hexdumps/od_decimal_quads.txt +0 -17
  432. data/spec/binary/hexdump/helpers/hexdumps/od_decimal_shorts.txt +0 -17
  433. data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +0 -17
  434. data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +0 -17
  435. data/spec/binary/hexdump/helpers/hexdumps/od_hex_bytes.txt +0 -17
  436. data/spec/binary/hexdump/helpers/hexdumps/od_hex_ints.txt +0 -17
  437. data/spec/binary/hexdump/helpers/hexdumps/od_hex_quads.txt +0 -17
  438. data/spec/binary/hexdump/helpers/hexdumps/od_hex_shorts.txt +0 -17
  439. data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +0 -17
  440. data/spec/binary/hexdump/helpers/hexdumps/od_octal_bytes.txt +0 -17
  441. data/spec/binary/hexdump/helpers/hexdumps/od_octal_ints.txt +0 -17
  442. data/spec/binary/hexdump/helpers/hexdumps/od_octal_quads.txt +0 -17
  443. data/spec/binary/hexdump/helpers/hexdumps/od_octal_shorts.txt +0 -17
  444. data/spec/binary/hexdump/helpers/hexdumps/od_repeated.txt +0 -6
  445. data/spec/binary/hexdump/helpers/hexdumps/repeated.bin +0 -1
  446. data/spec/binary/hexdump/helpers/hexdumps.rb +0 -13
  447. data/spec/binary/hexdump/parser_spec.rb +0 -302
  448. data/spec/binary/struct_spec.rb +0 -496
  449. data/spec/binary/template_spec.rb +0 -416
  450. data/spec/extensions/enumerable_spec.rb +0 -24
  451. data/spec/extensions/file_spec.rb +0 -61
  452. data/spec/extensions/ip_addr_spec.rb +0 -203
  453. data/spec/extensions/kernel_spec.rb +0 -30
  454. data/spec/extensions/regexp_spec.rb +0 -482
  455. data/spec/extensions/resolv_spec.rb +0 -18
  456. data/spec/extensions/string_spec.rb +0 -180
  457. data/spec/formatting/binary/array_spec.rb +0 -26
  458. data/spec/formatting/binary/base64_spec.rb +0 -50
  459. data/spec/formatting/binary/float_spec.rb +0 -36
  460. data/spec/formatting/binary/integer_spec.rb +0 -166
  461. data/spec/formatting/binary/string_spec.rb +0 -199
  462. data/spec/formatting/digest/string_spec.rb +0 -82
  463. data/spec/formatting/html/integer_spec.rb +0 -66
  464. data/spec/formatting/html/string_spec.rb +0 -103
  465. data/spec/formatting/http/integer_spec.rb +0 -42
  466. data/spec/formatting/http/string_spec.rb +0 -76
  467. data/spec/formatting/sql/string_spec.rb +0 -77
  468. data/spec/formatting/text/array_spec.rb +0 -105
  469. data/spec/formatting/text/string_spec.rb +0 -162
  470. data/spec/fuzzing/extensions/string_spec.rb +0 -87
  471. data/spec/fuzzing/fuzzer_spec.rb +0 -109
  472. data/spec/fuzzing/fuzzing_spec.rb +0 -24
  473. data/spec/fuzzing/mutator_spec.rb +0 -112
  474. data/spec/fuzzing/repeater_spec.rb +0 -57
  475. data/spec/fuzzing/template_spec.rb +0 -54
  476. data/spec/mixin_spec.rb +0 -51
  477. data/spec/network/dns_spec.rb +0 -203
  478. data/spec/network/ftp_spec.rb +0 -81
  479. data/spec/network/http/http_spec.rb +0 -559
  480. data/spec/network/http/proxy_spec.rb +0 -148
  481. data/spec/network/network_spec.rb +0 -8
  482. data/spec/network/proxy_spec.rb +0 -121
  483. data/spec/network/shared/unix_server.rb +0 -31
  484. data/spec/network/smtp/email_spec.rb +0 -100
  485. data/spec/network/ssl_spec.rb +0 -70
  486. data/spec/network/tcp/proxy_spec.rb +0 -118
  487. data/spec/network/tcp/tcp_spec.rb +0 -316
  488. data/spec/network/telnet_spec.rb +0 -67
  489. data/spec/network/udp/udp_spec.rb +0 -298
  490. data/spec/network/unix_spec.rb +0 -182
  491. data/spec/path_spec.rb +0 -111
  492. data/spec/spec_helper.rb +0 -8
  493. data/spec/support/inflector_spec.rb +0 -22
  494. data/spec/support_spec.rb +0 -8
  495. data/spec/templates/classes/example_erb.rb +0 -11
  496. data/spec/templates/classes/example_template.rb +0 -35
  497. data/spec/templates/erb_spec.rb +0 -21
  498. data/spec/templates/helpers/data/includes/_relative.erb +0 -1
  499. data/spec/templates/helpers/data/templates/example.erb +0 -1
  500. data/spec/templates/helpers/data.rb +0 -9
  501. data/spec/templates/template_spec.rb +0 -54
  502. data/spec/ui/classes/test_shell.rb +0 -22
  503. data/spec/ui/output_spec.rb +0 -32
  504. data/spec/ui/shell_spec.rb +0 -83
  505. data/spec/wordlist_spec.rb +0 -151
@@ -0,0 +1,1755 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2006-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-support is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-support is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-support. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'ronin/support/binary/buffer'
20
+ require 'ronin/support/binary/array'
21
+ require 'ronin/support/binary/struct'
22
+ require 'ronin/support/binary/union'
23
+
24
+ module Ronin
25
+ module Support
26
+ module Binary
27
+ class Stream
28
+ #
29
+ # Adds `read_*`/`write_*` methods for reading and writing binary data
30
+ # types.
31
+ #
32
+ # @api private
33
+ #
34
+ # @since 1.0.0
35
+ #
36
+ module Methods
37
+ #
38
+ # @group Reader Methods
39
+ #
40
+
41
+ #
42
+ # Reads a value of the given type from the IO stream.
43
+ #
44
+ # @param [Symbol] type
45
+ # The desired type of data to read.
46
+ #
47
+ # @return [Integer, Float, String, nil]
48
+ # The read value.
49
+ #
50
+ # @api public
51
+ #
52
+ def read_value(type)
53
+ type = type_system[type]
54
+
55
+ if (slice = read(type.size))
56
+ type.unpack(slice)
57
+ end
58
+ end
59
+
60
+ #
61
+ # Alias for `read_value(:byte)`.
62
+ #
63
+ # @return [Integer]
64
+ # The read `byte`.
65
+ #
66
+ # @see #read_value
67
+ #
68
+ # @api public
69
+ #
70
+ def read_byte
71
+ read_value(:byte)
72
+ end
73
+
74
+ #
75
+ # Alias for `read_value(:char)`.
76
+ #
77
+ # @return [String]
78
+ # The read `char`.
79
+ #
80
+ # @see #read_value
81
+ #
82
+ # @api public
83
+ #
84
+ def read_char
85
+ read_value(:char)
86
+ end
87
+
88
+ #
89
+ # Alias for `read_value(:uchar)`.
90
+ #
91
+ # @return [String]
92
+ # The read `uchar`.
93
+ #
94
+ # @see #read_value
95
+ #
96
+ # @api public
97
+ #
98
+ def read_uchar
99
+ read_value(:uchar)
100
+ end
101
+
102
+ #
103
+ # Reads a null-byte terminated C string from the buffer.
104
+ #
105
+ # @param [Integer, nil] length
106
+ # The optional maximum desired length of the string.
107
+ #
108
+ # @return [String]
109
+ # The read C string, without the null-byte.
110
+ #
111
+ # @api public
112
+ #
113
+ def read_string(length=nil)
114
+ new_string = String.new('', encoding: external_encoding)
115
+
116
+ if length
117
+ length.times do
118
+ if eof? || ((c = read(1)) == "\0")
119
+ break
120
+ end
121
+
122
+ new_string << c
123
+ end
124
+ else
125
+ until eof?
126
+ if ((c = read(1)) == "\0")
127
+ break
128
+ end
129
+
130
+ new_string << c
131
+ end
132
+ end
133
+
134
+ return new_string
135
+ end
136
+
137
+ #
138
+ # Alias for `read_value(:int8)`.
139
+ #
140
+ # @return [Integer, nil]
141
+ # The read `int8`.
142
+ #
143
+ # @see #read_value
144
+ #
145
+ # @api public
146
+ #
147
+ def read_int8
148
+ read_value(:int8)
149
+ end
150
+
151
+ #
152
+ # Alias for `read_value(:int16)`.
153
+ #
154
+ # @return [Integer, nil]
155
+ # The read `int16`.
156
+ #
157
+ # @see #read_value
158
+ #
159
+ # @api public
160
+ #
161
+ def read_int16
162
+ read_value(:int16)
163
+ end
164
+
165
+ #
166
+ # Alias for `read_value(:int32)`.
167
+ #
168
+ # @return [Integer, nil]
169
+ # The read `int32`.
170
+ #
171
+ # @see #read_value
172
+ #
173
+ # @api public
174
+ #
175
+ def read_int32
176
+ read_value(:int32)
177
+ end
178
+
179
+ #
180
+ # Alias for `read_value(:int64)`.
181
+ #
182
+ # @return [Integer, nil]
183
+ # The read `int64`.
184
+ #
185
+ # @see #read_value
186
+ #
187
+ # @api public
188
+ #
189
+ def read_int64
190
+ read_value(:int64)
191
+ end
192
+
193
+ #
194
+ # Alias for `read_value(:uint8)`.
195
+ #
196
+ # @return [Integer, nil]
197
+ # The read `uint8`.
198
+ #
199
+ # @see #read_value
200
+ #
201
+ # @api public
202
+ #
203
+ def read_uint8
204
+ read_value(:uint8)
205
+ end
206
+
207
+ #
208
+ # Alias for `read_value(:uint16)`.
209
+ #
210
+ # @return [Integer, nil]
211
+ # The read `uint16`.
212
+ #
213
+ # @see #read_value
214
+ #
215
+ # @api public
216
+ #
217
+ def read_uint16
218
+ read_value(:uint16)
219
+ end
220
+
221
+ #
222
+ # Alias for `read_value(:uint32)`.
223
+ #
224
+ # @return [Integer, nil]
225
+ # The read `uint32`.
226
+ #
227
+ # @see #read_value
228
+ #
229
+ # @api public
230
+ #
231
+ def read_uint32
232
+ read_value(:uint32)
233
+ end
234
+
235
+ #
236
+ # Alias for `read_value(:uint64)`.
237
+ #
238
+ # @return [Integer, nil]
239
+ # The read `uint64`.
240
+ #
241
+ # @see #read_value
242
+ #
243
+ # @api public
244
+ #
245
+ def read_uint64
246
+ read_value(:uint64)
247
+ end
248
+
249
+ #
250
+ # Alias for `read_value(:short)`.
251
+ #
252
+ # @return [Integer, nil]
253
+ # The read `short`.
254
+ #
255
+ # @see #read_value
256
+ #
257
+ # @api public
258
+ #
259
+ def read_short
260
+ read_value(:short)
261
+ end
262
+
263
+ #
264
+ # Alias for `read_value(:int)`.
265
+ #
266
+ # @return [Integer, nil]
267
+ # The read `int`.
268
+ #
269
+ # @see #read_value
270
+ #
271
+ # @api public
272
+ #
273
+ def read_int
274
+ read_value(:int)
275
+ end
276
+
277
+ #
278
+ # Alias for `read_value(:long)`.
279
+ #
280
+ # @return [Integer, nil]
281
+ # The read `long`.
282
+ #
283
+ # @see #read_value
284
+ #
285
+ # @api public
286
+ #
287
+ def read_long
288
+ read_value(:long)
289
+ end
290
+
291
+ #
292
+ # Alias for `read_value(:long_long)`.
293
+ #
294
+ # @return [Integer, nil]
295
+ # The read `long_long`.
296
+ #
297
+ # @see #read_value
298
+ #
299
+ # @api public
300
+ #
301
+ def read_long_long
302
+ read_value(:long_long)
303
+ end
304
+
305
+ #
306
+ # Alias for `read_value(:ushort)`.
307
+ #
308
+ # @return [Integer, nil]
309
+ # The read `ushort`.
310
+ #
311
+ # @see #read_value
312
+ #
313
+ # @api public
314
+ #
315
+ def read_ushort
316
+ read_value(:ushort)
317
+ end
318
+
319
+ #
320
+ # Alias for `read_value(:uint)`.
321
+ #
322
+ # @return [Integer, nil]
323
+ # The read `uint`.
324
+ #
325
+ # @see #read_value
326
+ #
327
+ # @api public
328
+ #
329
+ def read_uint
330
+ read_value(:uint)
331
+ end
332
+
333
+ #
334
+ # Alias for `read_value(:ulong)`.
335
+ #
336
+ # @return [Integer, nil]
337
+ # The read `ulong`.
338
+ #
339
+ # @see #read_value
340
+ #
341
+ # @api public
342
+ #
343
+ def read_ulong
344
+ read_value(:ulong)
345
+ end
346
+
347
+ #
348
+ # Alias for `read_value(:ulong_long)`.
349
+ #
350
+ # @return [Integer, nil]
351
+ # The read `ulong_long`.
352
+ #
353
+ # @see #read_value
354
+ #
355
+ # @api public
356
+ #
357
+ def read_ulong_long
358
+ read_value(:ulong_long)
359
+ end
360
+
361
+ #
362
+ # Alias for `read_value(:float32)`.
363
+ #
364
+ # @return [Float, nil]
365
+ # The read `float32`.
366
+ #
367
+ # @see #read_value
368
+ #
369
+ # @api public
370
+ #
371
+ def read_float32
372
+ read_value(:float32)
373
+ end
374
+
375
+ #
376
+ # Alias for `read_value(:float64)`.
377
+ #
378
+ # @return [Float, nil]
379
+ # The read `float64`.
380
+ #
381
+ # @see #read_value
382
+ #
383
+ # @api public
384
+ #
385
+ def read_float64
386
+ read_value(:float64)
387
+ end
388
+
389
+ #
390
+ # Alias for `read_value(:float)`.
391
+ #
392
+ # @return [Float, nil]
393
+ # The read `float`.
394
+ #
395
+ # @see #read_value
396
+ #
397
+ # @api public
398
+ #
399
+ def read_float
400
+ read_value(:float)
401
+ end
402
+
403
+ #
404
+ # Alias for `read_value(:double)`.
405
+ #
406
+ # @return [Float, nil]
407
+ # The read `double`.
408
+ #
409
+ # @see #read_value
410
+ #
411
+ # @api public
412
+ #
413
+ def read_double
414
+ read_value(:double)
415
+ end
416
+
417
+ #
418
+ # Reads an array of the given type, starting at the given with
419
+ # the given length.
420
+ #
421
+ # @param [Symbol] type
422
+ # The type of the value to read.
423
+ #
424
+ # @param [Integer] count
425
+ # The number of desired elements within the array.
426
+ #
427
+ # @return [Array<Object>]
428
+ # The read array of types.
429
+ #
430
+ # @api public
431
+ #
432
+ def read_array_of(type,count)
433
+ type = type_system[type]
434
+ array_type = type[count]
435
+ data = read(array_type.size)
436
+
437
+ return array_type.unpack(data)
438
+ end
439
+
440
+ #
441
+ # Alias to `read_array_of(:byte,count)`.
442
+ #
443
+ # @param [Integer] count
444
+ # The number of bytes to read.
445
+ #
446
+ # @return [Array<Integer, nil>]
447
+ # The read array of bytes.
448
+ #
449
+ # @see #read_array_of
450
+ #
451
+ # @api public
452
+ #
453
+ def read_array_of_byte(count)
454
+ read_array_of(:byte,count)
455
+ end
456
+
457
+ alias read_bytes read_array_of_byte
458
+
459
+ #
460
+ # Alias to `read_array_of(:char,count)`.
461
+ #
462
+ # @param [Integer] count
463
+ # The number of chars to read.
464
+ #
465
+ # @return [Array<Integer, nil>]
466
+ # The read array of chars.
467
+ #
468
+ # @see #read_array_of
469
+ #
470
+ # @api public
471
+ #
472
+ def read_array_of_char(count)
473
+ read_array_of(:char,count)
474
+ end
475
+
476
+ alias read_chars read_array_of_char
477
+
478
+ #
479
+ # Alias to `read_array_of(:uchar,count)`.
480
+ #
481
+ # @param [Integer] count
482
+ # The number of unsigned chars to read.
483
+ #
484
+ # @return [Array<Integer, nil>]
485
+ # The read array of unsigned chars.
486
+ #
487
+ # @see #read_array_of
488
+ #
489
+ # @api public
490
+ #
491
+ def read_array_of_uchar(count)
492
+ read_array_of(:uchar,count)
493
+ end
494
+
495
+ alias read_uchars read_array_of_uchar
496
+
497
+ #
498
+ # Alias to `read_array_of(:int8,count)`.
499
+ #
500
+ # @param [Integer] count
501
+ # The number of `int8` values to read.
502
+ #
503
+ # @return [Array<Integer, nil>]
504
+ # The read array of `int8` values.
505
+ #
506
+ # @see #read_array_of
507
+ #
508
+ # @api public
509
+ #
510
+ def read_array_of_int8(count)
511
+ read_array_of(:int8,count)
512
+ end
513
+
514
+ #
515
+ # Alias to `read_array_of(:int16,count)`.
516
+ #
517
+ # @param [Integer] count
518
+ # The number of `int16` values to read.
519
+ #
520
+ # @return [Array<Integer, nil>]
521
+ # The read array of `int16` values.
522
+ #
523
+ # @see #read_array_of
524
+ #
525
+ # @api public
526
+ #
527
+ def read_array_of_int16(count)
528
+ read_array_of(:int16,count)
529
+ end
530
+
531
+ #
532
+ # Alias to `read_array_of(:int32,count)`.
533
+ #
534
+ # @param [Integer] count
535
+ # The number of `int32` values to read.
536
+ #
537
+ # @return [Array<Integer, nil>]
538
+ # The read array of `int32` values.
539
+ #
540
+ # @see #read_array_of
541
+ #
542
+ # @api public
543
+ #
544
+ def read_array_of_int32(count)
545
+ read_array_of(:int32,count)
546
+ end
547
+
548
+ #
549
+ # Alias to `read_array_of(:int64,count)`.
550
+ #
551
+ # @param [Integer] count
552
+ # The number of `int64` values to read.
553
+ #
554
+ # @return [Array<Integer, nil>]
555
+ # The read array of `int64` values.
556
+ #
557
+ # @see #read_array_of
558
+ #
559
+ # @api public
560
+ #
561
+ def read_array_of_int64(count)
562
+ read_array_of(:int64,count)
563
+ end
564
+
565
+ #
566
+ # Alias to `read_array_of(:uint8,count)`.
567
+ #
568
+ # @param [Integer] count
569
+ # The number of `uint8` values to read.
570
+ #
571
+ # @return [Array<Integer, nil>]
572
+ # The read array of `uint8` values.
573
+ #
574
+ # @see #read_array_of
575
+ #
576
+ # @api public
577
+ #
578
+ def read_array_of_uint8(count)
579
+ read_array_of(:uint8,count)
580
+ end
581
+
582
+ #
583
+ # Alias to `read_array_of(:uint16,count)`.
584
+ #
585
+ # @param [Integer] count
586
+ # The number of `uint16` values to read.
587
+ #
588
+ # @return [Array<Integer, nil>]
589
+ # The read array of `uint16` values.
590
+ #
591
+ # @see #read_array_of
592
+ #
593
+ # @api public
594
+ #
595
+ def read_array_of_uint16(count)
596
+ read_array_of(:uint16,count)
597
+ end
598
+
599
+ #
600
+ # Alias to `read_array_of(:uint32,count)`.
601
+ #
602
+ # @param [Integer] count
603
+ # The number of `uint32` values to read.
604
+ #
605
+ # @return [Array<Integer, nil>]
606
+ # The read array of `uint32` values.
607
+ #
608
+ # @see #read_array_of
609
+ #
610
+ # @api public
611
+ #
612
+ def read_array_of_uint32(count)
613
+ read_array_of(:uint32,count)
614
+ end
615
+
616
+ #
617
+ # Alias to `read_array_of(:uint64,count)`.
618
+ #
619
+ # @param [Integer] count
620
+ # The number of `uint64` values to read.
621
+ #
622
+ # @return [Array<Integer, nil>]
623
+ # The read array of `uint64` values.
624
+ #
625
+ # @see #read_array_of
626
+ #
627
+ # @api public
628
+ #
629
+ def read_array_of_uint64(count)
630
+ read_array_of(:uint64,count)
631
+ end
632
+
633
+ #
634
+ # Alias to `read_array_of(:short,count)`.
635
+ #
636
+ # @param [Integer] count
637
+ # The number of `short` values to read.
638
+ #
639
+ # @return [Array<Integer, nil>]
640
+ # The read array of `short` values.
641
+ #
642
+ # @see #read_array_of
643
+ #
644
+ # @api public
645
+ #
646
+ def read_array_of_short(count)
647
+ read_array_of(:short,count)
648
+ end
649
+
650
+ #
651
+ # Alias to `read_array_of(:int,count)`.
652
+ #
653
+ # @param [Integer] count
654
+ # The number of `int` values to read.
655
+ #
656
+ # @return [Array<Integer, nil>]
657
+ # The read array of `int` values.
658
+ #
659
+ # @see #read_array_of
660
+ #
661
+ # @api public
662
+ #
663
+ def read_array_of_int(count)
664
+ read_array_of(:int,count)
665
+ end
666
+
667
+ alias read_ints read_array_of_int
668
+
669
+ #
670
+ # Alias to `read_array_of(:long,count)`.
671
+ #
672
+ # @param [Integer] count
673
+ # The number of `long` values to read.
674
+ #
675
+ # @return [Array<Integer, nil>]
676
+ # The read array of `long` values.
677
+ #
678
+ # @see #read_array_of
679
+ #
680
+ # @api public
681
+ #
682
+ def read_array_of_long(count)
683
+ read_array_of(:long,count)
684
+ end
685
+
686
+ #
687
+ # Alias to `read_array_of(:long_long,count)`.
688
+ #
689
+ # @param [Integer] count
690
+ # The number of `long_long` values to read.
691
+ #
692
+ # @return [Array<Integer, nil>]
693
+ # The read array of `long_long` values.
694
+ #
695
+ # @see #read_array_of
696
+ #
697
+ # @api public
698
+ #
699
+ def read_array_of_long_long(count)
700
+ read_array_of(:long_long,count)
701
+ end
702
+
703
+ #
704
+ # Alias to `read_array_of(:ushort,count)`.
705
+ #
706
+ # @param [Integer] count
707
+ # The number of `ushort` values to read.
708
+ #
709
+ # @return [Array<Integer, nil>]
710
+ # The read array of `ushort` values.
711
+ #
712
+ # @see #read_array_of
713
+ #
714
+ # @api public
715
+ #
716
+ def read_array_of_ushort(count)
717
+ read_array_of(:ushort,count)
718
+ end
719
+
720
+ #
721
+ # Alias to `read_array_of(:uint,count)`.
722
+ #
723
+ # @param [Integer] count
724
+ # The number of `uint` values to read.
725
+ #
726
+ # @return [Array<Integer, nil>]
727
+ # The read array of `uint` values.
728
+ #
729
+ # @see #read_array_of
730
+ #
731
+ # @api public
732
+ #
733
+ def read_array_of_uint(count)
734
+ read_array_of(:uint,count)
735
+ end
736
+
737
+ alias read_uints read_array_of_uint
738
+
739
+ #
740
+ # Alias to `read_array_of(:ulong,count)`.
741
+ #
742
+ # @param [Integer] count
743
+ # The number of `ulong` values to read.
744
+ #
745
+ # @return [Array<Integer, nil>]
746
+ # The read array of `ulong` values.
747
+ #
748
+ # @see #read_array_of
749
+ #
750
+ # @api public
751
+ #
752
+ def read_array_of_ulong(count)
753
+ read_array_of(:ulong,count)
754
+ end
755
+
756
+ #
757
+ # Alias to `read_array_of(:ulong_long,count)`.
758
+ #
759
+ # @param [Integer] count
760
+ # The number of `ulong_long` values to read.
761
+ #
762
+ # @return [Array<Integer, nil>]
763
+ # The read array of `ulong_long` values.
764
+ #
765
+ # @see #read_array_of
766
+ #
767
+ # @api public
768
+ #
769
+ def read_array_of_ulong_long(count)
770
+ read_array_of(:ulong_long,count)
771
+ end
772
+
773
+ #
774
+ # Alias to `read_array_of(:float32,count)`.
775
+ #
776
+ # @param [Integer] count
777
+ # The number of `float32` values to read.
778
+ #
779
+ # @return [Array<Float, nil>]
780
+ # The read array of `float32` values.
781
+ #
782
+ # @see #read_array_of
783
+ #
784
+ # @api public
785
+ #
786
+ def read_array_of_float32(count)
787
+ read_array_of(:float32,count)
788
+ end
789
+
790
+ #
791
+ # Alias to `read_array_of(:float64,count)`.
792
+ #
793
+ # @param [Integer] count
794
+ # The number of `float64` values to read.
795
+ #
796
+ # @return [Array<Float, nil>]
797
+ # The read array of `float64` values.
798
+ #
799
+ # @see #read_array_of
800
+ #
801
+ # @api public
802
+ #
803
+ def read_array_of_float64(count)
804
+ read_array_of(:float64,count)
805
+ end
806
+
807
+ #
808
+ # Alias to `read_array_of(:float,count)`.
809
+ #
810
+ # @param [Integer] count
811
+ # The number of `float` values to read.
812
+ #
813
+ # @return [Array<Float, nil>]
814
+ # The read array of `float` values.
815
+ #
816
+ # @see #read_array_of
817
+ #
818
+ # @api public
819
+ #
820
+ def read_array_of_float(count)
821
+ read_array_of(:float,count)
822
+ end
823
+
824
+ alias read_floats read_array_of_float
825
+
826
+ #
827
+ # Alias to `read_array_of(:double,count)`.
828
+ #
829
+ # @param [Integer] count
830
+ # The number of `double` values to read.
831
+ #
832
+ # @return [Array<Float, nil>]
833
+ # The read array of `double` values.
834
+ #
835
+ # @see #read_array_of
836
+ #
837
+ # @api public
838
+ #
839
+ def read_array_of_double(count)
840
+ read_array_of(:double,count)
841
+ end
842
+
843
+ alias read_doubles read_array_of_double
844
+
845
+ #
846
+ # Reads data from the stream into the memory object.
847
+ #
848
+ # @param [Buffer, Array, Struct, Union] memory
849
+ # The object ot read data into.
850
+ #
851
+ # @return [Buffer, Array, Struct, Union]
852
+ # The memory object.
853
+ #
854
+ # @see Memory#read_from
855
+ #
856
+ # @api public
857
+ #
858
+ def read_into(memory)
859
+ memory.read_from(self)
860
+ end
861
+
862
+ #
863
+ # Reads a buffer of count bytes from the stream.
864
+ #
865
+ # @param [Integer] count
866
+ # The number of bytes to read from the stream.
867
+ #
868
+ # @return [Buffer]
869
+ # The newly read buffer.
870
+ #
871
+ # @see Buffer.read_from
872
+ #
873
+ # @api public
874
+ #
875
+ def read_buffer(count)
876
+ Buffer.read_from(self,count)
877
+ end
878
+
879
+ #
880
+ # Reads an array of the given type and length from the stream.
881
+ #
882
+ # @param [Symbol] type
883
+ # The element type for the new array.
884
+ #
885
+ # @param [Integer] length
886
+ # The number of elements for the new array.
887
+ #
888
+ # @return [Binary::Array]
889
+ # The newly read array.
890
+ #
891
+ # @see Binary::Array.read_from
892
+ #
893
+ # @api public
894
+ #
895
+ def read_array(type,length)
896
+ Array.read_from(self,type,length)
897
+ end
898
+
899
+ #
900
+ # Reads a struct from the stream.
901
+ #
902
+ # @param [Binary::Struct.class] struct_class
903
+ # The struct class to read.
904
+ #
905
+ # @return [Binary::Struct]
906
+ # The newly read struct object.
907
+ #
908
+ # @see Binary::Struct.read_from
909
+ #
910
+ # @api public
911
+ #
912
+ def read_struct(struct_class)
913
+ struct_class.read_from(self)
914
+ end
915
+
916
+ #
917
+ # Reads a union from the stream.
918
+ #
919
+ # @param [Binary::Union.class] union_class
920
+ # The union class to read.
921
+ #
922
+ # @return [Binary::Union]
923
+ # The newly read union object.
924
+ #
925
+ # @see Binary::Struct.read_from
926
+ #
927
+ # @api public
928
+ #
929
+ def read_union(union_class)
930
+ union_class.read_from(self)
931
+ end
932
+
933
+ #
934
+ # @group Writer Methods
935
+ #
936
+
937
+ #
938
+ # Writes the value to the IO stream.
939
+ #
940
+ # @param [Symbol] type
941
+ # The type of value to write.
942
+ #
943
+ # @param [Integer, Float, String] value
944
+ # The value to write.
945
+ #
946
+ # @return [self]
947
+ #
948
+ # @api public
949
+ #
950
+ def write_value(type,value)
951
+ type = type_system[type]
952
+ data = type.pack(value)
953
+
954
+ write(data)
955
+ return self
956
+ end
957
+
958
+ #
959
+ # Alias for `write_value(:byte,value)`.
960
+ #
961
+ # @param [Integer] value
962
+ # The `char` value to write into the buffer.
963
+ #
964
+ # @return [self]
965
+ #
966
+ # @see #write_value
967
+ #
968
+ # @api public
969
+ #
970
+ def write_byte(value)
971
+ write_value(:byte,value)
972
+ end
973
+
974
+ #
975
+ # Alias for `write_value(:char,value)`.
976
+ #
977
+ # @param [String] value
978
+ # The `char` value to write into the buffer.
979
+ #
980
+ # @return [self]
981
+ #
982
+ # @see #write_value
983
+ #
984
+ # @api public
985
+ #
986
+ def write_char(value)
987
+ write_value(:char,value)
988
+ end
989
+
990
+ #
991
+ # Writes a null-terminated C string to the buffer.
992
+ #
993
+ # @param [String] string
994
+ # The String to write into the buffer.
995
+ #
996
+ # @return [self]
997
+ #
998
+ # @api public
999
+ #
1000
+ def write_string(string)
1001
+ ascii_string = string.encode(Encoding::ASCII_8BIT)
1002
+ cstring = if ascii_string.end_with?("\0")
1003
+ ascii_string
1004
+ else
1005
+ "#{ascii_string}\0"
1006
+ end
1007
+
1008
+ write(cstring)
1009
+ return self
1010
+ end
1011
+
1012
+ #
1013
+ # Alias for `write_value(:uchar,value)`.
1014
+ #
1015
+ # @param [String] value
1016
+ # The `uchar` value to write into the buffer.
1017
+ #
1018
+ # @return [self]
1019
+ #
1020
+ # @see #write_value
1021
+ #
1022
+ # @api public
1023
+ #
1024
+ def write_uchar(value)
1025
+ write_value(:uchar,value)
1026
+ end
1027
+
1028
+ #
1029
+ # Alias for `write_value(:int8,value)`.
1030
+ #
1031
+ # @param [Integer] value
1032
+ # The `int8` value to write into the buffer.
1033
+ #
1034
+ # @return [self]
1035
+ #
1036
+ # @see #write_value
1037
+ #
1038
+ # @api public
1039
+ #
1040
+ def write_int8(value)
1041
+ write_value(:int8,value)
1042
+ end
1043
+
1044
+ #
1045
+ # Alias for `write_value(:int16,value)`.
1046
+ #
1047
+ # @param [Integer] value
1048
+ # The `int16` value to write into the buffer.
1049
+ #
1050
+ # @return [self]
1051
+ #
1052
+ # @see #write_value
1053
+ #
1054
+ # @api public
1055
+ #
1056
+ def write_int16(value)
1057
+ write_value(:int16,value)
1058
+ end
1059
+
1060
+ #
1061
+ # Alias for `write_value(:int32,value)`.
1062
+ #
1063
+ # @param [Integer] value
1064
+ # The `int32` value to write into the buffer.
1065
+ #
1066
+ # @return [self]
1067
+ #
1068
+ # @see #write_value
1069
+ #
1070
+ # @api public
1071
+ #
1072
+ def write_int32(value)
1073
+ write_value(:int32,value)
1074
+ end
1075
+
1076
+ #
1077
+ # Alias for `write_value(:int64,value)`.
1078
+ #
1079
+ # @param [Integer] value
1080
+ # The `int64` value to write into the buffer.
1081
+ #
1082
+ # @return [self]
1083
+ #
1084
+ # @see #write_value
1085
+ #
1086
+ # @api public
1087
+ #
1088
+ def write_int64(value)
1089
+ write_value(:int64,value)
1090
+ end
1091
+
1092
+ #
1093
+ # Alias for `write_value(:uint8,value)`.
1094
+ #
1095
+ # @param [Integer] value
1096
+ # The `uint8` value to write into the buffer.
1097
+ #
1098
+ # @return [self]
1099
+ #
1100
+ # @see #write_value
1101
+ #
1102
+ # @api public
1103
+ #
1104
+ def write_uint8(value)
1105
+ write_value(:uint8,value)
1106
+ end
1107
+
1108
+ #
1109
+ # Alias for `write_value(:uint16,value)`.
1110
+ #
1111
+ # @param [Integer] value
1112
+ # The `uint16` value to write into the buffer.
1113
+ #
1114
+ # @return [self]
1115
+ #
1116
+ # @see #write_value
1117
+ #
1118
+ # @api public
1119
+ #
1120
+ def write_uint16(value)
1121
+ write_value(:uint16,value)
1122
+ end
1123
+
1124
+ #
1125
+ # Alias for `write_value(:uint32,value)`.
1126
+ #
1127
+ # @param [Integer] value
1128
+ # The `uint32` value to write into the buffer.
1129
+ #
1130
+ # @return [self]
1131
+ #
1132
+ # @see #write_value
1133
+ #
1134
+ # @api public
1135
+ #
1136
+ def write_uint32(value)
1137
+ write_value(:uint32,value)
1138
+ end
1139
+
1140
+ #
1141
+ # Alias for `write_value(:uint64,value)`.
1142
+ #
1143
+ # @param [Integer] value
1144
+ # The `uint64` value to write into the buffer.
1145
+ #
1146
+ # @return [self]
1147
+ #
1148
+ # @see #write_value
1149
+ #
1150
+ # @api public
1151
+ #
1152
+ def write_uint64(value)
1153
+ write_value(:uint64,value)
1154
+ end
1155
+
1156
+ #
1157
+ # Alias for `write_value(:short,value)`.
1158
+ #
1159
+ # @param [Integer] value
1160
+ # The `short` value to write into the buffer.
1161
+ #
1162
+ # @return [self]
1163
+ #
1164
+ # @see #write_value
1165
+ #
1166
+ # @api public
1167
+ #
1168
+ def write_short(value)
1169
+ write_value(:short,value)
1170
+ end
1171
+
1172
+ #
1173
+ # Alias for `write_value(:int,value)`.
1174
+ #
1175
+ # @param [Integer] value
1176
+ # The `int` value to write into the buffer.
1177
+ #
1178
+ # @return [self]
1179
+ #
1180
+ # @see #write_value
1181
+ #
1182
+ # @api public
1183
+ #
1184
+ def write_int(value)
1185
+ write_value(:int,value)
1186
+ end
1187
+
1188
+ #
1189
+ # Alias for `write_value(:long,value)`.
1190
+ #
1191
+ # @param [Integer] value
1192
+ # The `long` value to write into the buffer.
1193
+ #
1194
+ # @return [self]
1195
+ #
1196
+ # @see #write_value
1197
+ #
1198
+ # @api public
1199
+ #
1200
+ def write_long(value)
1201
+ write_value(:long,value)
1202
+ end
1203
+
1204
+ #
1205
+ # Alias for `write_value(:long_long,value)`.
1206
+ #
1207
+ # @param [Integer] value
1208
+ # The `long_long` value to write into the buffer.
1209
+ #
1210
+ # @return [self]
1211
+ #
1212
+ # @see #write_value
1213
+ #
1214
+ # @api public
1215
+ #
1216
+ def write_long_long(value)
1217
+ write_value(:long_long,value)
1218
+ end
1219
+
1220
+ #
1221
+ # Alias for `write_value(:ushort,value)`.
1222
+ #
1223
+ # @param [Integer] value
1224
+ # The `ushort` value to write into the buffer.
1225
+ #
1226
+ # @return [self]
1227
+ #
1228
+ # @see #write_value
1229
+ #
1230
+ # @api public
1231
+ #
1232
+ def write_ushort(value)
1233
+ write_value(:ushort,value)
1234
+ end
1235
+
1236
+ #
1237
+ # Alias for `write_value(:uint,value)`.
1238
+ #
1239
+ # @param [Integer] value
1240
+ # The `uint` value to write into the buffer.
1241
+ #
1242
+ # @return [self]
1243
+ #
1244
+ # @see #write_value
1245
+ #
1246
+ # @api public
1247
+ #
1248
+ def write_uint(value)
1249
+ write_value(:uint,value)
1250
+ end
1251
+
1252
+ #
1253
+ # Alias for `write_value(:ulong,value)`.
1254
+ #
1255
+ # @param [Integer] value
1256
+ # The `ulong` value to write into the buffer.
1257
+ #
1258
+ # @return [self]
1259
+ #
1260
+ # @see #write_value
1261
+ #
1262
+ # @api public
1263
+ #
1264
+ def write_ulong(value)
1265
+ write_value(:ulong,value)
1266
+ end
1267
+
1268
+ #
1269
+ # Alias for `write_value(:ulong_long,value)`.
1270
+ #
1271
+ # @param [Integer] value
1272
+ # The `ulong_long` value to write into the buffer.
1273
+ #
1274
+ # @return [self]
1275
+ #
1276
+ # @see #write_value
1277
+ #
1278
+ # @api public
1279
+ #
1280
+ def write_ulong_long(value)
1281
+ write_value(:ulong_long,value)
1282
+ end
1283
+
1284
+ #
1285
+ # Alias for `write_value(:float32,value)`.
1286
+ #
1287
+ # @param [Float] value
1288
+ # The `float32` value to write into the buffer.
1289
+ #
1290
+ # @return [self]
1291
+ #
1292
+ # @see #write_value
1293
+ #
1294
+ # @api public
1295
+ #
1296
+ def write_float32(value)
1297
+ write_value(:float32,value)
1298
+ end
1299
+
1300
+ #
1301
+ # Alias for `write_value(:float64,value)`.
1302
+ #
1303
+ # @param [Float] value
1304
+ # The `float64` value to write into the buffer.
1305
+ #
1306
+ # @return [self]
1307
+ #
1308
+ # @see #write_value
1309
+ #
1310
+ # @api public
1311
+ #
1312
+ def write_float64(value)
1313
+ write_value(:float64,value)
1314
+ end
1315
+
1316
+ #
1317
+ # Alias for `write_value(:float,value)`.
1318
+ #
1319
+ # @param [Float] value
1320
+ # The `float` value to write into the buffer.
1321
+ #
1322
+ # @return [self]
1323
+ #
1324
+ # @see #write_value
1325
+ #
1326
+ # @api public
1327
+ #
1328
+ def write_float(value)
1329
+ write_value(:float,value)
1330
+ end
1331
+
1332
+ #
1333
+ # Alias for `write_value(:double,value)`.
1334
+ #
1335
+ # @param [Float] value
1336
+ # The `double` value to write into the buffer.
1337
+ #
1338
+ # @return [self]
1339
+ #
1340
+ # @see #write_value
1341
+ #
1342
+ # @api public
1343
+ #
1344
+ def write_double(value)
1345
+ write_value(:double,value)
1346
+ end
1347
+
1348
+ #
1349
+ # Writes an array of the given type.
1350
+ #
1351
+ # @param [Symbol] type
1352
+ # The type of the value to write.
1353
+ #
1354
+ # @param [Array<Object>] array
1355
+ # The array of values to write.
1356
+ #
1357
+ # @return [self]
1358
+ #
1359
+ # @api public
1360
+ #
1361
+ def write_array_of(type,array)
1362
+ type = type_system[type]
1363
+ array_type = type[array.length]
1364
+ data = array_type.pack(array)
1365
+
1366
+ write(data)
1367
+ return self
1368
+ end
1369
+
1370
+ #
1371
+ # Alias to `write_array_of(:byte,bytes)`.
1372
+ #
1373
+ # @param [Array<Integer>] bytes
1374
+ # The array of bytes to write.
1375
+ #
1376
+ # @return [self]
1377
+ #
1378
+ # @see #write_array_of
1379
+ #
1380
+ # @api public
1381
+ #
1382
+ def write_array_of_byte(bytes)
1383
+ write_array_of(:byte,bytes)
1384
+ end
1385
+
1386
+ alias write_bytes write_array_of_byte
1387
+
1388
+ #
1389
+ # Alias to `write_array_of(:char,bytes)`.
1390
+ #
1391
+ # @param [String] chars
1392
+ # The array of characters to write.
1393
+ #
1394
+ # @return [self]
1395
+ #
1396
+ # @see #write_array_of
1397
+ #
1398
+ # @api public
1399
+ #
1400
+ def write_array_of_char(chars)
1401
+ write_array_of(:char,chars)
1402
+ end
1403
+
1404
+ alias write_chars write_array_of_char
1405
+
1406
+ #
1407
+ # Alias to `write_array_of(:uchar,bytes)`.
1408
+ #
1409
+ # @param [String] chars
1410
+ # The array of unsigned characters to write.
1411
+ #
1412
+ # @return [self]
1413
+ #
1414
+ # @see #write_array_of
1415
+ #
1416
+ # @api public
1417
+ #
1418
+ def write_array_of_uchar(chars)
1419
+ write_array_of(:uchar,chars)
1420
+ end
1421
+
1422
+ alias write_uchars write_array_of_uchar
1423
+
1424
+ #
1425
+ # Alias to `write_array_of(:int8,ints)`.
1426
+ #
1427
+ # @param [Array<Integer>] ints
1428
+ # The array of `int8` values to write.
1429
+ #
1430
+ # @return [self]
1431
+ #
1432
+ # @see #write_array_of
1433
+ #
1434
+ # @api public
1435
+ #
1436
+ def write_array_of_int8(ints)
1437
+ write_array_of(:int8,ints)
1438
+ end
1439
+
1440
+ #
1441
+ # Alias to `write_array_of(:int16,ints)`.
1442
+ #
1443
+ # @param [Array<Integer>] ints
1444
+ # The array of `int16` values to write.
1445
+ #
1446
+ # @return [self]
1447
+ #
1448
+ # @see #write_array_of
1449
+ #
1450
+ # @api public
1451
+ #
1452
+ def write_array_of_int16(ints)
1453
+ write_array_of(:int16,ints)
1454
+ end
1455
+
1456
+ #
1457
+ # Alias to `write_array_of(:int32,ints)`.
1458
+ #
1459
+ # @param [Array<Integer>] ints
1460
+ # The array of `int32` values to write.
1461
+ #
1462
+ # @return [self]
1463
+ #
1464
+ # @see #write_array_of
1465
+ #
1466
+ # @api public
1467
+ #
1468
+ def write_array_of_int32(ints)
1469
+ write_array_of(:int32,ints)
1470
+ end
1471
+
1472
+ #
1473
+ # Alias to `write_array_of(:int64,ints)`.
1474
+ #
1475
+ # @param [Array<Integer>] ints
1476
+ # The array of `int64` values to write.
1477
+ #
1478
+ # @return [self]
1479
+ #
1480
+ # @see #write_array_of
1481
+ #
1482
+ # @api public
1483
+ #
1484
+ def write_array_of_int64(ints)
1485
+ write_array_of(:int64,ints)
1486
+ end
1487
+
1488
+ #
1489
+ # Alias to `write_array_of(:uint8,uints)`.
1490
+ #
1491
+ # @param [Array<Integer>] uints
1492
+ # The array of `uint8` values to write.
1493
+ #
1494
+ # @return [self]
1495
+ #
1496
+ # @see #write_array_of
1497
+ #
1498
+ # @api public
1499
+ #
1500
+ def write_array_of_uint8(uints)
1501
+ write_array_of(:uint8,uints)
1502
+ end
1503
+
1504
+ #
1505
+ # Alias to `write_array_of(:uint16,uints)`.
1506
+ #
1507
+ # @param [Array<Integer>] uints
1508
+ # The array of `uint16` values to write.
1509
+ #
1510
+ # @return [self]
1511
+ #
1512
+ # @see #write_array_of
1513
+ #
1514
+ # @api public
1515
+ #
1516
+ def write_array_of_uint16(uints)
1517
+ write_array_of(:uint16,uints)
1518
+ end
1519
+
1520
+ #
1521
+ # Alias to `write_array_of(:uint32,uints)`.
1522
+ #
1523
+ # @param [Array<Integer>] uints
1524
+ # The array of `uint32` values to write.
1525
+ #
1526
+ # @return [self]
1527
+ #
1528
+ # @see #write_array_of
1529
+ #
1530
+ # @api public
1531
+ #
1532
+ def write_array_of_uint32(uints)
1533
+ write_array_of(:uint32,uints)
1534
+ end
1535
+
1536
+ #
1537
+ # Alias to `write_array_of(:uint64,uints)`.
1538
+ #
1539
+ # @param [Array<Integer>] uints
1540
+ # The array of `uint64` values to write.
1541
+ #
1542
+ # @return [self]
1543
+ #
1544
+ # @see #write_array_of
1545
+ #
1546
+ # @api public
1547
+ #
1548
+ def write_array_of_uint64(uints)
1549
+ write_array_of(:uint64,uints)
1550
+ end
1551
+
1552
+ #
1553
+ # Alias to `write_array_of(:short,ints)`.
1554
+ #
1555
+ # @param [Array<Integer>] ints
1556
+ # The array of `short` values to write.
1557
+ #
1558
+ # @return [self]
1559
+ #
1560
+ # @see #write_array_of
1561
+ #
1562
+ # @api public
1563
+ #
1564
+ def write_array_of_short(ints)
1565
+ write_array_of(:short,ints)
1566
+ end
1567
+
1568
+ #
1569
+ # Alias to `write_array_of(:int,ints)`.
1570
+ #
1571
+ # @param [Array<Integer>] ints
1572
+ # The array of `int` values to write.
1573
+ #
1574
+ # @return [self]
1575
+ #
1576
+ # @see #write_array_of
1577
+ #
1578
+ # @api public
1579
+ #
1580
+ def write_array_of_int(ints)
1581
+ write_array_of(:int,ints)
1582
+ end
1583
+
1584
+ alias write_ints write_array_of_int
1585
+
1586
+ #
1587
+ # Alias to `write_array_of(:long,ints)`.
1588
+ #
1589
+ # @param [Array<Integer>] ints
1590
+ # The array of `long` values to write.
1591
+ #
1592
+ # @return [self]
1593
+ #
1594
+ # @see #write_array_of
1595
+ #
1596
+ # @api public
1597
+ #
1598
+ def write_array_of_long(ints)
1599
+ write_array_of(:long,ints)
1600
+ end
1601
+
1602
+ #
1603
+ # Alias to `write_array_of(:long_long,ints)`.
1604
+ #
1605
+ # @param [Array<Integer>] ints
1606
+ # The array of `long_long` values to write.
1607
+ #
1608
+ # @return [self]
1609
+ #
1610
+ # @see #write_array_of
1611
+ #
1612
+ # @api public
1613
+ #
1614
+ def write_array_of_long_long(ints)
1615
+ write_array_of(:long_long,ints)
1616
+ end
1617
+
1618
+ #
1619
+ # Alias to `write_array_of(:ushort,uints)`.
1620
+ #
1621
+ # @param [Array<Integer>] uints
1622
+ # The array of `ushort` values to write.
1623
+ #
1624
+ # @return [self]
1625
+ #
1626
+ # @see #write_array_of
1627
+ #
1628
+ # @api public
1629
+ #
1630
+ def write_array_of_ushort(uints)
1631
+ write_array_of(:ushort,uints)
1632
+ end
1633
+
1634
+ #
1635
+ # Alias to `write_array_of(:uint,uints)`.
1636
+ #
1637
+ # @param [Array<Integer>] uints
1638
+ # The array of `uint` values to write.
1639
+ #
1640
+ # @return [self]
1641
+ #
1642
+ # @see #write_array_of
1643
+ #
1644
+ # @api public
1645
+ #
1646
+ def write_array_of_uint(uints)
1647
+ write_array_of(:uint,uints)
1648
+ end
1649
+
1650
+ alias write_uints write_array_of_uint
1651
+
1652
+ #
1653
+ # Alias to `write_array_of(:ulong,uints)`.
1654
+ #
1655
+ # @param [Array<Integer>] uints
1656
+ # The array of `ulong` values to write.
1657
+ #
1658
+ # @return [self]
1659
+ #
1660
+ # @see #write_array_of
1661
+ #
1662
+ # @api public
1663
+ #
1664
+ def write_array_of_ulong(uints)
1665
+ write_array_of(:ulong,uints)
1666
+ end
1667
+
1668
+ #
1669
+ # Alias to `write_array_of(:ulong_long,uints)`.
1670
+ #
1671
+ # @param [Array<Integer>] uints
1672
+ # The array of `ulong_long` values to write.
1673
+ #
1674
+ # @return [self]
1675
+ #
1676
+ # @see #write_array_of
1677
+ #
1678
+ # @api public
1679
+ #
1680
+ def write_array_of_ulong_long(uints)
1681
+ write_array_of(:ulong_long,uints)
1682
+ end
1683
+
1684
+ #
1685
+ # Alias to `write_array_of(:float32,floats)`.
1686
+ #
1687
+ # @param [Array<Float>] floats
1688
+ # The array of `float32` values to write.
1689
+ #
1690
+ # @return [self]
1691
+ #
1692
+ # @see #write_array_of
1693
+ #
1694
+ # @api public
1695
+ #
1696
+ def write_array_of_float32(floats)
1697
+ write_array_of(:float32,floats)
1698
+ end
1699
+
1700
+ #
1701
+ # Alias to `write_array_of(:float64,floats)`.
1702
+ #
1703
+ # @param [Array<Float>] floats
1704
+ # The array of `float64` values to write.
1705
+ #
1706
+ # @return [self]
1707
+ #
1708
+ # @see #write_array_of
1709
+ #
1710
+ # @api public
1711
+ #
1712
+ def write_array_of_float64(floats)
1713
+ write_array_of(:float64,floats)
1714
+ end
1715
+
1716
+ #
1717
+ # Alias to `write_array_of(:float,floats)`.
1718
+ #
1719
+ # @param [Array<Float>] floats
1720
+ # The array of `float` values to write.
1721
+ #
1722
+ # @return [self]
1723
+ #
1724
+ # @see #write_array_of
1725
+ #
1726
+ # @api public
1727
+ #
1728
+ def write_array_of_float(floats)
1729
+ write_array_of(:float,floats)
1730
+ end
1731
+
1732
+ alias write_floats write_array_of_float
1733
+
1734
+ #
1735
+ # Alias to `write_array_of(:double,floats)`.
1736
+ #
1737
+ # @param [Array<Float>] floats
1738
+ # The array of `double` values to write.
1739
+ #
1740
+ # @return [self]
1741
+ #
1742
+ # @see #write_array_of
1743
+ #
1744
+ # @api public
1745
+ #
1746
+ def write_array_of_double(floats)
1747
+ write_array_of(:double,floats)
1748
+ end
1749
+
1750
+ alias write_doubles write_array_of_double
1751
+ end
1752
+ end
1753
+ end
1754
+ end
1755
+ end