ronin-support 0.5.2 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -6
- data/.gitignore +7 -6
- data/.mailmap +1 -0
- data/.ruby-version +1 -1
- data/.yardopts +0 -1
- data/ChangeLog.md +518 -148
- data/Gemfile +17 -16
- data/README.md +107 -52
- data/Rakefile +28 -8
- data/data/text/homoglyphs/ascii.txt +8 -0
- data/data/text/homoglyphs/cyrillic.txt +33 -0
- data/data/text/homoglyphs/full_width.txt +81 -0
- data/data/text/homoglyphs/greek.txt +21 -0
- data/data/text/homoglyphs/latin_numbers.txt +14 -0
- data/data/text/homoglyphs/punctuation.txt +7 -0
- data/data/text/patterns/network/public_suffix.rb.erb +44 -0
- data/examples/ssl_proxy.rb +38 -0
- data/examples/tcp_proxy.rb +41 -0
- data/gemspec.yml +16 -15
- data/lib/ronin/support/archive/core_ext/file.rb +118 -0
- data/lib/ronin/{formatting/sql.rb → support/archive/core_ext.rb} +3 -4
- data/lib/ronin/support/archive/mixin.rb +213 -0
- data/lib/ronin/support/archive/tar/reader.rb +135 -0
- data/lib/ronin/support/archive/tar/writer.rb +197 -0
- data/lib/ronin/support/archive/tar.rb +155 -0
- data/lib/ronin/support/archive/zip/reader/entry.rb +134 -0
- data/lib/ronin/support/archive/zip/reader/statistics.rb +76 -0
- data/lib/ronin/support/archive/zip/reader.rb +273 -0
- data/lib/ronin/support/archive/zip/writer.rb +175 -0
- data/lib/ronin/support/archive/zip.rb +105 -0
- data/lib/ronin/support/archive.rb +211 -0
- data/lib/ronin/support/binary/array.rb +255 -0
- data/lib/ronin/support/binary/bit_flip.rb +147 -0
- data/lib/ronin/support/binary/buffer.rb +2027 -0
- data/lib/ronin/support/binary/byte_slice.rb +324 -0
- data/lib/ronin/{formatting/extensions/binary → support/binary/core_ext}/array.rb +25 -11
- data/lib/ronin/support/binary/core_ext/float.rb +80 -0
- data/lib/ronin/support/binary/core_ext/integer.rb +305 -0
- data/lib/ronin/support/binary/core_ext/io.rb +38 -0
- data/lib/ronin/support/binary/core_ext/string.rb +162 -0
- data/lib/ronin/{formatting/extensions/text.rb → support/binary/core_ext.rb} +6 -6
- data/lib/ronin/support/binary/cstring.rb +259 -0
- data/lib/ronin/support/binary/ctypes/aggregate_type.rb +98 -0
- data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +77 -0
- data/lib/ronin/support/binary/ctypes/arch/arm.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +77 -0
- data/lib/ronin/support/binary/ctypes/arch/arm64.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +77 -0
- data/lib/ronin/support/binary/ctypes/arch/mips.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +77 -0
- data/lib/ronin/support/binary/ctypes/arch/mips64.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch/ppc.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch/x86.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +75 -0
- data/lib/ronin/support/binary/ctypes/arch.rb +30 -0
- data/lib/ronin/support/binary/ctypes/array_object_type.rb +164 -0
- data/lib/ronin/support/binary/ctypes/array_type.rb +232 -0
- data/lib/ronin/support/binary/ctypes/big_endian.rb +195 -0
- data/lib/ronin/support/binary/ctypes/char_type.rb +59 -0
- data/lib/ronin/support/binary/ctypes/char_types.rb +39 -0
- data/lib/ronin/support/binary/ctypes/enum_type.rb +181 -0
- data/lib/ronin/support/binary/ctypes/float32_type.rb +50 -0
- data/lib/ronin/support/binary/ctypes/float64_type.rb +50 -0
- data/lib/ronin/support/binary/ctypes/float_type.rb +62 -0
- data/lib/ronin/support/binary/ctypes/int16_type.rb +50 -0
- data/lib/ronin/support/binary/ctypes/int32_type.rb +50 -0
- data/lib/ronin/support/binary/ctypes/int64_type.rb +50 -0
- data/lib/ronin/support/{support.rb → binary/ctypes/int8_type.rb} +20 -21
- data/lib/ronin/support/binary/ctypes/int_type.rb +62 -0
- data/lib/ronin/support/binary/ctypes/little_endian.rb +195 -0
- data/lib/ronin/support/binary/ctypes/mixin.rb +135 -0
- data/lib/ronin/support/binary/ctypes/native.rb +205 -0
- data/lib/ronin/support/binary/ctypes/network.rb +29 -0
- data/lib/ronin/support/binary/ctypes/object_type.rb +55 -0
- data/lib/ronin/support/binary/ctypes/os/bsd.rb +65 -0
- data/lib/ronin/support/binary/ctypes/os/freebsd.rb +215 -0
- data/lib/ronin/support/binary/ctypes/os/linux.rb +193 -0
- data/lib/ronin/support/binary/ctypes/os/macos.rb +151 -0
- data/lib/ronin/support/binary/ctypes/os/netbsd.rb +147 -0
- data/lib/ronin/support/binary/ctypes/os/openbsd.rb +168 -0
- data/lib/ronin/support/binary/ctypes/os/unix.rb +78 -0
- data/lib/ronin/support/binary/ctypes/os/windows.rb +125 -0
- data/lib/ronin/support/binary/ctypes/os.rb +125 -0
- data/lib/ronin/support/binary/ctypes/scalar_type.rb +200 -0
- data/lib/ronin/support/binary/ctypes/string_type.rb +143 -0
- data/lib/ronin/support/binary/ctypes/struct_object_type.rb +173 -0
- data/lib/ronin/support/binary/ctypes/struct_type.rb +359 -0
- data/lib/ronin/support/binary/ctypes/type.rb +193 -0
- data/lib/ronin/support/binary/ctypes/type_resolver.rb +206 -0
- data/lib/ronin/support/binary/ctypes/uint16_type.rb +50 -0
- data/lib/ronin/support/binary/ctypes/uint32_type.rb +50 -0
- data/lib/ronin/support/binary/ctypes/uint64_type.rb +50 -0
- data/lib/ronin/support/binary/ctypes/uint8_type.rb +41 -0
- data/lib/ronin/support/binary/ctypes/uint_type.rb +59 -0
- data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +258 -0
- data/lib/ronin/support/binary/ctypes/union_object_type.rb +173 -0
- data/lib/ronin/support/binary/ctypes/union_type.rb +261 -0
- data/lib/ronin/support/binary/ctypes.rb +462 -0
- data/lib/ronin/support/binary/hexdump/core_ext/file.rb +118 -0
- data/lib/ronin/support/binary/hexdump/core_ext/string.rb +115 -0
- data/lib/ronin/support/binary/hexdump/core_ext.rb +20 -0
- data/lib/ronin/support/binary/hexdump/parser.rb +492 -0
- data/lib/ronin/support/binary/hexdump.rb +20 -0
- data/lib/ronin/support/binary/memory.rb +268 -0
- data/lib/ronin/support/binary/packet.rb +33 -0
- data/lib/ronin/support/binary/stack.rb +256 -0
- data/lib/ronin/support/binary/stream/methods.rb +1755 -0
- data/lib/ronin/support/binary/stream.rb +151 -0
- data/lib/ronin/support/binary/struct/member.rb +86 -0
- data/lib/ronin/support/binary/struct.rb +830 -0
- data/lib/ronin/support/binary/template.rb +284 -0
- data/lib/ronin/support/binary/union.rb +162 -0
- data/lib/ronin/{formatting/extensions → support}/binary.rb +10 -10
- data/lib/ronin/support/cli/ansi.rb +330 -0
- data/lib/ronin/support/cli/io_shell/core_ext/io.rb +67 -0
- data/lib/ronin/{extensions/meta.rb → support/cli/io_shell/core_ext.rb} +3 -4
- data/lib/ronin/support/cli/io_shell.rb +161 -0
- data/lib/ronin/support/cli/printing.rb +216 -0
- data/lib/ronin/support/cli.rb +20 -0
- data/lib/ronin/support/compression/core_ext/file.rb +70 -0
- data/lib/ronin/support/compression/core_ext/string.rb +101 -0
- data/lib/ronin/{fuzzing/extensions.rb → support/compression/core_ext.rb} +3 -4
- data/lib/ronin/support/compression/gzip/reader.rb +70 -0
- data/lib/ronin/support/compression/gzip/writer.rb +74 -0
- data/lib/ronin/support/compression/gzip.rb +105 -0
- data/lib/ronin/support/compression/mixin.rb +180 -0
- data/lib/ronin/{network/extensions/esmtp/net.rb → support/compression/zlib.rb} +6 -7
- data/lib/ronin/support/compression.rb +174 -0
- data/lib/ronin/{extensions → support/core_ext}/enumerable.rb +2 -3
- data/lib/ronin/{extensions → support/core_ext}/file.rb +2 -31
- data/lib/ronin/support/core_ext/integer.rb +37 -0
- data/lib/ronin/support/core_ext/ipaddr.rb +65 -0
- data/lib/ronin/{extensions → support/core_ext}/kernel.rb +7 -6
- data/lib/ronin/{extensions → support/core_ext}/resolv.rb +2 -25
- data/lib/ronin/{extensions → support/core_ext}/string.rb +114 -54
- data/lib/ronin/support/core_ext.rb +34 -0
- data/lib/ronin/support/crypto/cert.rb +522 -0
- data/lib/ronin/support/crypto/cert_chain.rb +204 -0
- data/lib/ronin/support/crypto/cipher/aes.rb +71 -0
- data/lib/ronin/support/crypto/cipher/aes128.rb +54 -0
- data/lib/ronin/support/crypto/cipher/aes256.rb +54 -0
- data/lib/ronin/support/crypto/cipher.rb +194 -0
- data/lib/ronin/support/crypto/core_ext/file.rb +660 -0
- data/lib/ronin/support/crypto/core_ext/string.rb +548 -0
- data/lib/ronin/{binary.rb → support/crypto/core_ext.rb} +4 -5
- data/lib/ronin/{network/mixins/mixin.rb → support/crypto/hmac.rb} +18 -28
- data/lib/ronin/support/crypto/key/dh.rb +122 -0
- data/lib/ronin/support/crypto/key/dsa.rb +103 -0
- data/lib/ronin/support/crypto/key/ec.rb +99 -0
- data/lib/ronin/support/crypto/key/methods.rb +163 -0
- data/lib/ronin/support/crypto/key/rsa.rb +169 -0
- data/lib/ronin/support/crypto/key.rb +105 -0
- data/lib/ronin/support/crypto/mixin.rb +620 -0
- data/lib/ronin/{network/extensions/http/net.rb → support/crypto/openssl.rb} +6 -7
- data/lib/ronin/support/crypto.rb +779 -0
- data/lib/ronin/support/encoding/base16/core_ext/string.rb +63 -0
- data/lib/ronin/{formatting/binary.rb → support/encoding/base16/core_ext.rb} +3 -4
- data/lib/ronin/support/encoding/base16.rb +82 -0
- data/lib/ronin/support/encoding/base32/core_ext/string.rb +63 -0
- data/lib/ronin/support/encoding/base32/core_ext.rb +19 -0
- data/lib/ronin/support/encoding/base32.rb +164 -0
- data/lib/ronin/support/encoding/base64/core_ext/string.rb +76 -0
- data/lib/ronin/support/encoding/base64/core_ext.rb +19 -0
- data/lib/ronin/support/encoding/base64.rb +78 -0
- data/lib/ronin/support/encoding/c/core_ext/integer.rb +82 -0
- data/lib/ronin/support/encoding/c/core_ext/string.rb +125 -0
- data/lib/ronin/support/encoding/c/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/c.rb +277 -0
- data/lib/ronin/support/encoding/core_ext/string.rb +107 -0
- data/lib/ronin/support/encoding/core_ext.rb +33 -0
- data/lib/ronin/support/encoding/hex/core_ext/integer.rb +82 -0
- data/lib/ronin/support/encoding/hex/core_ext/string.rb +133 -0
- data/lib/ronin/support/encoding/hex/core_ext.rb +22 -0
- data/lib/ronin/support/encoding/hex.rb +248 -0
- data/lib/ronin/support/encoding/html/core_ext/integer.rb +106 -0
- data/lib/ronin/support/encoding/html/core_ext/string.rb +130 -0
- data/lib/ronin/support/encoding/html/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/html.rb +233 -0
- data/lib/ronin/support/encoding/http/core_ext/integer.rb +95 -0
- data/lib/ronin/support/encoding/http/core_ext/string.rb +129 -0
- data/lib/ronin/support/encoding/http/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/http.rb +241 -0
- data/lib/ronin/support/encoding/js/core_ext/integer.rb +67 -0
- data/lib/ronin/support/encoding/js/core_ext/string.rb +125 -0
- data/lib/ronin/support/encoding/js/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/js.rb +279 -0
- data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +87 -0
- data/lib/ronin/support/encoding/powershell/core_ext/string.rb +145 -0
- data/lib/ronin/support/encoding/powershell/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/powershell.rb +297 -0
- data/lib/ronin/{formatting/extensions/http/integer.rb → support/encoding/punycode/core_ext/string.rb} +23 -29
- data/lib/ronin/support/encoding/punycode/core_ext.rb +19 -0
- data/lib/ronin/support/encoding/punycode.rb +76 -0
- data/lib/ronin/support/encoding/quoted_printable/core_ext/string.rb +75 -0
- data/lib/ronin/support/encoding/quoted_printable/core_ext.rb +19 -0
- data/lib/ronin/support/encoding/quoted_printable.rb +102 -0
- data/lib/ronin/support/encoding/ruby/core_ext/string.rb +129 -0
- data/lib/ronin/support/encoding/ruby/core_ext.rb +19 -0
- data/lib/ronin/support/encoding/ruby.rb +235 -0
- data/lib/ronin/support/encoding/shell/core_ext/integer.rb +89 -0
- data/lib/ronin/support/encoding/shell/core_ext/string.rb +134 -0
- data/lib/ronin/support/encoding/shell/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/shell.rb +293 -0
- data/lib/ronin/{network/extensions → support/encoding}/smtp.rb +4 -4
- data/lib/ronin/support/encoding/sql/core_ext/string.rb +114 -0
- data/lib/ronin/{formatting/html.rb → support/encoding/sql/core_ext.rb} +3 -4
- data/lib/ronin/support/encoding/sql.rb +124 -0
- data/lib/ronin/support/encoding/uri/core_ext/integer.rb +149 -0
- data/lib/ronin/support/encoding/uri/core_ext/string.rb +195 -0
- data/lib/ronin/support/encoding/uri/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/uri.rb +424 -0
- data/lib/ronin/support/encoding/uuencoding/core_ext/string.rb +73 -0
- data/lib/ronin/support/encoding/uuencoding/core_ext.rb +19 -0
- data/lib/ronin/support/encoding/uuencoding.rb +70 -0
- data/lib/ronin/support/encoding/xml/core_ext/integer.rb +100 -0
- data/lib/ronin/support/encoding/xml/core_ext/string.rb +124 -0
- data/lib/ronin/support/encoding/xml/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/xml.rb +328 -0
- data/lib/ronin/support/encoding.rb +46 -0
- data/lib/ronin/support/home.rb +88 -0
- data/lib/ronin/{network/network.rb → support/mixin.rb} +17 -20
- data/lib/ronin/support/network/asn/dns_record.rb +112 -0
- data/lib/ronin/support/network/asn/list.rb +269 -0
- data/lib/ronin/support/network/asn/record.rb +164 -0
- data/lib/ronin/support/network/asn/record_set.rb +226 -0
- data/lib/ronin/support/network/asn.rb +88 -0
- data/lib/ronin/{binary/hexdump.rb → support/network/core_ext.rb} +3 -4
- data/lib/ronin/support/network/dns/idn.rb +38 -0
- data/lib/ronin/support/network/dns/mixin.rb +941 -0
- data/lib/ronin/support/network/dns/resolver.rb +707 -0
- data/lib/ronin/support/network/dns.rb +1109 -0
- data/lib/ronin/support/network/domain.rb +70 -0
- data/lib/ronin/support/network/email_address.rb +574 -0
- data/lib/ronin/support/network/esmtp/mixin.rb +115 -0
- data/lib/ronin/support/network/exceptions.rb +43 -0
- data/lib/ronin/support/network/ftp/mixin.rb +106 -0
- data/lib/ronin/support/network/host.rb +1473 -0
- data/lib/ronin/support/network/http/cookie.rb +245 -0
- data/lib/ronin/support/network/http/core_ext/uri/http.rb +63 -0
- data/lib/ronin/support/network/http/core_ext.rb +19 -0
- data/lib/ronin/support/network/http/mixin.rb +890 -0
- data/lib/ronin/support/network/http/request.rb +215 -0
- data/lib/ronin/support/network/http/set_cookie.rb +210 -0
- data/lib/ronin/support/network/http/user_agents.rb +115 -0
- data/lib/ronin/support/network/http.rb +2582 -0
- data/lib/ronin/support/network/imap/mixin.rb +133 -0
- data/lib/ronin/support/network/ip/mixin.rb +114 -0
- data/lib/ronin/support/network/ip.rb +540 -0
- data/lib/ronin/support/network/ip_range/cidr.rb +252 -0
- data/lib/ronin/support/network/ip_range/glob.rb +309 -0
- data/lib/ronin/support/network/ip_range/range.rb +249 -0
- data/lib/ronin/support/network/ip_range.rb +284 -0
- data/lib/ronin/support/network/mixin.rb +58 -0
- data/lib/ronin/support/network/packet.rb +27 -0
- data/lib/ronin/support/network/pop3/mixin.rb +113 -0
- data/lib/ronin/support/network/proxy.rb +602 -0
- data/lib/ronin/support/network/public_suffix/list.rb +339 -0
- data/lib/ronin/support/network/public_suffix/suffix.rb +118 -0
- data/lib/ronin/support/network/public_suffix/suffix_set.rb +150 -0
- data/lib/ronin/support/network/public_suffix.rb +41 -0
- data/lib/ronin/support/network/smtp/email.rb +190 -0
- data/lib/ronin/support/network/smtp/mixin.rb +290 -0
- data/lib/ronin/support/network/smtp.rb +19 -0
- data/lib/ronin/support/network/ssl/local_cert.rb +114 -0
- data/lib/ronin/support/network/ssl/local_key.rb +84 -0
- data/lib/ronin/support/network/ssl/mixin.rb +740 -0
- data/lib/ronin/{network/extensions/imap/net.rb → support/network/ssl/openssl.rb} +6 -7
- data/lib/ronin/support/network/ssl/proxy.rb +296 -0
- data/lib/ronin/support/network/ssl.rb +173 -0
- data/lib/ronin/support/network/tcp/mixin.rb +400 -0
- data/lib/ronin/support/network/tcp/proxy.rb +435 -0
- data/lib/ronin/support/network/tcp.rb +443 -0
- data/lib/ronin/support/network/telnet/mixin.rb +150 -0
- data/lib/ronin/support/network/telnet.rb +90 -0
- data/lib/ronin/support/network/tld/list.rb +266 -0
- data/lib/ronin/support/network/tld.rb +41 -0
- data/lib/ronin/support/network/tls/mixin.rb +670 -0
- data/lib/ronin/support/network/tls/proxy.rb +135 -0
- data/lib/ronin/{network/mixins/dns.rb → support/network/tls.rb} +23 -25
- data/lib/ronin/support/network/udp/mixin.rb +389 -0
- data/lib/ronin/support/network/udp/proxy.rb +192 -0
- data/lib/ronin/support/network/udp.rb +435 -0
- data/lib/ronin/support/network/unix/mixin.rb +273 -0
- data/lib/ronin/support/network.rb +37 -0
- data/lib/ronin/support/path.rb +136 -0
- data/lib/ronin/{network/extensions/dns/net.rb → support/text/core_ext/regexp.rb} +5 -6
- data/lib/ronin/support/text/core_ext/string.rb +46 -0
- data/lib/ronin/{formatting.rb → support/text/core_ext.rb} +7 -9
- data/lib/ronin/support/text/entropy/core_ext/string.rb +45 -0
- data/lib/ronin/{formatting/http.rb → support/text/entropy/core_ext.rb} +3 -4
- data/lib/ronin/support/text/entropy.rb +66 -0
- data/lib/ronin/support/text/erb/mixin.rb +44 -0
- data/lib/ronin/support/text/erb.rb +19 -0
- data/lib/ronin/support/text/homoglyph/core_ext/string.rb +108 -0
- data/lib/ronin/{formatting/digest.rb → support/text/homoglyph/core_ext.rb} +3 -4
- data/lib/ronin/{network/http/exceptions/unknown_request.rb → support/text/homoglyph/exceptions.rb} +7 -6
- data/lib/ronin/support/text/homoglyph/table.rb +228 -0
- data/lib/ronin/support/text/homoglyph.rb +142 -0
- data/lib/ronin/support/text/mixin.rb +31 -0
- data/lib/ronin/support/text/patterns/credentials.rb +75 -0
- data/lib/ronin/support/text/patterns/crypto.rb +67 -0
- data/lib/ronin/support/text/patterns/file_system.rb +93 -0
- data/lib/ronin/support/text/patterns/language.rb +37 -0
- data/lib/ronin/support/text/patterns/network/public_suffix.rb +44 -0
- data/lib/ronin/support/text/patterns/network.rb +140 -0
- data/lib/ronin/support/text/patterns/numeric.rb +52 -0
- data/lib/ronin/support/text/patterns/pii.rb +105 -0
- data/lib/ronin/support/text/patterns/source_code.rb +148 -0
- data/lib/ronin/{extensions.rb → support/text/patterns.rb} +10 -13
- data/lib/ronin/support/text/random/mixin.rb +437 -0
- data/lib/ronin/support/text/random.rb +419 -0
- data/lib/ronin/support/text/typo/core_ext/string.rb +123 -0
- data/lib/ronin/support/text/typo/core_ext.rb +19 -0
- data/lib/ronin/support/text/typo/exceptions.rb +28 -0
- data/lib/ronin/support/text/typo/generator.rb +161 -0
- data/lib/ronin/support/text/typo.rb +260 -0
- data/lib/ronin/{formatting → support}/text.rb +10 -4
- data/lib/ronin/support/version.rb +3 -4
- data/lib/ronin/support.rb +17 -12
- data/ronin-support.gemspec +2 -1
- metadata +342 -291
- data/lib/ronin/binary/hexdump/parser.rb +0 -403
- data/lib/ronin/binary/struct.rb +0 -567
- data/lib/ronin/binary/template.rb +0 -454
- data/lib/ronin/extensions/ip_addr.rb +0 -216
- data/lib/ronin/extensions/meta/object.rb +0 -24
- data/lib/ronin/extensions/regexp.rb +0 -157
- data/lib/ronin/formatting/extensions/binary/base64.rb +0 -106
- data/lib/ronin/formatting/extensions/binary/file.rb +0 -77
- data/lib/ronin/formatting/extensions/binary/float.rb +0 -65
- data/lib/ronin/formatting/extensions/binary/integer.rb +0 -180
- data/lib/ronin/formatting/extensions/binary/string.rb +0 -345
- data/lib/ronin/formatting/extensions/digest/file.rb +0 -129
- data/lib/ronin/formatting/extensions/digest/string.rb +0 -86
- data/lib/ronin/formatting/extensions/digest.rb +0 -21
- data/lib/ronin/formatting/extensions/html/integer.rb +0 -142
- data/lib/ronin/formatting/extensions/html/string.rb +0 -194
- data/lib/ronin/formatting/extensions/html.rb +0 -21
- data/lib/ronin/formatting/extensions/http/string.rb +0 -110
- data/lib/ronin/formatting/extensions/http.rb +0 -21
- data/lib/ronin/formatting/extensions/sql/string.rb +0 -130
- data/lib/ronin/formatting/extensions/sql.rb +0 -20
- data/lib/ronin/formatting/extensions/text/array.rb +0 -137
- data/lib/ronin/formatting/extensions/text/string.rb +0 -297
- data/lib/ronin/formatting/extensions.rb +0 -24
- data/lib/ronin/fuzzing/extensions/string.rb +0 -209
- data/lib/ronin/fuzzing/fuzzer.rb +0 -110
- data/lib/ronin/fuzzing/fuzzing.rb +0 -360
- data/lib/ronin/fuzzing/mutator.rb +0 -161
- data/lib/ronin/fuzzing/repeater.rb +0 -81
- data/lib/ronin/fuzzing/template.rb +0 -133
- data/lib/ronin/fuzzing.rb +0 -21
- data/lib/ronin/mixin.rb +0 -89
- data/lib/ronin/network/dns.rb +0 -201
- data/lib/ronin/network/esmtp.rb +0 -113
- data/lib/ronin/network/extensions/dns.rb +0 -20
- data/lib/ronin/network/extensions/esmtp.rb +0 -20
- data/lib/ronin/network/extensions/http/uri/http.rb +0 -228
- data/lib/ronin/network/extensions/http.rb +0 -21
- data/lib/ronin/network/extensions/imap.rb +0 -20
- data/lib/ronin/network/extensions/pop3/net.rb +0 -24
- data/lib/ronin/network/extensions/pop3.rb +0 -20
- data/lib/ronin/network/extensions/smtp/net.rb +0 -24
- data/lib/ronin/network/extensions/ssl/net.rb +0 -24
- data/lib/ronin/network/extensions/ssl.rb +0 -20
- data/lib/ronin/network/extensions/tcp/net.rb +0 -24
- data/lib/ronin/network/extensions/tcp.rb +0 -20
- data/lib/ronin/network/extensions/telnet/net.rb +0 -24
- data/lib/ronin/network/extensions/telnet.rb +0 -20
- data/lib/ronin/network/extensions/udp/net.rb +0 -24
- data/lib/ronin/network/extensions/udp.rb +0 -20
- data/lib/ronin/network/extensions.rb +0 -29
- data/lib/ronin/network/ftp.rb +0 -149
- data/lib/ronin/network/http/exceptions.rb +0 -20
- data/lib/ronin/network/http/http.rb +0 -1122
- data/lib/ronin/network/http/proxy.rb +0 -330
- data/lib/ronin/network/http.rb +0 -22
- data/lib/ronin/network/imap.rb +0 -158
- data/lib/ronin/network/mixins/esmtp.rb +0 -164
- data/lib/ronin/network/mixins/ftp.rb +0 -155
- data/lib/ronin/network/mixins/http.rb +0 -227
- data/lib/ronin/network/mixins/imap.rb +0 -156
- data/lib/ronin/network/mixins/pop3.rb +0 -149
- data/lib/ronin/network/mixins/smtp.rb +0 -159
- data/lib/ronin/network/mixins/ssl.rb +0 -148
- data/lib/ronin/network/mixins/tcp.rb +0 -368
- data/lib/ronin/network/mixins/telnet.rb +0 -208
- data/lib/ronin/network/mixins/udp.rb +0 -381
- data/lib/ronin/network/mixins/unix.rb +0 -279
- data/lib/ronin/network/mixins.rb +0 -29
- data/lib/ronin/network/pop3.rb +0 -124
- data/lib/ronin/network/proxy.rb +0 -578
- data/lib/ronin/network/smtp/email.rb +0 -174
- data/lib/ronin/network/smtp/smtp.rb +0 -230
- data/lib/ronin/network/smtp.rb +0 -22
- data/lib/ronin/network/ssl.rb +0 -186
- data/lib/ronin/network/tcp/proxy.rb +0 -417
- data/lib/ronin/network/tcp/tcp.rb +0 -452
- data/lib/ronin/network/tcp.rb +0 -21
- data/lib/ronin/network/telnet.rb +0 -266
- data/lib/ronin/network/udp/proxy.rb +0 -191
- data/lib/ronin/network/udp/udp.rb +0 -452
- data/lib/ronin/network/udp.rb +0 -21
- data/lib/ronin/network/unix.rb +0 -286
- data/lib/ronin/network.rb +0 -31
- data/lib/ronin/path.rb +0 -133
- data/lib/ronin/spec/ui/output.rb +0 -22
- data/lib/ronin/support/inflector.rb +0 -92
- data/lib/ronin/templates/erb.rb +0 -78
- data/lib/ronin/templates/template.rb +0 -169
- data/lib/ronin/templates.rb +0 -21
- data/lib/ronin/ui/output/helpers.rb +0 -296
- data/lib/ronin/ui/output/output.rb +0 -142
- data/lib/ronin/ui/output/terminal/color.rb +0 -124
- data/lib/ronin/ui/output/terminal/raw.rb +0 -103
- data/lib/ronin/ui/output/terminal.rb +0 -21
- data/lib/ronin/ui/output.rb +0 -21
- data/lib/ronin/ui/shell.rb +0 -286
- data/lib/ronin/wordlist.rb +0 -287
- data/spec/binary/hexdump/helpers/hexdumps/ascii.bin +0 -0
- data/spec/binary/hexdump/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/hexdump_hex_bytes.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/hexdump_hex_shorts.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/hexdump_octal_bytes.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/hexdump_octal_shorts.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/hexdump_repeated.txt +0 -6
- data/spec/binary/hexdump/helpers/hexdumps/od_decimal_bytes.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_decimal_ints.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_decimal_quads.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_decimal_shorts.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_hex_bytes.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_hex_ints.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_hex_quads.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_hex_shorts.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_octal_bytes.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_octal_ints.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_octal_quads.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_octal_shorts.txt +0 -17
- data/spec/binary/hexdump/helpers/hexdumps/od_repeated.txt +0 -6
- data/spec/binary/hexdump/helpers/hexdumps/repeated.bin +0 -1
- data/spec/binary/hexdump/helpers/hexdumps.rb +0 -13
- data/spec/binary/hexdump/parser_spec.rb +0 -302
- data/spec/binary/struct_spec.rb +0 -496
- data/spec/binary/template_spec.rb +0 -416
- data/spec/extensions/enumerable_spec.rb +0 -24
- data/spec/extensions/file_spec.rb +0 -61
- data/spec/extensions/ip_addr_spec.rb +0 -203
- data/spec/extensions/kernel_spec.rb +0 -30
- data/spec/extensions/regexp_spec.rb +0 -482
- data/spec/extensions/resolv_spec.rb +0 -18
- data/spec/extensions/string_spec.rb +0 -180
- data/spec/formatting/binary/array_spec.rb +0 -26
- data/spec/formatting/binary/base64_spec.rb +0 -50
- data/spec/formatting/binary/float_spec.rb +0 -36
- data/spec/formatting/binary/integer_spec.rb +0 -166
- data/spec/formatting/binary/string_spec.rb +0 -199
- data/spec/formatting/digest/string_spec.rb +0 -82
- data/spec/formatting/html/integer_spec.rb +0 -66
- data/spec/formatting/html/string_spec.rb +0 -103
- data/spec/formatting/http/integer_spec.rb +0 -42
- data/spec/formatting/http/string_spec.rb +0 -76
- data/spec/formatting/sql/string_spec.rb +0 -77
- data/spec/formatting/text/array_spec.rb +0 -105
- data/spec/formatting/text/string_spec.rb +0 -162
- data/spec/fuzzing/extensions/string_spec.rb +0 -87
- data/spec/fuzzing/fuzzer_spec.rb +0 -109
- data/spec/fuzzing/fuzzing_spec.rb +0 -24
- data/spec/fuzzing/mutator_spec.rb +0 -112
- data/spec/fuzzing/repeater_spec.rb +0 -57
- data/spec/fuzzing/template_spec.rb +0 -54
- data/spec/mixin_spec.rb +0 -51
- data/spec/network/dns_spec.rb +0 -203
- data/spec/network/ftp_spec.rb +0 -81
- data/spec/network/http/http_spec.rb +0 -559
- data/spec/network/http/proxy_spec.rb +0 -148
- data/spec/network/network_spec.rb +0 -8
- data/spec/network/proxy_spec.rb +0 -121
- data/spec/network/shared/unix_server.rb +0 -31
- data/spec/network/smtp/email_spec.rb +0 -100
- data/spec/network/ssl_spec.rb +0 -70
- data/spec/network/tcp/proxy_spec.rb +0 -118
- data/spec/network/tcp/tcp_spec.rb +0 -316
- data/spec/network/telnet_spec.rb +0 -67
- data/spec/network/udp/udp_spec.rb +0 -298
- data/spec/network/unix_spec.rb +0 -182
- data/spec/path_spec.rb +0 -111
- data/spec/spec_helper.rb +0 -8
- data/spec/support/inflector_spec.rb +0 -22
- data/spec/support_spec.rb +0 -8
- data/spec/templates/classes/example_erb.rb +0 -11
- data/spec/templates/classes/example_template.rb +0 -35
- data/spec/templates/erb_spec.rb +0 -21
- data/spec/templates/helpers/data/includes/_relative.erb +0 -1
- data/spec/templates/helpers/data/templates/example.erb +0 -1
- data/spec/templates/helpers/data.rb +0 -9
- data/spec/templates/template_spec.rb +0 -54
- data/spec/ui/classes/test_shell.rb +0 -22
- data/spec/ui/output_spec.rb +0 -32
- data/spec/ui/shell_spec.rb +0 -83
- data/spec/wordlist_spec.rb +0 -151
@@ -0,0 +1,2027 @@
|
|
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/memory'
|
20
|
+
require 'ronin/support/binary/byte_slice'
|
21
|
+
require 'ronin/support/binary/ctypes/mixin'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Support
|
25
|
+
module Binary
|
26
|
+
#
|
27
|
+
# Represents a binary buffer of data.
|
28
|
+
#
|
29
|
+
# ## Examples
|
30
|
+
#
|
31
|
+
# Writing bytes into an empty buffer:
|
32
|
+
#
|
33
|
+
# buffer = Buffer.new(10)
|
34
|
+
# # => #<Ronin::Support::Binary::Buffer: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00">
|
35
|
+
# buffer[0] = 0x41
|
36
|
+
# buffer[1] = 0x42
|
37
|
+
# buffer[2] = 0x43
|
38
|
+
# buffer.to_s
|
39
|
+
# # => "ABC\x00\x00\x00\x00\x00\x00\x00"
|
40
|
+
#
|
41
|
+
# Writing different types of data to a buffer:
|
42
|
+
#
|
43
|
+
# buffer = Buffer.new(16)
|
44
|
+
# # => #<Ronin::Support::Binary::Buffer: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00">
|
45
|
+
# buffer.put_uint32(0,0x11223344)
|
46
|
+
# buffer.put_int32(4,-1)
|
47
|
+
# buffer.put_string(8,"ABC")
|
48
|
+
# buffer.put_float32(12,0.5)
|
49
|
+
# buffer.to_s
|
50
|
+
# # => "D3\"\x11\xFF\xFF\xFF\xFFABC\x00\x00\x00\x00?"
|
51
|
+
#
|
52
|
+
# Creating a buffer from an existing String:
|
53
|
+
#
|
54
|
+
# buffer = Buffer.new("\x41\x00\x00\x00\x42\x00\x00\x00")
|
55
|
+
# # => #<Ronin::Support::Binary::Buffer: "A\u0000\u0000\u0000B\u0000\u0000\u0000">
|
56
|
+
# buffer.get_uint32(0)
|
57
|
+
# # => 65
|
58
|
+
# buffer.get_uint32(4)
|
59
|
+
# # => 66
|
60
|
+
#
|
61
|
+
# @api public
|
62
|
+
#
|
63
|
+
# @since 1.0.0
|
64
|
+
#
|
65
|
+
class Buffer < Memory
|
66
|
+
|
67
|
+
include CTypes::Mixin
|
68
|
+
|
69
|
+
#
|
70
|
+
# Initializes the buffer.
|
71
|
+
#
|
72
|
+
# @param [Integer, String, ByteSlice] length_or_string
|
73
|
+
# The size of the buffer or an existing String which will be used
|
74
|
+
# as the underlying buffer.
|
75
|
+
#
|
76
|
+
# @param [Hash{Symbol => Object}] kwargs
|
77
|
+
# Additional keyword arguments.
|
78
|
+
#
|
79
|
+
# @option kwargs [:little, :big, :net, nil] :endian
|
80
|
+
# The desired endianness of the values within the buffer.
|
81
|
+
#
|
82
|
+
# @option kwargs [:x86, :x86_64,
|
83
|
+
# :ppc, :ppc64,
|
84
|
+
# :mips, :mips_le, :mips_be,
|
85
|
+
# :mips64, :mips64_le, :mips64_be,
|
86
|
+
# :arm, :arm_le, :arm_be,
|
87
|
+
# :arm64, :arm64_le, :arm64_be] :arch
|
88
|
+
# The desired architecture for the values within the buffer.
|
89
|
+
#
|
90
|
+
# @raise [ArgumentError]
|
91
|
+
# Either the `length_or_string` argument was not an Integer or a
|
92
|
+
# String.
|
93
|
+
#
|
94
|
+
def initialize(length_or_string, **kwargs)
|
95
|
+
initialize_type_system(**kwargs)
|
96
|
+
|
97
|
+
super(length_or_string)
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Reads from the IO stream and returns a buffer.
|
102
|
+
#
|
103
|
+
# @param [IO] io
|
104
|
+
# The IO object to read from.
|
105
|
+
#
|
106
|
+
# @param [Integer] size
|
107
|
+
# The size of the buffer to read.
|
108
|
+
#
|
109
|
+
# @return [Buffer]
|
110
|
+
# The read buffer.
|
111
|
+
#
|
112
|
+
# @see #read_from
|
113
|
+
#
|
114
|
+
# @api public
|
115
|
+
#
|
116
|
+
def self.read_from(io,size)
|
117
|
+
new(io.read(size))
|
118
|
+
end
|
119
|
+
|
120
|
+
alias length size
|
121
|
+
|
122
|
+
#
|
123
|
+
# Writes a value to the buffer at the given index.
|
124
|
+
#
|
125
|
+
# @param [Integer, Range<Integer,Integer>] index_or_range
|
126
|
+
# The index within the string to write to.
|
127
|
+
#
|
128
|
+
# @param [Integer, nil] length
|
129
|
+
# Optional additional length argument.
|
130
|
+
#
|
131
|
+
# @param [String] value
|
132
|
+
# The integer, float, or character value to write to the buffer.
|
133
|
+
#
|
134
|
+
# @return [String]
|
135
|
+
# The string written into the buffer.
|
136
|
+
#
|
137
|
+
# @example Writing a single byte:
|
138
|
+
# buffer[0] = 0x41
|
139
|
+
#
|
140
|
+
# @example Writing a single char:
|
141
|
+
# buffer[0] = 'A'
|
142
|
+
#
|
143
|
+
# @example Writing an Array of bytes to the given range of indexes:
|
144
|
+
# buffer[0..3] = [0x41, 0x42, 0x43]
|
145
|
+
#
|
146
|
+
# @example Writing an Array of chars to the given range of indexes:
|
147
|
+
# buffer[0..3] = ['A', 'B', 'C']
|
148
|
+
#
|
149
|
+
# @example Writing an Array of bytes to the given index and length:
|
150
|
+
# buffer[0,3] = [0x41, 0x42, 0x43]
|
151
|
+
#
|
152
|
+
# @example Writing an Array of bytes to the given index and length:
|
153
|
+
# buffer[0,3] = ['A', 'B', 'C']
|
154
|
+
#
|
155
|
+
def []=(index_or_range,length=nil,value)
|
156
|
+
value = case value
|
157
|
+
when Integer
|
158
|
+
value.chr(Encoding::ASCII_8BIT)
|
159
|
+
when ::Array
|
160
|
+
value.map { |char_or_byte|
|
161
|
+
case char_or_byte
|
162
|
+
when Integer
|
163
|
+
char_or_byte.chr(Encoding::ASCII_8BIT)
|
164
|
+
else
|
165
|
+
char_or_byte
|
166
|
+
end
|
167
|
+
}.join
|
168
|
+
else
|
169
|
+
value
|
170
|
+
end
|
171
|
+
|
172
|
+
super(index_or_range,length,value)
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Converts the buffer to a String.
|
177
|
+
#
|
178
|
+
# @return [String]
|
179
|
+
# The raw binary buffer.
|
180
|
+
#
|
181
|
+
def to_s
|
182
|
+
@string.to_s
|
183
|
+
end
|
184
|
+
|
185
|
+
alias to_str to_s
|
186
|
+
|
187
|
+
#
|
188
|
+
# @group Reader Methods
|
189
|
+
#
|
190
|
+
|
191
|
+
#
|
192
|
+
# Reads a value of the given type at the given offset.
|
193
|
+
#
|
194
|
+
# @param [Symbol] type
|
195
|
+
# The type of the value to read.
|
196
|
+
#
|
197
|
+
# @param [Integer] offset
|
198
|
+
# The offset within the buffer to read.
|
199
|
+
#
|
200
|
+
# @return [Integer, Float, String]
|
201
|
+
# The decoded value.
|
202
|
+
#
|
203
|
+
def get(type,offset)
|
204
|
+
type = @type_system[type]
|
205
|
+
|
206
|
+
if (offset < 0 || offset+type.size > size)
|
207
|
+
raise(IndexError,"offset #{offset} is out of bounds: 0...#{size-type.size}")
|
208
|
+
end
|
209
|
+
|
210
|
+
data = @string[offset,type.size]
|
211
|
+
return type.unpack(data)
|
212
|
+
end
|
213
|
+
|
214
|
+
#
|
215
|
+
# Alias for `get(:byte,offset)`.
|
216
|
+
#
|
217
|
+
# @param [Integer] offset
|
218
|
+
# The offset of the `byte` within the buffer.
|
219
|
+
#
|
220
|
+
# @return [Integer]
|
221
|
+
# The read `byte`.
|
222
|
+
#
|
223
|
+
# @see #get
|
224
|
+
#
|
225
|
+
def get_byte(offset)
|
226
|
+
get(:byte,offset)
|
227
|
+
end
|
228
|
+
|
229
|
+
#
|
230
|
+
# Alias for `get(:char,offset)`.
|
231
|
+
#
|
232
|
+
# @param [Integer] offset
|
233
|
+
# The offset of the `char` within the buffer.
|
234
|
+
#
|
235
|
+
# @return [String]
|
236
|
+
# The read `char`.
|
237
|
+
#
|
238
|
+
# @see #get
|
239
|
+
#
|
240
|
+
def get_char(offset)
|
241
|
+
get(:char,offset)
|
242
|
+
end
|
243
|
+
|
244
|
+
#
|
245
|
+
# Alias for `get(:uchar,offset)`.
|
246
|
+
#
|
247
|
+
# @param [Integer] offset
|
248
|
+
# The offset of the `uchar` within the buffer.
|
249
|
+
#
|
250
|
+
# @return [String]
|
251
|
+
# The read `uchar`.
|
252
|
+
#
|
253
|
+
# @see #get
|
254
|
+
#
|
255
|
+
def get_uchar(offset)
|
256
|
+
get(:uchar,offset)
|
257
|
+
end
|
258
|
+
|
259
|
+
#
|
260
|
+
# Reads a null-byte terminated C string from the buffer, at the given
|
261
|
+
# offset.
|
262
|
+
#
|
263
|
+
# @param [Integer] offset
|
264
|
+
# The offset of the `string` within the buffer.
|
265
|
+
#
|
266
|
+
# @param [Integer, nil] length
|
267
|
+
# The optional maximum desired length of the string.
|
268
|
+
#
|
269
|
+
# @return [String]
|
270
|
+
# The read C string, without the null-byte.
|
271
|
+
#
|
272
|
+
def get_string(offset,length=nil)
|
273
|
+
if (offset < 0 || offset >= size)
|
274
|
+
raise(IndexError,"offset #{offset} is out of bounds: 0...#{size-1}")
|
275
|
+
elsif (length && offset+length > size)
|
276
|
+
raise(IndexError,"offset #{offset} or length #{length} is out of bounds: 0...#{size-1}")
|
277
|
+
end
|
278
|
+
|
279
|
+
if length
|
280
|
+
substring = @string[offset,length]
|
281
|
+
|
282
|
+
if (null_byte = substring.index("\0"))
|
283
|
+
substring[0...null_byte]
|
284
|
+
end
|
285
|
+
else
|
286
|
+
if (null_byte = @string.index("\0",offset))
|
287
|
+
substring = @string[offset...null_byte]
|
288
|
+
else
|
289
|
+
substring = @string[offset..]
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
return substring
|
294
|
+
end
|
295
|
+
|
296
|
+
#
|
297
|
+
# Alias for `get(:int8,offset)`.
|
298
|
+
#
|
299
|
+
# @param [Integer] offset
|
300
|
+
# The offset of the `int8` within the buffer.
|
301
|
+
#
|
302
|
+
# @return [Integer]
|
303
|
+
# The read `int8`.
|
304
|
+
#
|
305
|
+
# @see #get
|
306
|
+
#
|
307
|
+
def get_int8(offset)
|
308
|
+
get(:int8,offset)
|
309
|
+
end
|
310
|
+
|
311
|
+
#
|
312
|
+
# Alias for `get(:int16,offset)`.
|
313
|
+
#
|
314
|
+
# @param [Integer] offset
|
315
|
+
# The offset of the `int16` within the buffer.
|
316
|
+
#
|
317
|
+
# @return [Integer]
|
318
|
+
# The read `int16`.
|
319
|
+
#
|
320
|
+
# @see #get
|
321
|
+
#
|
322
|
+
def get_int16(offset)
|
323
|
+
get(:int16,offset)
|
324
|
+
end
|
325
|
+
|
326
|
+
#
|
327
|
+
# Alias for `get(:int32,offset)`.
|
328
|
+
#
|
329
|
+
# @param [Integer] offset
|
330
|
+
# The offset of the `int32` within the buffer.
|
331
|
+
#
|
332
|
+
# @return [Integer]
|
333
|
+
# The read `int32`.
|
334
|
+
#
|
335
|
+
# @see #get
|
336
|
+
#
|
337
|
+
def get_int32(offset)
|
338
|
+
get(:int32,offset)
|
339
|
+
end
|
340
|
+
|
341
|
+
#
|
342
|
+
# Alias for `get(:int64,offset)`.
|
343
|
+
#
|
344
|
+
# @param [Integer] offset
|
345
|
+
# The offset of the `int64` within the buffer.
|
346
|
+
#
|
347
|
+
# @return [Integer]
|
348
|
+
# The read `int64`.
|
349
|
+
#
|
350
|
+
# @see #get
|
351
|
+
#
|
352
|
+
def get_int64(offset)
|
353
|
+
get(:int64,offset)
|
354
|
+
end
|
355
|
+
|
356
|
+
#
|
357
|
+
# Alias for `get(:uint8,offset)`.
|
358
|
+
#
|
359
|
+
# @param [Integer] offset
|
360
|
+
# The offset of the `uint8` within the buffer.
|
361
|
+
#
|
362
|
+
# @return [Integer]
|
363
|
+
# The read `uint8`.
|
364
|
+
#
|
365
|
+
# @see #get
|
366
|
+
#
|
367
|
+
def get_uint8(offset)
|
368
|
+
get(:uint8,offset)
|
369
|
+
end
|
370
|
+
|
371
|
+
#
|
372
|
+
# Alias for `get(:uint16,offset)`.
|
373
|
+
#
|
374
|
+
# @param [Integer] offset
|
375
|
+
# The offset of the `uint16` within the buffer.
|
376
|
+
#
|
377
|
+
# @return [Integer]
|
378
|
+
# The read `uint16`.
|
379
|
+
#
|
380
|
+
# @see #get
|
381
|
+
#
|
382
|
+
def get_uint16(offset)
|
383
|
+
get(:uint16,offset)
|
384
|
+
end
|
385
|
+
|
386
|
+
#
|
387
|
+
# Alias for `get(:uint32,offset)`.
|
388
|
+
#
|
389
|
+
# @param [Integer] offset
|
390
|
+
# The offset of the `uint32` within the buffer.
|
391
|
+
#
|
392
|
+
# @return [Integer]
|
393
|
+
# The read `uint32`.
|
394
|
+
#
|
395
|
+
# @see #get
|
396
|
+
#
|
397
|
+
def get_uint32(offset)
|
398
|
+
get(:uint32,offset)
|
399
|
+
end
|
400
|
+
|
401
|
+
#
|
402
|
+
# Alias for `get(:uint64,offset)`.
|
403
|
+
#
|
404
|
+
# @param [Integer] offset
|
405
|
+
# The offset of the `uint64` within the buffer.
|
406
|
+
#
|
407
|
+
# @return [Integer]
|
408
|
+
# The read `uint64`.
|
409
|
+
#
|
410
|
+
# @see #get
|
411
|
+
#
|
412
|
+
def get_uint64(offset)
|
413
|
+
get(:uint64,offset)
|
414
|
+
end
|
415
|
+
|
416
|
+
#
|
417
|
+
# Alias for `get(:short,offset)`.
|
418
|
+
#
|
419
|
+
# @param [Integer] offset
|
420
|
+
# The offset of the `short` within the buffer.
|
421
|
+
#
|
422
|
+
# @return [Integer]
|
423
|
+
# The read `short`.
|
424
|
+
#
|
425
|
+
# @see #get
|
426
|
+
#
|
427
|
+
def get_short(offset)
|
428
|
+
get(:short,offset)
|
429
|
+
end
|
430
|
+
|
431
|
+
#
|
432
|
+
# Alias for `get(:int,offset)`.
|
433
|
+
#
|
434
|
+
# @param [Integer] offset
|
435
|
+
# The offset of the `int` within the buffer.
|
436
|
+
#
|
437
|
+
# @return [Integer]
|
438
|
+
# The read `int`.
|
439
|
+
#
|
440
|
+
# @see #get
|
441
|
+
#
|
442
|
+
def get_int(offset)
|
443
|
+
get(:int,offset)
|
444
|
+
end
|
445
|
+
|
446
|
+
#
|
447
|
+
# Alias for `get(:long,offset)`.
|
448
|
+
#
|
449
|
+
# @param [Integer] offset
|
450
|
+
# The offset of the `long` within the buffer.
|
451
|
+
#
|
452
|
+
# @return [Integer]
|
453
|
+
# The read `long`.
|
454
|
+
#
|
455
|
+
# @see #get
|
456
|
+
#
|
457
|
+
def get_long(offset)
|
458
|
+
get(:long,offset)
|
459
|
+
end
|
460
|
+
|
461
|
+
#
|
462
|
+
# Alias for `get(:long_long,offset)`.
|
463
|
+
#
|
464
|
+
# @param [Integer] offset
|
465
|
+
# The offset of the `long_long` within the buffer.
|
466
|
+
#
|
467
|
+
# @return [Integer]
|
468
|
+
# The read `long_long`.
|
469
|
+
#
|
470
|
+
# @see #get
|
471
|
+
#
|
472
|
+
def get_long_long(offset)
|
473
|
+
get(:long_long,offset)
|
474
|
+
end
|
475
|
+
|
476
|
+
#
|
477
|
+
# Alias for `get(:ushort,offset)`.
|
478
|
+
#
|
479
|
+
# @param [Integer] offset
|
480
|
+
# The offset of the `ushort` within the buffer.
|
481
|
+
#
|
482
|
+
# @return [Integer]
|
483
|
+
# The read `ushort`.
|
484
|
+
#
|
485
|
+
# @see #get
|
486
|
+
#
|
487
|
+
def get_ushort(offset)
|
488
|
+
get(:ushort,offset)
|
489
|
+
end
|
490
|
+
|
491
|
+
#
|
492
|
+
# Alias for `get(:uint,offset)`.
|
493
|
+
#
|
494
|
+
# @param [Integer] offset
|
495
|
+
# The offset of the `uint` within the buffer.
|
496
|
+
#
|
497
|
+
# @return [Integer]
|
498
|
+
# The read `uint`.
|
499
|
+
#
|
500
|
+
# @see #get
|
501
|
+
#
|
502
|
+
def get_uint(offset)
|
503
|
+
get(:uint,offset)
|
504
|
+
end
|
505
|
+
|
506
|
+
#
|
507
|
+
# Alias for `get(:ulong,offset)`.
|
508
|
+
#
|
509
|
+
# @param [Integer] offset
|
510
|
+
# The offset of the `ulong` within the buffer.
|
511
|
+
#
|
512
|
+
# @return [Integer]
|
513
|
+
# The read `ulong`.
|
514
|
+
#
|
515
|
+
# @see #get
|
516
|
+
#
|
517
|
+
def get_ulong(offset)
|
518
|
+
get(:ulong,offset)
|
519
|
+
end
|
520
|
+
|
521
|
+
#
|
522
|
+
# Alias for `get(:ulong_long,offset)`.
|
523
|
+
#
|
524
|
+
# @param [Integer] offset
|
525
|
+
# The offset of the `ulong_long` within the buffer.
|
526
|
+
#
|
527
|
+
# @return [Integer]
|
528
|
+
# The read `ulong_long`.
|
529
|
+
#
|
530
|
+
# @see #get
|
531
|
+
#
|
532
|
+
def get_ulong_long(offset)
|
533
|
+
get(:ulong_long,offset)
|
534
|
+
end
|
535
|
+
|
536
|
+
#
|
537
|
+
# Alias for `get(:float32,offset)`.
|
538
|
+
#
|
539
|
+
# @param [Integer] offset
|
540
|
+
# The offset of the `float32` within the buffer.
|
541
|
+
#
|
542
|
+
# @return [Float]
|
543
|
+
# The read `float32`.
|
544
|
+
#
|
545
|
+
# @see #get
|
546
|
+
#
|
547
|
+
def get_float32(offset)
|
548
|
+
get(:float32,offset)
|
549
|
+
end
|
550
|
+
|
551
|
+
#
|
552
|
+
# Alias for `get(:float64,offset)`.
|
553
|
+
#
|
554
|
+
# @param [Integer] offset
|
555
|
+
# The offset of the `float64` within the buffer.
|
556
|
+
#
|
557
|
+
# @return [Float]
|
558
|
+
# The read `float64`.
|
559
|
+
#
|
560
|
+
# @see #get
|
561
|
+
#
|
562
|
+
def get_float64(offset)
|
563
|
+
get(:float64,offset)
|
564
|
+
end
|
565
|
+
|
566
|
+
#
|
567
|
+
# Alias for `get(:float,offset)`.
|
568
|
+
#
|
569
|
+
# @param [Integer] offset
|
570
|
+
# The offset of the `float` within the buffer.
|
571
|
+
#
|
572
|
+
# @return [Float]
|
573
|
+
# The read `float`.
|
574
|
+
#
|
575
|
+
# @see #get
|
576
|
+
#
|
577
|
+
def get_float(offset)
|
578
|
+
get(:float,offset)
|
579
|
+
end
|
580
|
+
|
581
|
+
#
|
582
|
+
# Alias for `get(:double,offset)`.
|
583
|
+
#
|
584
|
+
# @param [Integer] offset
|
585
|
+
# The offset of the `double` within the buffer.
|
586
|
+
#
|
587
|
+
# @return [Float]
|
588
|
+
# The read `double`.
|
589
|
+
#
|
590
|
+
# @see #get
|
591
|
+
#
|
592
|
+
def get_double(offset)
|
593
|
+
get(:double,offset)
|
594
|
+
end
|
595
|
+
|
596
|
+
#
|
597
|
+
# Returns the buffer starting at the given offset and with the given
|
598
|
+
# size.
|
599
|
+
#
|
600
|
+
# @param [Integer] offset
|
601
|
+
# The offset within the buffer.
|
602
|
+
#
|
603
|
+
# @param [Integer] size
|
604
|
+
# The number of bytes for the buffer.
|
605
|
+
#
|
606
|
+
# @return [Buffer]
|
607
|
+
# The new buffer.
|
608
|
+
#
|
609
|
+
# @example
|
610
|
+
# subbuffer = buffer.buffer_at(10,40)
|
611
|
+
#
|
612
|
+
def buffer_at(offset,size)
|
613
|
+
Buffer.new(byteslice(offset,size))
|
614
|
+
end
|
615
|
+
|
616
|
+
#
|
617
|
+
# Returns the array starting at the given offset, with the given
|
618
|
+
# length, containing the given type.
|
619
|
+
#
|
620
|
+
# @param [Integer] offset
|
621
|
+
# The offset within the buffer that the array starts at.
|
622
|
+
#
|
623
|
+
# @param [Symbol] type
|
624
|
+
# The type name.
|
625
|
+
#
|
626
|
+
# @param [Integer] length
|
627
|
+
# The number of elements in the array.
|
628
|
+
#
|
629
|
+
# @return [Array]
|
630
|
+
# The new array.
|
631
|
+
#
|
632
|
+
# @example
|
633
|
+
# array = buffer.array_at(0,:uint32,10)
|
634
|
+
#
|
635
|
+
def array_at(offset,type,length)
|
636
|
+
type = @type_system[type]
|
637
|
+
size = type.size * length
|
638
|
+
|
639
|
+
return Array.new(type,byteslice(offset,size))
|
640
|
+
end
|
641
|
+
|
642
|
+
#
|
643
|
+
# Returns a new {Struct} instance starting at the given offset.
|
644
|
+
#
|
645
|
+
# @param [Integer] offset
|
646
|
+
# The offset within the buffer that the struct starts at.
|
647
|
+
#
|
648
|
+
# @param [Class<Binary::Struct>] struct_class
|
649
|
+
# The struct class.
|
650
|
+
#
|
651
|
+
# @return [Binary::Struct]
|
652
|
+
# The new struct instance.
|
653
|
+
#
|
654
|
+
# @example
|
655
|
+
# struct = buffer.struct_at(10,MyStruct)
|
656
|
+
# # => #<MyStruct: ...>
|
657
|
+
#
|
658
|
+
def struct_at(offset,struct_class)
|
659
|
+
unless struct_class < Struct
|
660
|
+
raise(ArgumentError,"the given class must be a #{Struct} subclass: #{struct_class.inspect}")
|
661
|
+
end
|
662
|
+
|
663
|
+
return struct_class.new(byteslice(offset,struct_class.size))
|
664
|
+
end
|
665
|
+
|
666
|
+
#
|
667
|
+
# Returns a new {Union} instance starting at the given offset.
|
668
|
+
#
|
669
|
+
# @param [Integer] offset
|
670
|
+
# The offset within the buffer that the union starts at.
|
671
|
+
#
|
672
|
+
# @param [Class<Union>] union_class
|
673
|
+
# The union class.
|
674
|
+
#
|
675
|
+
# @return [Union]
|
676
|
+
# The new union instance.
|
677
|
+
#
|
678
|
+
# @example
|
679
|
+
# union = buffer.union_at(10,MyUnion)
|
680
|
+
# # => #<MyUnion: ...>
|
681
|
+
#
|
682
|
+
def union_at(offset,union_class)
|
683
|
+
unless union_class < Union
|
684
|
+
raise(ArgumentError,"the given class must be a #{Union} subclass: #{union_class.inspect}")
|
685
|
+
end
|
686
|
+
|
687
|
+
return union_class.new(byteslice(offset,union_class.size))
|
688
|
+
end
|
689
|
+
|
690
|
+
#
|
691
|
+
# Reads an array of the given type, starting at the given offset, with
|
692
|
+
# the given length.
|
693
|
+
#
|
694
|
+
# @param [Symbol] type
|
695
|
+
# The type of the value to read.
|
696
|
+
#
|
697
|
+
# @param [Integer] offset
|
698
|
+
# The offset that the array starts at within the buffer.
|
699
|
+
#
|
700
|
+
# @param [Integer] count
|
701
|
+
# The number of desired elements within the array.
|
702
|
+
#
|
703
|
+
# @return [::Array<Object>]
|
704
|
+
# The read array of types.
|
705
|
+
#
|
706
|
+
def get_array_of(type,offset,count)
|
707
|
+
type = @type_system[type]
|
708
|
+
array_type = type[count]
|
709
|
+
|
710
|
+
if (offset < 0 || offset+array_type.size > size)
|
711
|
+
raise(IndexError,"offset #{offset} or size #{array_type.size} is out of bounds: 0...#{size-type.size}")
|
712
|
+
end
|
713
|
+
|
714
|
+
slice = @string[offset,array_type.size]
|
715
|
+
return array_type.unpack(slice)
|
716
|
+
end
|
717
|
+
|
718
|
+
#
|
719
|
+
# Alias to `get_array_of(:byte,offset,count)`.
|
720
|
+
#
|
721
|
+
# @param [Integer] offset
|
722
|
+
# The offset within the buffer to start reading at.
|
723
|
+
#
|
724
|
+
# @param [Integer] count
|
725
|
+
# The number of bytes to read.
|
726
|
+
#
|
727
|
+
# @return [::Array<Integer>]
|
728
|
+
# The read array of bytes.
|
729
|
+
#
|
730
|
+
# @see #get_array_of
|
731
|
+
#
|
732
|
+
def get_array_of_byte(offset,count)
|
733
|
+
get_array_of(:byte,offset,count)
|
734
|
+
end
|
735
|
+
|
736
|
+
alias get_bytes get_array_of_byte
|
737
|
+
|
738
|
+
#
|
739
|
+
# Alias to `get_array_of(:char,offset,count)`.
|
740
|
+
#
|
741
|
+
# @param [Integer] offset
|
742
|
+
# The offset within the buffer to start reading at.
|
743
|
+
#
|
744
|
+
# @param [Integer] count
|
745
|
+
# The number of chars to read.
|
746
|
+
#
|
747
|
+
# @return [::Array<Integer>]
|
748
|
+
# The read array of chars.
|
749
|
+
#
|
750
|
+
# @see #get_array_of
|
751
|
+
#
|
752
|
+
def get_array_of_char(offset,count)
|
753
|
+
get_array_of(:char,offset,count)
|
754
|
+
end
|
755
|
+
|
756
|
+
alias get_chars get_array_of_char
|
757
|
+
|
758
|
+
#
|
759
|
+
# Alias to `get_array_of(:uchar,offset,count)`.
|
760
|
+
#
|
761
|
+
# @param [Integer] offset
|
762
|
+
# The offset within the buffer to start reading at.
|
763
|
+
#
|
764
|
+
# @param [Integer] count
|
765
|
+
# The number of unsigned chars to read.
|
766
|
+
#
|
767
|
+
# @return [::Array<Integer>]
|
768
|
+
# The read array of unsigned chars.
|
769
|
+
#
|
770
|
+
# @see #get_array_of
|
771
|
+
#
|
772
|
+
def get_array_of_uchar(offset,count)
|
773
|
+
get_array_of(:uchar,offset,count)
|
774
|
+
end
|
775
|
+
|
776
|
+
alias get_uchars get_array_of_uchar
|
777
|
+
|
778
|
+
#
|
779
|
+
# Alias to `get_array_of(:int8,offset,count)`.
|
780
|
+
#
|
781
|
+
# @param [Integer] offset
|
782
|
+
# The offset within the buffer to start reading at.
|
783
|
+
#
|
784
|
+
# @param [Integer] count
|
785
|
+
# The number of `int8` values to read.
|
786
|
+
#
|
787
|
+
# @return [::Array<Integer>]
|
788
|
+
# The read array of `int8` values.
|
789
|
+
#
|
790
|
+
# @see #get_array_of
|
791
|
+
#
|
792
|
+
def get_array_of_int8(offset,count)
|
793
|
+
get_array_of(:int8,offset,count)
|
794
|
+
end
|
795
|
+
|
796
|
+
#
|
797
|
+
# Alias to `get_array_of(:int16,offset,count)`.
|
798
|
+
#
|
799
|
+
# @param [Integer] offset
|
800
|
+
# The offset within the buffer to start reading at.
|
801
|
+
#
|
802
|
+
# @param [Integer] count
|
803
|
+
# The number of `int16` values to read.
|
804
|
+
#
|
805
|
+
# @return [::Array<Integer>]
|
806
|
+
# The read array of `int16` values.
|
807
|
+
#
|
808
|
+
# @see #get_array_of
|
809
|
+
#
|
810
|
+
def get_array_of_int16(offset,count)
|
811
|
+
get_array_of(:int16,offset,count)
|
812
|
+
end
|
813
|
+
|
814
|
+
#
|
815
|
+
# Alias to `get_array_of(:int32,offset,count)`.
|
816
|
+
#
|
817
|
+
# @param [Integer] offset
|
818
|
+
# The offset within the buffer to start reading at.
|
819
|
+
#
|
820
|
+
# @param [Integer] count
|
821
|
+
# The number of `int32` values to read.
|
822
|
+
#
|
823
|
+
# @return [::Array<Integer>]
|
824
|
+
# The read array of `int32` values.
|
825
|
+
#
|
826
|
+
# @see #get_array_of
|
827
|
+
#
|
828
|
+
def get_array_of_int32(offset,count)
|
829
|
+
get_array_of(:int32,offset,count)
|
830
|
+
end
|
831
|
+
|
832
|
+
#
|
833
|
+
# Alias to `get_array_of(:int64,offset,count)`.
|
834
|
+
#
|
835
|
+
# @param [Integer] offset
|
836
|
+
# The offset within the buffer to start reading at.
|
837
|
+
#
|
838
|
+
# @param [Integer] count
|
839
|
+
# The number of `int64` values to read.
|
840
|
+
#
|
841
|
+
# @return [::Array<Integer>]
|
842
|
+
# The read array of `int64` values.
|
843
|
+
#
|
844
|
+
# @see #get_array_of
|
845
|
+
#
|
846
|
+
def get_array_of_int64(offset,count)
|
847
|
+
get_array_of(:int64,offset,count)
|
848
|
+
end
|
849
|
+
|
850
|
+
#
|
851
|
+
# Alias to `get_array_of(:uint8,offset,count)`.
|
852
|
+
#
|
853
|
+
# @param [Integer] offset
|
854
|
+
# The offset within the buffer to start reading at.
|
855
|
+
#
|
856
|
+
# @param [Integer] count
|
857
|
+
# The number of `uint8` values to read.
|
858
|
+
#
|
859
|
+
# @return [::Array<Integer>]
|
860
|
+
# The read array of `uint8` values.
|
861
|
+
#
|
862
|
+
# @see #get_array_of
|
863
|
+
#
|
864
|
+
def get_array_of_uint8(offset,count)
|
865
|
+
get_array_of(:uint8,offset,count)
|
866
|
+
end
|
867
|
+
|
868
|
+
#
|
869
|
+
# Alias to `get_array_of(:uint16,offset,count)`.
|
870
|
+
#
|
871
|
+
# @param [Integer] offset
|
872
|
+
# The offset within the buffer to start reading at.
|
873
|
+
#
|
874
|
+
# @param [Integer] count
|
875
|
+
# The number of `uint16` values to read.
|
876
|
+
#
|
877
|
+
# @return [::Array<Integer>]
|
878
|
+
# The read array of `uint16` values.
|
879
|
+
#
|
880
|
+
# @see #get_array_of
|
881
|
+
#
|
882
|
+
def get_array_of_uint16(offset,count)
|
883
|
+
get_array_of(:uint16,offset,count)
|
884
|
+
end
|
885
|
+
|
886
|
+
#
|
887
|
+
# Alias to `get_array_of(:uint32,offset,count)`.
|
888
|
+
#
|
889
|
+
# @param [Integer] offset
|
890
|
+
# The offset within the buffer to start reading at.
|
891
|
+
#
|
892
|
+
# @param [Integer] count
|
893
|
+
# The number of `uint32` values to read.
|
894
|
+
#
|
895
|
+
# @return [::Array<Integer>]
|
896
|
+
# The read array of `uint32` values.
|
897
|
+
#
|
898
|
+
# @see #get_array_of
|
899
|
+
#
|
900
|
+
def get_array_of_uint32(offset,count)
|
901
|
+
get_array_of(:uint32,offset,count)
|
902
|
+
end
|
903
|
+
|
904
|
+
#
|
905
|
+
# Alias to `get_array_of(:uint64,offset,count)`.
|
906
|
+
#
|
907
|
+
# @param [Integer] offset
|
908
|
+
# The offset within the buffer to start reading at.
|
909
|
+
#
|
910
|
+
# @param [Integer] count
|
911
|
+
# The number of `uint64` values to read.
|
912
|
+
#
|
913
|
+
# @return [::Array<Integer>]
|
914
|
+
# The read array of `uint64` values.
|
915
|
+
#
|
916
|
+
# @see #get_array_of
|
917
|
+
#
|
918
|
+
def get_array_of_uint64(offset,count)
|
919
|
+
get_array_of(:uint64,offset,count)
|
920
|
+
end
|
921
|
+
|
922
|
+
#
|
923
|
+
# Alias to `get_array_of(:short,offset,count)`.
|
924
|
+
#
|
925
|
+
# @param [Integer] offset
|
926
|
+
# The offset within the buffer to start reading at.
|
927
|
+
#
|
928
|
+
# @param [Integer] count
|
929
|
+
# The number of `short` values to read.
|
930
|
+
#
|
931
|
+
# @return [::Array<Integer>]
|
932
|
+
# The read array of `short` values.
|
933
|
+
#
|
934
|
+
# @see #get_array_of
|
935
|
+
#
|
936
|
+
def get_array_of_short(offset,count)
|
937
|
+
get_array_of(:short,offset,count)
|
938
|
+
end
|
939
|
+
|
940
|
+
#
|
941
|
+
# Alias to `get_array_of(:int,offset,count)`.
|
942
|
+
#
|
943
|
+
# @param [Integer] offset
|
944
|
+
# The offset within the buffer to start reading at.
|
945
|
+
#
|
946
|
+
# @param [Integer] count
|
947
|
+
# The number of `int` values to read.
|
948
|
+
#
|
949
|
+
# @return [::Array<Integer>]
|
950
|
+
# The read array of `int` values.
|
951
|
+
#
|
952
|
+
# @see #get_array_of
|
953
|
+
#
|
954
|
+
def get_array_of_int(offset,count)
|
955
|
+
get_array_of(:int,offset,count)
|
956
|
+
end
|
957
|
+
|
958
|
+
alias get_ints get_array_of_int
|
959
|
+
|
960
|
+
#
|
961
|
+
# Alias to `get_array_of(:long,offset,count)`.
|
962
|
+
#
|
963
|
+
# @param [Integer] offset
|
964
|
+
# The offset within the buffer to start reading at.
|
965
|
+
#
|
966
|
+
# @param [Integer] count
|
967
|
+
# The number of `long` values to read.
|
968
|
+
#
|
969
|
+
# @return [::Array<Integer>]
|
970
|
+
# The read array of `long` values.
|
971
|
+
#
|
972
|
+
# @see #get_array_of
|
973
|
+
#
|
974
|
+
def get_array_of_long(offset,count)
|
975
|
+
get_array_of(:long,offset,count)
|
976
|
+
end
|
977
|
+
|
978
|
+
#
|
979
|
+
# Alias to `get_array_of(:long_long,offset,count)`.
|
980
|
+
#
|
981
|
+
# @param [Integer] offset
|
982
|
+
# The offset within the buffer to start reading at.
|
983
|
+
#
|
984
|
+
# @param [Integer] count
|
985
|
+
# The number of `long_long` values to read.
|
986
|
+
#
|
987
|
+
# @return [::Array<Integer>]
|
988
|
+
# The read array of `long_long` values.
|
989
|
+
#
|
990
|
+
# @see #get_array_of
|
991
|
+
#
|
992
|
+
def get_array_of_long_long(offset,count)
|
993
|
+
get_array_of(:long_long,offset,count)
|
994
|
+
end
|
995
|
+
|
996
|
+
#
|
997
|
+
# Alias to `get_array_of(:ushort,offset,count)`.
|
998
|
+
#
|
999
|
+
# @param [Integer] offset
|
1000
|
+
# The offset within the buffer to start reading at.
|
1001
|
+
#
|
1002
|
+
# @param [Integer] count
|
1003
|
+
# The number of `ushort` values to read.
|
1004
|
+
#
|
1005
|
+
# @return [::Array<Integer>]
|
1006
|
+
# The read array of `ushort` values.
|
1007
|
+
#
|
1008
|
+
# @see #get_array_of
|
1009
|
+
#
|
1010
|
+
def get_array_of_ushort(offset,count)
|
1011
|
+
get_array_of(:ushort,offset,count)
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
#
|
1015
|
+
# Alias to `get_array_of(:uint,offset,count)`.
|
1016
|
+
#
|
1017
|
+
# @param [Integer] offset
|
1018
|
+
# The offset within the buffer to start reading at.
|
1019
|
+
#
|
1020
|
+
# @param [Integer] count
|
1021
|
+
# The number of `uint` values to read.
|
1022
|
+
#
|
1023
|
+
# @return [::Array<Integer>]
|
1024
|
+
# The read array of `uint` values.
|
1025
|
+
#
|
1026
|
+
# @see #get_array_of
|
1027
|
+
#
|
1028
|
+
def get_array_of_uint(offset,count)
|
1029
|
+
get_array_of(:uint,offset,count)
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
alias get_uints get_array_of_uint
|
1033
|
+
|
1034
|
+
#
|
1035
|
+
# Alias to `get_array_of(:ulong,offset,count)`.
|
1036
|
+
#
|
1037
|
+
# @param [Integer] offset
|
1038
|
+
# The offset within the buffer to start reading at.
|
1039
|
+
#
|
1040
|
+
# @param [Integer] count
|
1041
|
+
# The number of `ulong` values to read.
|
1042
|
+
#
|
1043
|
+
# @return [::Array<Integer>]
|
1044
|
+
# The read array of `ulong` values.
|
1045
|
+
#
|
1046
|
+
# @see #get_array_of
|
1047
|
+
#
|
1048
|
+
def get_array_of_ulong(offset,count)
|
1049
|
+
get_array_of(:ulong,offset,count)
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
#
|
1053
|
+
# Alias to `get_array_of(:ulong_long,offset,count)`.
|
1054
|
+
#
|
1055
|
+
# @param [Integer] offset
|
1056
|
+
# The offset within the buffer to start reading at.
|
1057
|
+
#
|
1058
|
+
# @param [Integer] count
|
1059
|
+
# The number of `ulong_long` values to read.
|
1060
|
+
#
|
1061
|
+
# @return [::Array<Integer>]
|
1062
|
+
# The read array of `ulong_long` values.
|
1063
|
+
#
|
1064
|
+
# @see #get_array_of
|
1065
|
+
#
|
1066
|
+
def get_array_of_ulong_long(offset,count)
|
1067
|
+
get_array_of(:ulong_long,offset,count)
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
#
|
1071
|
+
# Alias to `get_array_of(:float32,offset,count)`.
|
1072
|
+
#
|
1073
|
+
# @param [Integer] offset
|
1074
|
+
# The offset within the buffer to start reading at.
|
1075
|
+
#
|
1076
|
+
# @param [Integer] count
|
1077
|
+
# The number of `float32` values to read.
|
1078
|
+
#
|
1079
|
+
# @return [::Array<Float>]
|
1080
|
+
# The read array of `float32` values.
|
1081
|
+
#
|
1082
|
+
# @see #get_array_of
|
1083
|
+
#
|
1084
|
+
def get_array_of_float32(offset,count)
|
1085
|
+
get_array_of(:float32,offset,count)
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
#
|
1089
|
+
# Alias to `get_array_of(:float64,offset,count)`.
|
1090
|
+
#
|
1091
|
+
# @param [Integer] offset
|
1092
|
+
# The offset within the buffer to start reading at.
|
1093
|
+
#
|
1094
|
+
# @param [Integer] count
|
1095
|
+
# The number of `float64` values to read.
|
1096
|
+
#
|
1097
|
+
# @return [::Array<Float>]
|
1098
|
+
# The read array of `float64` values.
|
1099
|
+
#
|
1100
|
+
# @see #get_array_of
|
1101
|
+
#
|
1102
|
+
def get_array_of_float64(offset,count)
|
1103
|
+
get_array_of(:float64,offset,count)
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
#
|
1107
|
+
# Alias to `get_array_of(:float,offset,count)`.
|
1108
|
+
#
|
1109
|
+
# @param [Integer] offset
|
1110
|
+
# The offset within the buffer to start reading at.
|
1111
|
+
#
|
1112
|
+
# @param [Integer] count
|
1113
|
+
# The number of `float` values to read.
|
1114
|
+
#
|
1115
|
+
# @return [::Array<Float>]
|
1116
|
+
# The read array of `float` values.
|
1117
|
+
#
|
1118
|
+
# @see #get_array_of
|
1119
|
+
#
|
1120
|
+
def get_array_of_float(offset,count)
|
1121
|
+
get_array_of(:float,offset,count)
|
1122
|
+
end
|
1123
|
+
|
1124
|
+
alias get_floats get_array_of_float
|
1125
|
+
|
1126
|
+
#
|
1127
|
+
# Alias to `get_array_of(:double,offset,count)`.
|
1128
|
+
#
|
1129
|
+
# @param [Integer] offset
|
1130
|
+
# The offset within the buffer to start reading at.
|
1131
|
+
#
|
1132
|
+
# @param [Integer] count
|
1133
|
+
# The number of `double` values to read.
|
1134
|
+
#
|
1135
|
+
# @return [::Array<Float>]
|
1136
|
+
# The read array of `double` values.
|
1137
|
+
#
|
1138
|
+
# @see #get_array_of
|
1139
|
+
#
|
1140
|
+
def get_array_of_double(offset,count)
|
1141
|
+
get_array_of(:double,offset,count)
|
1142
|
+
end
|
1143
|
+
|
1144
|
+
alias get_doubles get_array_of_double
|
1145
|
+
|
1146
|
+
#
|
1147
|
+
# @group Writer Methods
|
1148
|
+
#
|
1149
|
+
|
1150
|
+
#
|
1151
|
+
# Writes a value of the given type to the given offset.
|
1152
|
+
#
|
1153
|
+
# @param [Symbol] type
|
1154
|
+
# The type of the value to write.
|
1155
|
+
#
|
1156
|
+
# @param [Integer] offset
|
1157
|
+
# The offset within the buffer to write.
|
1158
|
+
#
|
1159
|
+
# @param [Integer, Float, String] value
|
1160
|
+
# The value to write.
|
1161
|
+
#
|
1162
|
+
def put(type,offset,value)
|
1163
|
+
type = @type_system[type]
|
1164
|
+
|
1165
|
+
if (offset < 0 || offset+type.size > size)
|
1166
|
+
raise(IndexError,"offset #{offset} is out of bounds: 0...#{size-type.size}")
|
1167
|
+
end
|
1168
|
+
|
1169
|
+
data = type.pack(value)
|
1170
|
+
|
1171
|
+
@string[offset,type.size] = data
|
1172
|
+
return self
|
1173
|
+
end
|
1174
|
+
|
1175
|
+
#
|
1176
|
+
# Alias for `put(:byte,offset,value)`.
|
1177
|
+
#
|
1178
|
+
# @param [Integer] offset
|
1179
|
+
# The offset of the `byte` within the buffer.
|
1180
|
+
#
|
1181
|
+
# @param [Integer] value
|
1182
|
+
# The `char` value to write into the buffer.
|
1183
|
+
#
|
1184
|
+
# @return [self]
|
1185
|
+
#
|
1186
|
+
# @see #put
|
1187
|
+
#
|
1188
|
+
def put_byte(offset,value)
|
1189
|
+
put(:byte,offset,value)
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
#
|
1193
|
+
# Alias for `put(:char,offset,value)`.
|
1194
|
+
#
|
1195
|
+
# @param [Integer] offset
|
1196
|
+
# The offset of the `char` within the buffer.
|
1197
|
+
#
|
1198
|
+
# @param [String] value
|
1199
|
+
# The `char` value to write into the buffer.
|
1200
|
+
#
|
1201
|
+
# @return [self]
|
1202
|
+
#
|
1203
|
+
# @see #put
|
1204
|
+
#
|
1205
|
+
def put_char(offset,value)
|
1206
|
+
put(:char,offset,value)
|
1207
|
+
end
|
1208
|
+
|
1209
|
+
#
|
1210
|
+
# Writes a null-terminated C string into the buffer at the given
|
1211
|
+
# offset.
|
1212
|
+
#
|
1213
|
+
# @param [Integer] offset
|
1214
|
+
# The offset to start writing the string into the buffer.
|
1215
|
+
#
|
1216
|
+
# @param [String] string
|
1217
|
+
# The String to write into the buffer.
|
1218
|
+
#
|
1219
|
+
# @return [self]
|
1220
|
+
#
|
1221
|
+
def put_string(offset,string)
|
1222
|
+
ascii_string = string.encode(Encoding::ASCII_8BIT)
|
1223
|
+
cstring = "#{ascii_string}\0"
|
1224
|
+
|
1225
|
+
if (offset < 0 || offset+cstring.bytesize >= size)
|
1226
|
+
raise(IndexError,"offset #{offset} or C string size #{cstring.bytesize} is out of bounds: 0...#{size-1}")
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
@string[offset,cstring.bytesize] = cstring
|
1230
|
+
return self
|
1231
|
+
end
|
1232
|
+
|
1233
|
+
#
|
1234
|
+
# Alias for `put(:uchar,offset,value)`.
|
1235
|
+
#
|
1236
|
+
# @param [Integer] offset
|
1237
|
+
# The offset of the `uchar` within the buffer.
|
1238
|
+
#
|
1239
|
+
# @param [String] value
|
1240
|
+
# The `uchar` value to write into the buffer.
|
1241
|
+
#
|
1242
|
+
# @return [self]
|
1243
|
+
#
|
1244
|
+
# @see #put
|
1245
|
+
#
|
1246
|
+
def put_uchar(offset,value)
|
1247
|
+
put(:uchar,offset,value)
|
1248
|
+
end
|
1249
|
+
|
1250
|
+
#
|
1251
|
+
# Alias for `put(:int8,offset,value)`.
|
1252
|
+
#
|
1253
|
+
# @param [Integer] offset
|
1254
|
+
# The offset of the `int8` within the buffer.
|
1255
|
+
#
|
1256
|
+
# @param [Integer] value
|
1257
|
+
# The `int8` value to write into the buffer.
|
1258
|
+
#
|
1259
|
+
# @return [self]
|
1260
|
+
#
|
1261
|
+
# @see #put
|
1262
|
+
#
|
1263
|
+
def put_int8(offset,value)
|
1264
|
+
put(:int8,offset,value)
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
#
|
1268
|
+
# Alias for `put(:int16,offset,value)`.
|
1269
|
+
#
|
1270
|
+
# @param [Integer] offset
|
1271
|
+
# The offset of the `int16` within the buffer.
|
1272
|
+
#
|
1273
|
+
# @param [Integer] value
|
1274
|
+
# The `int16` value to write into the buffer.
|
1275
|
+
#
|
1276
|
+
# @return [self]
|
1277
|
+
#
|
1278
|
+
# @see #put
|
1279
|
+
#
|
1280
|
+
def put_int16(offset,value)
|
1281
|
+
put(:int16,offset,value)
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
#
|
1285
|
+
# Alias for `put(:int32,offset,value)`.
|
1286
|
+
#
|
1287
|
+
# @param [Integer] offset
|
1288
|
+
# The offset of the `int32` within the buffer.
|
1289
|
+
#
|
1290
|
+
# @param [Integer] value
|
1291
|
+
# The `int32` value to write into the buffer.
|
1292
|
+
#
|
1293
|
+
# @return [self]
|
1294
|
+
#
|
1295
|
+
# @see #put
|
1296
|
+
#
|
1297
|
+
def put_int32(offset,value)
|
1298
|
+
put(:int32,offset,value)
|
1299
|
+
end
|
1300
|
+
|
1301
|
+
#
|
1302
|
+
# Alias for `put(:int64,offset,value)`.
|
1303
|
+
#
|
1304
|
+
# @param [Integer] offset
|
1305
|
+
# The offset of the `int64` within the buffer.
|
1306
|
+
#
|
1307
|
+
# @param [Integer] value
|
1308
|
+
# The `int64` value to write into the buffer.
|
1309
|
+
#
|
1310
|
+
# @return [self]
|
1311
|
+
#
|
1312
|
+
# @see #put
|
1313
|
+
#
|
1314
|
+
def put_int64(offset,value)
|
1315
|
+
put(:int64,offset,value)
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
#
|
1319
|
+
# Alias for `put(:uint8,offset,value)`.
|
1320
|
+
#
|
1321
|
+
# @param [Integer] offset
|
1322
|
+
# The offset of the `uint8` within the buffer.
|
1323
|
+
#
|
1324
|
+
# @param [Integer] value
|
1325
|
+
# The `uint8` value to write into the buffer.
|
1326
|
+
#
|
1327
|
+
# @return [self]
|
1328
|
+
#
|
1329
|
+
# @see #put
|
1330
|
+
#
|
1331
|
+
def put_uint8(offset,value)
|
1332
|
+
put(:uint8,offset,value)
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
#
|
1336
|
+
# Alias for `put(:uint16,offset,value)`.
|
1337
|
+
#
|
1338
|
+
# @param [Integer] offset
|
1339
|
+
# The offset of the `uint16` within the buffer.
|
1340
|
+
#
|
1341
|
+
# @param [Integer] value
|
1342
|
+
# The `uint16` value to write into the buffer.
|
1343
|
+
#
|
1344
|
+
# @return [self]
|
1345
|
+
#
|
1346
|
+
# @see #put
|
1347
|
+
#
|
1348
|
+
def put_uint16(offset,value)
|
1349
|
+
put(:uint16,offset,value)
|
1350
|
+
end
|
1351
|
+
|
1352
|
+
#
|
1353
|
+
# Alias for `put(:uint32,offset,value)`.
|
1354
|
+
#
|
1355
|
+
# @param [Integer] offset
|
1356
|
+
# The offset of the `uint32` within the buffer.
|
1357
|
+
#
|
1358
|
+
# @param [Integer] value
|
1359
|
+
# The `uint32` value to write into the buffer.
|
1360
|
+
#
|
1361
|
+
# @return [self]
|
1362
|
+
#
|
1363
|
+
# @see #put
|
1364
|
+
#
|
1365
|
+
def put_uint32(offset,value)
|
1366
|
+
put(:uint32,offset,value)
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
#
|
1370
|
+
# Alias for `put(:uint64,offset,value)`.
|
1371
|
+
#
|
1372
|
+
# @param [Integer] offset
|
1373
|
+
# The offset of the `uint64` within the buffer.
|
1374
|
+
#
|
1375
|
+
# @param [Integer] value
|
1376
|
+
# The `uint64` value to write into the buffer.
|
1377
|
+
#
|
1378
|
+
# @return [self]
|
1379
|
+
#
|
1380
|
+
# @see #put
|
1381
|
+
#
|
1382
|
+
def put_uint64(offset,value)
|
1383
|
+
put(:uint64,offset,value)
|
1384
|
+
end
|
1385
|
+
|
1386
|
+
#
|
1387
|
+
# Alias for `put(:short,offset,value)`.
|
1388
|
+
#
|
1389
|
+
# @param [Integer] offset
|
1390
|
+
# The offset of the `short` within the buffer.
|
1391
|
+
#
|
1392
|
+
# @param [Integer] value
|
1393
|
+
# The `short` value to write into the buffer.
|
1394
|
+
#
|
1395
|
+
# @return [self]
|
1396
|
+
#
|
1397
|
+
# @see #put
|
1398
|
+
#
|
1399
|
+
def put_short(offset,value)
|
1400
|
+
put(:short,offset,value)
|
1401
|
+
end
|
1402
|
+
|
1403
|
+
#
|
1404
|
+
# Alias for `put(:int,offset,value)`.
|
1405
|
+
#
|
1406
|
+
# @param [Integer] offset
|
1407
|
+
# The offset of the `int` within the buffer.
|
1408
|
+
#
|
1409
|
+
# @param [Integer] value
|
1410
|
+
# The `int` value to write into the buffer.
|
1411
|
+
#
|
1412
|
+
# @return [self]
|
1413
|
+
#
|
1414
|
+
# @see #put
|
1415
|
+
#
|
1416
|
+
def put_int(offset,value)
|
1417
|
+
put(:int,offset,value)
|
1418
|
+
end
|
1419
|
+
|
1420
|
+
#
|
1421
|
+
# Alias for `put(:long,offset,value)`.
|
1422
|
+
#
|
1423
|
+
# @param [Integer] offset
|
1424
|
+
# The offset of the `long` within the buffer.
|
1425
|
+
#
|
1426
|
+
# @param [Integer] value
|
1427
|
+
# The `long` value to write into the buffer.
|
1428
|
+
#
|
1429
|
+
# @return [self]
|
1430
|
+
#
|
1431
|
+
# @see #put
|
1432
|
+
#
|
1433
|
+
def put_long(offset,value)
|
1434
|
+
put(:long,offset,value)
|
1435
|
+
end
|
1436
|
+
|
1437
|
+
#
|
1438
|
+
# Alias for `put(:long_long,offset,value)`.
|
1439
|
+
#
|
1440
|
+
# @param [Integer] offset
|
1441
|
+
# The offset of the `long_long` within the buffer.
|
1442
|
+
#
|
1443
|
+
# @param [Integer] value
|
1444
|
+
# The `long_long` value to write into the buffer.
|
1445
|
+
#
|
1446
|
+
# @return [self]
|
1447
|
+
#
|
1448
|
+
# @see #put
|
1449
|
+
#
|
1450
|
+
def put_long_long(offset,value)
|
1451
|
+
put(:long_long,offset,value)
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
#
|
1455
|
+
# Alias for `put(:ushort,offset,value)`.
|
1456
|
+
#
|
1457
|
+
# @param [Integer] offset
|
1458
|
+
# The offset of the `ushort` within the buffer.
|
1459
|
+
#
|
1460
|
+
# @param [Integer] value
|
1461
|
+
# The `ushort` value to write into the buffer.
|
1462
|
+
#
|
1463
|
+
# @return [self]
|
1464
|
+
#
|
1465
|
+
# @see #put
|
1466
|
+
#
|
1467
|
+
def put_ushort(offset,value)
|
1468
|
+
put(:ushort,offset,value)
|
1469
|
+
end
|
1470
|
+
|
1471
|
+
#
|
1472
|
+
# Alias for `put(:uint,offset,value)`.
|
1473
|
+
#
|
1474
|
+
# @param [Integer] offset
|
1475
|
+
# The offset of the `uint` within the buffer.
|
1476
|
+
#
|
1477
|
+
# @param [Integer] value
|
1478
|
+
# The `uint` value to write into the buffer.
|
1479
|
+
#
|
1480
|
+
# @return [self]
|
1481
|
+
#
|
1482
|
+
# @see #put
|
1483
|
+
#
|
1484
|
+
def put_uint(offset,value)
|
1485
|
+
put(:uint,offset,value)
|
1486
|
+
end
|
1487
|
+
|
1488
|
+
#
|
1489
|
+
# Alias for `put(:ulong,offset,value)`.
|
1490
|
+
#
|
1491
|
+
# @param [Integer] offset
|
1492
|
+
# The offset of the `ulong` within the buffer.
|
1493
|
+
#
|
1494
|
+
# @param [Integer] value
|
1495
|
+
# The `ulong` value to write into the buffer.
|
1496
|
+
#
|
1497
|
+
# @return [self]
|
1498
|
+
#
|
1499
|
+
# @see #put
|
1500
|
+
#
|
1501
|
+
def put_ulong(offset,value)
|
1502
|
+
put(:ulong,offset,value)
|
1503
|
+
end
|
1504
|
+
|
1505
|
+
#
|
1506
|
+
# Alias for `put(:ulong_long,offset,value)`.
|
1507
|
+
#
|
1508
|
+
# @param [Integer] offset
|
1509
|
+
# The offset of the `ulong_long` within the buffer.
|
1510
|
+
#
|
1511
|
+
# @param [Integer] value
|
1512
|
+
# The `ulong_long` value to write into the buffer.
|
1513
|
+
#
|
1514
|
+
# @return [self]
|
1515
|
+
#
|
1516
|
+
# @see #put
|
1517
|
+
#
|
1518
|
+
def put_ulong_long(offset,value)
|
1519
|
+
put(:ulong_long,offset,value)
|
1520
|
+
end
|
1521
|
+
|
1522
|
+
#
|
1523
|
+
# Alias for `put(:float32,offset,value)`.
|
1524
|
+
#
|
1525
|
+
# @param [Integer] offset
|
1526
|
+
# The offset of the `float32` within the buffer.
|
1527
|
+
#
|
1528
|
+
# @param [Float] value
|
1529
|
+
# The `float32` value to write into the buffer.
|
1530
|
+
#
|
1531
|
+
# @return [self]
|
1532
|
+
#
|
1533
|
+
# @see #put
|
1534
|
+
#
|
1535
|
+
def put_float32(offset,value)
|
1536
|
+
put(:float32,offset,value)
|
1537
|
+
end
|
1538
|
+
|
1539
|
+
#
|
1540
|
+
# Alias for `put(:float64,offset,value)`.
|
1541
|
+
#
|
1542
|
+
# @param [Integer] offset
|
1543
|
+
# The offset of the `float64` within the buffer.
|
1544
|
+
#
|
1545
|
+
# @param [Float] value
|
1546
|
+
# The `float64` value to write into the buffer.
|
1547
|
+
#
|
1548
|
+
# @return [self]
|
1549
|
+
#
|
1550
|
+
# @see #put
|
1551
|
+
#
|
1552
|
+
def put_float64(offset,value)
|
1553
|
+
put(:float64,offset,value)
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
#
|
1557
|
+
# Alias for `put(:float,offset,value)`.
|
1558
|
+
#
|
1559
|
+
# @param [Integer] offset
|
1560
|
+
# The offset of the `float` within the buffer.
|
1561
|
+
#
|
1562
|
+
# @param [Float] value
|
1563
|
+
# The `float` value to write into the buffer.
|
1564
|
+
#
|
1565
|
+
# @return [self]
|
1566
|
+
#
|
1567
|
+
# @see #put
|
1568
|
+
#
|
1569
|
+
def put_float(offset,value)
|
1570
|
+
put(:float,offset,value)
|
1571
|
+
end
|
1572
|
+
|
1573
|
+
#
|
1574
|
+
# Alias for `put(:double,offset,value)`.
|
1575
|
+
#
|
1576
|
+
# @param [Integer] offset
|
1577
|
+
# The offset of the `double` within the buffer.
|
1578
|
+
#
|
1579
|
+
# @param [Float] value
|
1580
|
+
# The `double` value to write into the buffer.
|
1581
|
+
#
|
1582
|
+
# @return [self]
|
1583
|
+
#
|
1584
|
+
# @see #put
|
1585
|
+
#
|
1586
|
+
def put_double(offset,value)
|
1587
|
+
put(:double,offset,value)
|
1588
|
+
end
|
1589
|
+
|
1590
|
+
#
|
1591
|
+
# Writes an array of the given type, to the given offset within the
|
1592
|
+
# buffer.
|
1593
|
+
#
|
1594
|
+
# @param [Symbol] type
|
1595
|
+
# The type of the value to write.
|
1596
|
+
#
|
1597
|
+
# @param [Integer] offset
|
1598
|
+
# The offset that the array should start at within the buffer.
|
1599
|
+
#
|
1600
|
+
# @param [::Array<Object>] array
|
1601
|
+
# The array of values to write.
|
1602
|
+
#
|
1603
|
+
# @return [self]
|
1604
|
+
#
|
1605
|
+
def put_array_of(type,offset,array)
|
1606
|
+
type = @type_system[type]
|
1607
|
+
array_type = type[array.length]
|
1608
|
+
|
1609
|
+
if (offset < 0 || offset+array_type.size > size)
|
1610
|
+
raise(IndexError,"offset #{offset} or size #{array_type.size} is out of bounds: 0...#{size-type.size}")
|
1611
|
+
end
|
1612
|
+
|
1613
|
+
data = array_type.pack(array)
|
1614
|
+
|
1615
|
+
@string[offset,array_type.size] = data
|
1616
|
+
return self
|
1617
|
+
end
|
1618
|
+
|
1619
|
+
#
|
1620
|
+
# Alias to `put_array_of(:byte,offset,bytes)`.
|
1621
|
+
#
|
1622
|
+
# @param [Integer] offset
|
1623
|
+
# The offset within the buffer to start reading at.
|
1624
|
+
#
|
1625
|
+
# @param [::Array<Integer>] bytes
|
1626
|
+
# The array of bytes to write.
|
1627
|
+
#
|
1628
|
+
# @return [self]
|
1629
|
+
#
|
1630
|
+
# @see #put_array_of
|
1631
|
+
#
|
1632
|
+
def put_array_of_byte(offset,bytes)
|
1633
|
+
put_array_of(:byte,offset,bytes)
|
1634
|
+
end
|
1635
|
+
|
1636
|
+
alias put_bytes put_array_of_byte
|
1637
|
+
|
1638
|
+
#
|
1639
|
+
# Alias to `put_array_of(:char,offset,bytes)`.
|
1640
|
+
#
|
1641
|
+
# @param [Integer] offset
|
1642
|
+
# The offset within the buffer to start reading at.
|
1643
|
+
#
|
1644
|
+
# @param [String] chars
|
1645
|
+
# The array of characters to write.
|
1646
|
+
#
|
1647
|
+
# @return [self]
|
1648
|
+
#
|
1649
|
+
# @see #put_array_of
|
1650
|
+
#
|
1651
|
+
def put_array_of_char(offset,chars)
|
1652
|
+
put_array_of(:char,offset,chars)
|
1653
|
+
end
|
1654
|
+
|
1655
|
+
alias put_chars put_array_of_char
|
1656
|
+
|
1657
|
+
#
|
1658
|
+
# Alias to `put_array_of(:uchar,offset,bytes)`.
|
1659
|
+
#
|
1660
|
+
# @param [Integer] offset
|
1661
|
+
# The offset within the buffer to start reading at.
|
1662
|
+
#
|
1663
|
+
# @param [String] chars
|
1664
|
+
# The array of unsigned characters to write.
|
1665
|
+
#
|
1666
|
+
# @return [self]
|
1667
|
+
#
|
1668
|
+
# @see #put_array_of
|
1669
|
+
#
|
1670
|
+
def put_array_of_uchar(offset,chars)
|
1671
|
+
put_array_of(:uchar,offset,chars)
|
1672
|
+
end
|
1673
|
+
|
1674
|
+
alias put_uchars put_array_of_uchar
|
1675
|
+
|
1676
|
+
#
|
1677
|
+
# Alias to `put_array_of(:int8,offset,ints)`.
|
1678
|
+
#
|
1679
|
+
# @param [Integer] offset
|
1680
|
+
# The offset within the buffer to start reading at.
|
1681
|
+
#
|
1682
|
+
# @param [::Array<Integer>] ints
|
1683
|
+
# The array of `int8` values to write.
|
1684
|
+
#
|
1685
|
+
# @return [self]
|
1686
|
+
#
|
1687
|
+
# @see #put_array_of
|
1688
|
+
#
|
1689
|
+
def put_array_of_int8(offset,ints)
|
1690
|
+
put_array_of(:int8,offset,ints)
|
1691
|
+
end
|
1692
|
+
|
1693
|
+
#
|
1694
|
+
# Alias to `put_array_of(:int16,offset,ints)`.
|
1695
|
+
#
|
1696
|
+
# @param [Integer] offset
|
1697
|
+
# The offset within the buffer to start reading at.
|
1698
|
+
#
|
1699
|
+
# @param [::Array<Integer>] ints
|
1700
|
+
# The array of `int16` values to write.
|
1701
|
+
#
|
1702
|
+
# @return [self]
|
1703
|
+
#
|
1704
|
+
# @see #put_array_of
|
1705
|
+
#
|
1706
|
+
def put_array_of_int16(offset,ints)
|
1707
|
+
put_array_of(:int16,offset,ints)
|
1708
|
+
end
|
1709
|
+
|
1710
|
+
#
|
1711
|
+
# Alias to `put_array_of(:int32,offset,ints)`.
|
1712
|
+
#
|
1713
|
+
# @param [Integer] offset
|
1714
|
+
# The offset within the buffer to start reading at.
|
1715
|
+
#
|
1716
|
+
# @param [::Array<Integer>] ints
|
1717
|
+
# The array of `int32` values to write.
|
1718
|
+
#
|
1719
|
+
# @return [self]
|
1720
|
+
#
|
1721
|
+
# @see #put_array_of
|
1722
|
+
#
|
1723
|
+
def put_array_of_int32(offset,ints)
|
1724
|
+
put_array_of(:int32,offset,ints)
|
1725
|
+
end
|
1726
|
+
|
1727
|
+
#
|
1728
|
+
# Alias to `put_array_of(:int64,offset,ints)`.
|
1729
|
+
#
|
1730
|
+
# @param [Integer] offset
|
1731
|
+
# The offset within the buffer to start reading at.
|
1732
|
+
#
|
1733
|
+
# @param [::Array<Integer>] ints
|
1734
|
+
# The array of `int64` values to write.
|
1735
|
+
#
|
1736
|
+
# @return [self]
|
1737
|
+
#
|
1738
|
+
# @see #put_array_of
|
1739
|
+
#
|
1740
|
+
def put_array_of_int64(offset,ints)
|
1741
|
+
put_array_of(:int64,offset,ints)
|
1742
|
+
end
|
1743
|
+
|
1744
|
+
#
|
1745
|
+
# Alias to `put_array_of(:uint8,offset,uints)`.
|
1746
|
+
#
|
1747
|
+
# @param [Integer] offset
|
1748
|
+
# The offset within the buffer to start reading at.
|
1749
|
+
#
|
1750
|
+
# @param [::Array<Integer>] uints
|
1751
|
+
# The array of `uint8` values to write.
|
1752
|
+
#
|
1753
|
+
# @return [self]
|
1754
|
+
#
|
1755
|
+
# @see #put_array_of
|
1756
|
+
#
|
1757
|
+
def put_array_of_uint8(offset,uints)
|
1758
|
+
put_array_of(:uint8,offset,uints)
|
1759
|
+
end
|
1760
|
+
|
1761
|
+
#
|
1762
|
+
# Alias to `put_array_of(:uint16,offset,uints)`.
|
1763
|
+
#
|
1764
|
+
# @param [Integer] offset
|
1765
|
+
# The offset within the buffer to start reading at.
|
1766
|
+
#
|
1767
|
+
# @param [::Array<Integer>] uints
|
1768
|
+
# The array of `uint16` values to write.
|
1769
|
+
#
|
1770
|
+
# @return [self]
|
1771
|
+
#
|
1772
|
+
# @see #put_array_of
|
1773
|
+
#
|
1774
|
+
def put_array_of_uint16(offset,uints)
|
1775
|
+
put_array_of(:uint16,offset,uints)
|
1776
|
+
end
|
1777
|
+
|
1778
|
+
#
|
1779
|
+
# Alias to `put_array_of(:uint32,offset,uints)`.
|
1780
|
+
#
|
1781
|
+
# @param [Integer] offset
|
1782
|
+
# The offset within the buffer to start reading at.
|
1783
|
+
#
|
1784
|
+
# @param [::Array<Integer>] uints
|
1785
|
+
# The array of `uint32` values to write.
|
1786
|
+
#
|
1787
|
+
# @return [self]
|
1788
|
+
#
|
1789
|
+
# @see #put_array_of
|
1790
|
+
#
|
1791
|
+
def put_array_of_uint32(offset,uints)
|
1792
|
+
put_array_of(:uint32,offset,uints)
|
1793
|
+
end
|
1794
|
+
|
1795
|
+
#
|
1796
|
+
# Alias to `put_array_of(:uint64,offset,uints)`.
|
1797
|
+
#
|
1798
|
+
# @param [Integer] offset
|
1799
|
+
# The offset within the buffer to start reading at.
|
1800
|
+
#
|
1801
|
+
# @param [::Array<Integer>] uints
|
1802
|
+
# The array of `uint64` values to write.
|
1803
|
+
#
|
1804
|
+
# @return [self]
|
1805
|
+
#
|
1806
|
+
# @see #put_array_of
|
1807
|
+
#
|
1808
|
+
def put_array_of_uint64(offset,uints)
|
1809
|
+
put_array_of(:uint64,offset,uints)
|
1810
|
+
end
|
1811
|
+
|
1812
|
+
#
|
1813
|
+
# Alias to `put_array_of(:short,offset,ints)`.
|
1814
|
+
#
|
1815
|
+
# @param [Integer] offset
|
1816
|
+
# The offset within the buffer to start reading at.
|
1817
|
+
#
|
1818
|
+
# @param [::Array<Integer>] ints
|
1819
|
+
# The array of `short` values to write.
|
1820
|
+
#
|
1821
|
+
# @return [self]
|
1822
|
+
#
|
1823
|
+
# @see #put_array_of
|
1824
|
+
#
|
1825
|
+
def put_array_of_short(offset,ints)
|
1826
|
+
put_array_of(:short,offset,ints)
|
1827
|
+
end
|
1828
|
+
|
1829
|
+
#
|
1830
|
+
# Alias to `put_array_of(:int,offset,ints)`.
|
1831
|
+
#
|
1832
|
+
# @param [Integer] offset
|
1833
|
+
# The offset within the buffer to start reading at.
|
1834
|
+
#
|
1835
|
+
# @param [::Array<Integer>] ints
|
1836
|
+
# The array of `int` values to write.
|
1837
|
+
#
|
1838
|
+
# @return [self]
|
1839
|
+
#
|
1840
|
+
# @see #put_array_of
|
1841
|
+
#
|
1842
|
+
def put_array_of_int(offset,ints)
|
1843
|
+
put_array_of(:int,offset,ints)
|
1844
|
+
end
|
1845
|
+
|
1846
|
+
alias put_ints put_array_of_int
|
1847
|
+
|
1848
|
+
#
|
1849
|
+
# Alias to `put_array_of(:long,offset,ints)`.
|
1850
|
+
#
|
1851
|
+
# @param [Integer] offset
|
1852
|
+
# The offset within the buffer to start reading at.
|
1853
|
+
#
|
1854
|
+
# @param [::Array<Integer>] ints
|
1855
|
+
# The array of `long` values to write.
|
1856
|
+
#
|
1857
|
+
# @return [self]
|
1858
|
+
#
|
1859
|
+
# @see #put_array_of
|
1860
|
+
#
|
1861
|
+
def put_array_of_long(offset,ints)
|
1862
|
+
put_array_of(:long,offset,ints)
|
1863
|
+
end
|
1864
|
+
|
1865
|
+
#
|
1866
|
+
# Alias to `put_array_of(:long_long,offset,ints)`.
|
1867
|
+
#
|
1868
|
+
# @param [Integer] offset
|
1869
|
+
# The offset within the buffer to start reading at.
|
1870
|
+
#
|
1871
|
+
# @param [::Array<Integer>] ints
|
1872
|
+
# The array of `long_long` values to write.
|
1873
|
+
#
|
1874
|
+
# @return [self]
|
1875
|
+
#
|
1876
|
+
# @see #put_array_of
|
1877
|
+
#
|
1878
|
+
def put_array_of_long_long(offset,ints)
|
1879
|
+
put_array_of(:long_long,offset,ints)
|
1880
|
+
end
|
1881
|
+
|
1882
|
+
#
|
1883
|
+
# Alias to `put_array_of(:ushort,offset,uints)`.
|
1884
|
+
#
|
1885
|
+
# @param [Integer] offset
|
1886
|
+
# The offset within the buffer to start reading at.
|
1887
|
+
#
|
1888
|
+
# @param [::Array<Integer>] uints
|
1889
|
+
# The array of `ushort` values to write.
|
1890
|
+
#
|
1891
|
+
# @return [self]
|
1892
|
+
#
|
1893
|
+
# @see #put_array_of
|
1894
|
+
#
|
1895
|
+
def put_array_of_ushort(offset,uints)
|
1896
|
+
put_array_of(:ushort,offset,uints)
|
1897
|
+
end
|
1898
|
+
|
1899
|
+
#
|
1900
|
+
# Alias to `put_array_of(:uint,offset,uints)`.
|
1901
|
+
#
|
1902
|
+
# @param [Integer] offset
|
1903
|
+
# The offset within the buffer to start reading at.
|
1904
|
+
#
|
1905
|
+
# @param [::Array<Integer>] uints
|
1906
|
+
# The array of `uint` values to write.
|
1907
|
+
#
|
1908
|
+
# @return [self]
|
1909
|
+
#
|
1910
|
+
# @see #put_array_of
|
1911
|
+
#
|
1912
|
+
def put_array_of_uint(offset,uints)
|
1913
|
+
put_array_of(:uint,offset,uints)
|
1914
|
+
end
|
1915
|
+
|
1916
|
+
alias put_uints put_array_of_uint
|
1917
|
+
|
1918
|
+
#
|
1919
|
+
# Alias to `put_array_of(:ulong,offset,uints)`.
|
1920
|
+
#
|
1921
|
+
# @param [Integer] offset
|
1922
|
+
# The offset within the buffer to start reading at.
|
1923
|
+
#
|
1924
|
+
# @param [::Array<Integer>] uints
|
1925
|
+
# The array of `ulong` values to write.
|
1926
|
+
#
|
1927
|
+
# @return [self]
|
1928
|
+
#
|
1929
|
+
# @see #put_array_of
|
1930
|
+
#
|
1931
|
+
def put_array_of_ulong(offset,uints)
|
1932
|
+
put_array_of(:ulong,offset,uints)
|
1933
|
+
end
|
1934
|
+
|
1935
|
+
#
|
1936
|
+
# Alias to `put_array_of(:ulong_long,offset,uints)`.
|
1937
|
+
#
|
1938
|
+
# @param [Integer] offset
|
1939
|
+
# The offset within the buffer to start reading at.
|
1940
|
+
#
|
1941
|
+
# @param [::Array<Integer>] uints
|
1942
|
+
# The array of `ulong_long` values to write.
|
1943
|
+
#
|
1944
|
+
# @return [self]
|
1945
|
+
#
|
1946
|
+
# @see #put_array_of
|
1947
|
+
#
|
1948
|
+
def put_array_of_ulong_long(offset,uints)
|
1949
|
+
put_array_of(:ulong_long,offset,uints)
|
1950
|
+
end
|
1951
|
+
|
1952
|
+
#
|
1953
|
+
# Alias to `put_array_of(:float32,offset,floats)`.
|
1954
|
+
#
|
1955
|
+
# @param [Integer] offset
|
1956
|
+
# The offset within the buffer to start reading at.
|
1957
|
+
#
|
1958
|
+
# @param [::Array<Float>] floats
|
1959
|
+
# The array of `float32` values to write.
|
1960
|
+
#
|
1961
|
+
# @return [self]
|
1962
|
+
#
|
1963
|
+
# @see #put_array_of
|
1964
|
+
#
|
1965
|
+
def put_array_of_float32(offset,floats)
|
1966
|
+
put_array_of(:float32,offset,floats)
|
1967
|
+
end
|
1968
|
+
|
1969
|
+
#
|
1970
|
+
# Alias to `put_array_of(:float64,offset,floats)`.
|
1971
|
+
#
|
1972
|
+
# @param [Integer] offset
|
1973
|
+
# The offset within the buffer to start reading at.
|
1974
|
+
#
|
1975
|
+
# @param [::Array<Float>] floats
|
1976
|
+
# The array of `float64` values to write.
|
1977
|
+
#
|
1978
|
+
# @return [self]
|
1979
|
+
#
|
1980
|
+
# @see #put_array_of
|
1981
|
+
#
|
1982
|
+
def put_array_of_float64(offset,floats)
|
1983
|
+
put_array_of(:float64,offset,floats)
|
1984
|
+
end
|
1985
|
+
|
1986
|
+
#
|
1987
|
+
# Alias to `put_array_of(:float,offset,floats)`.
|
1988
|
+
#
|
1989
|
+
# @param [Integer] offset
|
1990
|
+
# The offset within the buffer to start reading at.
|
1991
|
+
#
|
1992
|
+
# @param [::Array<Float>] floats
|
1993
|
+
# The array of `float` values to write.
|
1994
|
+
#
|
1995
|
+
# @return [self]
|
1996
|
+
#
|
1997
|
+
# @see #put_array_of
|
1998
|
+
#
|
1999
|
+
def put_array_of_float(offset,floats)
|
2000
|
+
put_array_of(:float,offset,floats)
|
2001
|
+
end
|
2002
|
+
|
2003
|
+
alias put_floats put_array_of_float
|
2004
|
+
|
2005
|
+
#
|
2006
|
+
# Alias to `put_array_of(:double,offset,floats)`.
|
2007
|
+
#
|
2008
|
+
# @param [Integer] offset
|
2009
|
+
# The offset within the buffer to start reading at.
|
2010
|
+
#
|
2011
|
+
# @param [::Array<Float>] floats
|
2012
|
+
# The array of `double` values to write.
|
2013
|
+
#
|
2014
|
+
# @return [self]
|
2015
|
+
#
|
2016
|
+
# @see #put_array_of
|
2017
|
+
#
|
2018
|
+
def put_array_of_double(offset,floats)
|
2019
|
+
put_array_of(:double,offset,floats)
|
2020
|
+
end
|
2021
|
+
|
2022
|
+
alias put_doubles put_array_of_double
|
2023
|
+
|
2024
|
+
end
|
2025
|
+
end
|
2026
|
+
end
|
2027
|
+
end
|