ronin-support 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +14 -0
  3. data/.rubocop.yml +109 -0
  4. data/ChangeLog.md +12 -1
  5. data/Gemfile +8 -4
  6. data/README.md +1 -1
  7. data/Rakefile +2 -2
  8. data/examples/ssl_proxy.rb +2 -1
  9. data/examples/tcp_proxy.rb +6 -4
  10. data/lib/ronin/support/archive/tar/writer.rb +2 -2
  11. data/lib/ronin/support/archive/tar.rb +4 -4
  12. data/lib/ronin/support/archive/zip/reader.rb +2 -2
  13. data/lib/ronin/support/binary/array.rb +4 -7
  14. data/lib/ronin/support/binary/bit_flip.rb +7 -1
  15. data/lib/ronin/support/binary/buffer.rb +22 -22
  16. data/lib/ronin/support/binary/byte_slice.rb +17 -17
  17. data/lib/ronin/support/binary/cstring.rb +7 -4
  18. data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +4 -0
  19. data/lib/ronin/support/binary/ctypes/arch/arm.rb +3 -0
  20. data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +4 -0
  21. data/lib/ronin/support/binary/ctypes/arch/arm64.rb +3 -0
  22. data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +4 -0
  23. data/lib/ronin/support/binary/ctypes/arch/mips.rb +3 -0
  24. data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +4 -0
  25. data/lib/ronin/support/binary/ctypes/arch/mips64.rb +3 -0
  26. data/lib/ronin/support/binary/ctypes/arch/ppc.rb +3 -0
  27. data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +3 -0
  28. data/lib/ronin/support/binary/ctypes/arch/x86.rb +3 -0
  29. data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +3 -0
  30. data/lib/ronin/support/binary/ctypes/array_type.rb +1 -1
  31. data/lib/ronin/support/binary/ctypes/big_endian.rb +3 -0
  32. data/lib/ronin/support/binary/ctypes/enum_type.rb +2 -2
  33. data/lib/ronin/support/binary/ctypes/little_endian.rb +3 -0
  34. data/lib/ronin/support/binary/ctypes/native.rb +3 -0
  35. data/lib/ronin/support/binary/ctypes/scalar_type.rb +2 -2
  36. data/lib/ronin/support/binary/ctypes/struct_type.rb +3 -3
  37. data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -8
  38. data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +1 -1
  39. data/lib/ronin/support/binary/ctypes/union_type.rb +3 -3
  40. data/lib/ronin/support/binary/ctypes.rb +3 -3
  41. data/lib/ronin/support/binary/memory.rb +2 -2
  42. data/lib/ronin/support/binary/packet.rb +3 -0
  43. data/lib/ronin/support/binary/stack.rb +3 -4
  44. data/lib/ronin/support/binary/struct/member.rb +5 -3
  45. data/lib/ronin/support/binary/struct.rb +81 -79
  46. data/lib/ronin/support/binary/template.rb +1 -0
  47. data/lib/ronin/support/binary/unhexdump/parser.rb +11 -11
  48. data/lib/ronin/support/binary/union.rb +22 -22
  49. data/lib/ronin/support/cli/ansi.rb +0 -1
  50. data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
  51. data/lib/ronin/support/cli/io_shell.rb +4 -4
  52. data/lib/ronin/support/cli/printing.rb +3 -3
  53. data/lib/ronin/support/compression/zlib.rb +1 -1
  54. data/lib/ronin/support/core_ext/enumerable.rb +0 -2
  55. data/lib/ronin/support/core_ext/file.rb +1 -1
  56. data/lib/ronin/support/core_ext/kernel.rb +6 -5
  57. data/lib/ronin/support/core_ext/string.rb +2 -2
  58. data/lib/ronin/support/crypto/cert.rb +11 -15
  59. data/lib/ronin/support/crypto/cert_chain.rb +1 -1
  60. data/lib/ronin/support/crypto/cipher/aes.rb +3 -0
  61. data/lib/ronin/support/crypto/cipher/aes128.rb +4 -1
  62. data/lib/ronin/support/crypto/cipher/aes256.rb +4 -1
  63. data/lib/ronin/support/crypto/cipher.rb +1 -1
  64. data/lib/ronin/support/crypto/core_ext/file.rb +1 -1
  65. data/lib/ronin/support/crypto/key/methods.rb +4 -1
  66. data/lib/ronin/support/crypto/key.rb +5 -2
  67. data/lib/ronin/support/crypto/openssl.rb +1 -1
  68. data/lib/ronin/support/crypto.rb +0 -1
  69. data/lib/ronin/support/encoding/base16.rb +1 -1
  70. data/lib/ronin/support/encoding/base32.rb +28 -17
  71. data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
  72. data/lib/ronin/support/encoding/c.rb +4 -4
  73. data/lib/ronin/support/encoding/hex.rb +2 -2
  74. data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
  75. data/lib/ronin/support/encoding/js.rb +4 -4
  76. data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +2 -2
  77. data/lib/ronin/support/encoding/powershell.rb +4 -5
  78. data/lib/ronin/support/encoding/ruby.rb +4 -4
  79. data/lib/ronin/support/encoding/shell/core_ext/integer.rb +2 -2
  80. data/lib/ronin/support/encoding/shell.rb +3 -3
  81. data/lib/ronin/support/encoding/sql.rb +1 -1
  82. data/lib/ronin/support/encoding/xml.rb +2 -2
  83. data/lib/ronin/support/encoding.rb +95 -0
  84. data/lib/ronin/support/network/asn/list.rb +6 -1
  85. data/lib/ronin/support/network/asn/record.rb +3 -0
  86. data/lib/ronin/support/network/asn/record_set.rb +3 -0
  87. data/lib/ronin/support/network/asn.rb +167 -6
  88. data/lib/ronin/support/network/dns/resolver.rb +3 -0
  89. data/lib/ronin/support/network/domain.rb +21 -21
  90. data/lib/ronin/support/network/email_address.rb +1 -5
  91. data/lib/ronin/support/network/esmtp/mixin.rb +1 -0
  92. data/lib/ronin/support/network/ftp/mixin.rb +1 -1
  93. data/lib/ronin/support/network/host.rb +75 -47
  94. data/lib/ronin/support/network/http/core_ext.rb +1 -1
  95. data/lib/ronin/support/network/http.rb +317 -80
  96. data/lib/ronin/support/network/ip.rb +8 -10
  97. data/lib/ronin/support/network/ip_range/cidr.rb +1 -5
  98. data/lib/ronin/support/network/ip_range/glob.rb +1 -0
  99. data/lib/ronin/support/network/ip_range/range.rb +1 -1
  100. data/lib/ronin/support/network/ip_range.rb +1 -3
  101. data/lib/ronin/support/network/proxy.rb +4 -4
  102. data/lib/ronin/support/network/public_suffix/list.rb +10 -8
  103. data/lib/ronin/support/network/public_suffix/suffix_set.rb +3 -0
  104. data/lib/ronin/support/network/public_suffix.rb +9 -4
  105. data/lib/ronin/support/network/smtp/email.rb +0 -9
  106. data/lib/ronin/support/network/smtp/mixin.rb +2 -2
  107. data/lib/ronin/support/network/ssl/local_cert.rb +1 -3
  108. data/lib/ronin/support/network/ssl/mixin.rb +13 -13
  109. data/lib/ronin/support/network/ssl/openssl.rb +1 -1
  110. data/lib/ronin/support/network/ssl/proxy.rb +14 -16
  111. data/lib/ronin/support/network/ssl.rb +4 -2
  112. data/lib/ronin/support/network/tcp/proxy.rb +3 -3
  113. data/lib/ronin/support/network/tcp.rb +10 -12
  114. data/lib/ronin/support/network/telnet/mixin.rb +14 -14
  115. data/lib/ronin/support/network/tld/list.rb +2 -1
  116. data/lib/ronin/support/network/tld.rb +7 -4
  117. data/lib/ronin/support/network/tls/proxy.rb +1 -1
  118. data/lib/ronin/support/network/tls.rb +0 -2
  119. data/lib/ronin/support/network/udp/proxy.rb +5 -5
  120. data/lib/ronin/support/network/udp.rb +14 -16
  121. data/lib/ronin/support/path.rb +3 -3
  122. data/lib/ronin/support/text/erb/mixin.rb +3 -0
  123. data/lib/ronin/support/text/homoglyph/table.rb +3 -3
  124. data/lib/ronin/support/text/patterns/credentials.rb +2 -2
  125. data/lib/ronin/support/text/patterns/crypto.rb +1 -1
  126. data/lib/ronin/support/text/patterns/file_system.rb +3 -4
  127. data/lib/ronin/support/text/patterns/network.rb +10 -10
  128. data/lib/ronin/support/text/patterns/numeric.rb +1 -1
  129. data/lib/ronin/support/text/patterns/source_code.rb +2 -2
  130. data/lib/ronin/support/text/random.rb +2 -2
  131. data/lib/ronin/support/text/typo/generator.rb +2 -2
  132. data/lib/ronin/support/version.rb +1 -1
  133. data/ronin-support.gemspec +6 -5
  134. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b487230c13b8458ad2f063e60e872f35f6262b14921d7f76050647e94aced0a3
4
- data.tar.gz: 6bfe1e1bc33c1694070529fe6d622cc745f370cc8afc688fb62bb262cf71e550
3
+ metadata.gz: e4a9cca292661aabc9b8b8360bef73af12a140bac7b80bbe969671a78d5c4cb8
4
+ data.tar.gz: cb8920fa647c56bcf03c9a4b5796f6e58fd732d82ea79027bce10d77246f1af6
5
5
  SHA512:
6
- metadata.gz: a928c76fae066768a23621ac2cf1c1c746e034c2d16d141a2f4275bed0dc24ec24556fc8226d3e8fc6cdcf7990528c35850477bf266fa9cfe85d38b3f0898ec4
7
- data.tar.gz: 424f6d0b54160808cd43a4dee8f553830182fddb345b80708cc654e2a5df19d0225c1b0076df17fbb64425824a695c72e32f41601625450977b0eea62738df21
6
+ metadata.gz: '04831026ac5813990e5db208ac229f707f24cfb0bcff277ff0da70eecdce58b379925ed944b5377ead08ac63f7e6fce0a323bcfe05a4a617a6d0cfa5987ec90b'
7
+ data.tar.gz: ed25a967fe35242afdb9a9d2e3dc8dff096de0e7737494100b6a54c96f67c4288d2ff21ab2e6eadce4f07fe6284037e454e37498ae1b108dfeda024b115bf26b
@@ -26,3 +26,17 @@ jobs:
26
26
  run: bundle install --jobs 4 --retry 3
27
27
  - name: Run tests
28
28
  run: bundle exec rake test
29
+
30
+ # rubocop linting
31
+ rubocop:
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v2
35
+ - name: Set up Ruby
36
+ uses: ruby/setup-ruby@v1
37
+ with:
38
+ ruby-version: 3.0
39
+ - name: Install dependencies
40
+ run: bundle install --jobs 4 --retry 3
41
+ - name: Run rubocop
42
+ run: bundle exec rubocop --parallel
data/.rubocop.yml ADDED
@@ -0,0 +1,109 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ TargetRubyVersion: 3.1
5
+
6
+ inherit_gem:
7
+ rubocop-ronin: rubocop.yml
8
+
9
+ Style/CommentedKeyword: { Enabled: false }
10
+ Style/ArgumentsForwarding: { Enabled: false }
11
+ Style/WhileUntilModifier: { Enabled: false }
12
+
13
+ #
14
+ # ronin-support specific exceptions
15
+ #
16
+
17
+ # it makes sense to use octal numbers when testing the file's mode
18
+ Style/NumericLiteralPrefix:
19
+ Exclude:
20
+ - 'lib/ronin/support/archive/tar/writer.rb'
21
+ - 'lib/ronin/support/network/ssl/local_key.rb'
22
+ - 'lib/ronin/support/network/ssl/local_cert.rb'
23
+ - 'spec/archive/tar/writer_spec.rb'
24
+ - 'spec/network/ssl/local_cert_spec.rb'
25
+ - 'spec/network/ssl/local_key_spec.rb'
26
+
27
+ # in certain specs we need to use an empty block
28
+ Lint/EmptyBlock:
29
+ Exclude:
30
+ - 'spec/archive/zip/reader_spec.rb'
31
+ - 'spec/network/proxy_spec.rb'
32
+
33
+ Lint/RaiseException:
34
+ Exclude:
35
+ - 'spec/core_ext/kernel_spec.rb'
36
+
37
+ # the arrays of Floats need to be organized into rows of columns
38
+ Layout/ArrayAlignment:
39
+ Exclude:
40
+ - 'spec/binary/unhexdump/parser_spec.rb'
41
+
42
+ # the arrays of Floats need to be organized into rows of columns
43
+ Layout/ExtraSpacing:
44
+ Exclude:
45
+ - 'spec/binary/unhexdump/parser_spec.rb'
46
+
47
+ # make an exception for required block keyword arguments.
48
+ Layout/SpaceAroundBlockParameters:
49
+ Exclude:
50
+ - 'spec/binary/unhexdump/parser_spec.rb'
51
+
52
+ # robucop mistakes :x86_64 for a "symbol number"
53
+ Naming/VariableNumber:
54
+ AllowedIdentifiers:
55
+ - x86_64
56
+ # OpenSSL TLS version symbols
57
+ - TLSv1
58
+ - TLSv1_1
59
+ - TLSv1_2
60
+
61
+ # rubocop does not support constants that contain multiple numbers
62
+ Naming/ClassAndModuleCamelCase:
63
+ AllowedNames:
64
+ - X86_64
65
+
66
+ # we need to test Ronin::Support::Binary::CString#+ does not modify itself
67
+ Lint/Void:
68
+ Exclude:
69
+ - 'spec/binary/cstring_spec.rb'
70
+
71
+ Style/Documentation:
72
+ Exclude:
73
+ # ignore top-level documentation for core-ext classes
74
+ - 'lib/ronin/support/**/core_ext/**/*.rb'
75
+ # BUG: Ronin::Support::Crypto is already documented in lib/ronin/support/crypto.rb
76
+ - 'lib/ronin/support/crypto/cert.rb'
77
+ # BUG: Ronin::Support::Binary is already documented in lib/ronin/support/binary.rb
78
+ - 'lib/ronin/support/binary/struct.rb'
79
+
80
+ Naming/MethodParameterName:
81
+ AllowedNames:
82
+ - n
83
+ - id
84
+ - ip
85
+ - io
86
+ - iv
87
+ - os
88
+ - to
89
+
90
+ # prefer to keep `self.user_agent` a method
91
+ Style/TrivialAccessors:
92
+ Exclude:
93
+ - 'lib/ronin/support/network/http.rb'
94
+
95
+ # we need to redefine the public-key component methods as public
96
+ Lint/UselessMethodDefinition:
97
+ Exclude:
98
+ - 'lib/ronin/support/crypto/key/dh.rb'
99
+ - 'lib/ronin/support/crypto/key/dsa.rb'
100
+ - 'lib/ronin/support/crypto/key/rsa.rb'
101
+
102
+ Naming/BinaryOperatorParameterName:
103
+ Exclude:
104
+ - 'lib/ronin/support/binary/memory.rb'
105
+
106
+ # Kernel#try explicitly rescues all exceptions
107
+ Lint/RescueException:
108
+ Exclude:
109
+ - 'lib/ronin/support/core_ext/kernel.rb'
data/ChangeLog.md CHANGED
@@ -1,4 +1,15 @@
1
- ### 1.0.0 / 2023-XX-XX
1
+ ### 1.0.1 / 2023-03-01
2
+
3
+ * {Ronin::Support::Network::HTTP.connect_uri} can now infer when to enable
4
+ SSL/TLS from the given URI.
5
+ * {Ronin::Support::Network::HTTP.connect_uri} can now use the `user` and
6
+ `password` information from the given URI.
7
+ * All {Ronin::Support::Network::HTTP} class methods which accept URI objects
8
+ can now accept URLs with International Domain Names (IDN).
9
+ * Changed {Kernel#try} to not silently ignore `SyntaxError` exceptions.
10
+ * Documentation improvements.
11
+
12
+ ### 1.0.0 / 2023-02-01
2
13
 
3
14
  * Added {File.aes_encrypt}.
4
15
  * Added {File.aes_decrypt}.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
@@ -6,10 +8,10 @@ gem 'jruby-openssl', '~> 0.7', platforms: :jruby
6
8
 
7
9
  gem 'net-telnet', '~> 0.1', group: :net
8
10
  if RUBY_VERSION >= '3.1.0'
9
- gem 'net-ftp', '~> 0.1', group: :net, platform: :mri
10
- gem 'net-smtp', '~> 0.1', group: :net, platform: :mri
11
- gem 'net-pop', '~> 0.1', group: :net, platform: :mri
12
- gem 'net-imap', '~> 0.1', group: :net, platform: :mri
11
+ gem 'net-ftp', '~> 0.1', group: :net
12
+ gem 'net-smtp', '~> 0.1', group: :net
13
+ gem 'net-pop', '~> 0.1', group: :net
14
+ gem 'net-imap', '~> 0.1', group: :net
13
15
  end
14
16
 
15
17
  group :development do
@@ -27,4 +29,6 @@ group :development do
27
29
  gem 'dead_end', require: false
28
30
  gem 'sord', require: false, platform: :mri
29
31
  gem 'stackprof', require: false, platform: :mri
32
+ gem 'rubocop', require: false, platform: :mri
33
+ gem 'rubocop-ronin', require: false, platform: :mri
30
34
  end
data/README.md CHANGED
@@ -95,7 +95,7 @@ research and development.
95
95
  * [Regexs for matching/extracting common types of data][docs-text-patterns].
96
96
  * Adds additional methods to many of [Ruby's core classes][docs-core-exts].
97
97
  * Small memory footprint (~46Kb).
98
- * Has 95% documentation coverage.
98
+ * Has 96% documentation coverage.
99
99
  * Has 93% test coverage.
100
100
 
101
101
  ## Synopsis
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require 'rubygems'
1
+ # frozen_string_literal: true
2
2
 
3
3
  begin
4
4
  require 'bundler'
@@ -53,7 +53,7 @@ namespace :public_suffix do
53
53
  list = Ronin::Support::Network::PublicSuffix::List.load_file(
54
54
  'public_suffix_list.dat'
55
55
  )
56
-
56
+
57
57
  regex = list.to_regexp
58
58
 
59
59
  template = 'data/text/patterns/network/public_suffix.rb.erb'
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'ronin/support/network/ssl/proxy'
5
6
 
6
7
  Ronin::Support::Network::SSL::Proxy.start(port: 1337, server: ['example.com', 443]) do |proxy|
7
- address = lambda { |socket|
8
+ address = ->(socket) {
8
9
  addrinfo = socket.peeraddr
9
10
 
10
11
  "#{addrinfo[3]}:#{addrinfo[1]}"
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
 
@@ -6,16 +7,17 @@ require 'ronin/support/network/tcp/proxy'
6
7
  require 'hexdump'
7
8
 
8
9
  Ronin::Support::Network::TCP::Proxy.start(port: 1337, server: ['www.wired.com', 80]) do |proxy|
9
- address = lambda { |socket|
10
+ address = ->(socket) {
10
11
  addrinfo = socket.peeraddr
11
12
 
12
13
  "#{addrinfo[3]}:#{addrinfo[1]}"
13
14
  }
14
- hex = Hexdump::Dumper.new
15
+
16
+ hexdump = Hexdump::Dumper.new
15
17
 
16
18
  proxy.on_client_data do |client,server,data|
17
19
  puts "#{address[client]} -> #{proxy}"
18
- hex.dump(data)
20
+ hexdump.dump(data)
19
21
  end
20
22
 
21
23
  proxy.on_client_connect do |client|
@@ -28,7 +30,7 @@ Ronin::Support::Network::TCP::Proxy.start(port: 1337, server: ['www.wired.com',
28
30
 
29
31
  proxy.on_server_data do |client,server,data|
30
32
  puts "#{address[client]} <- #{proxy}"
31
- hex.dump(data)
33
+ hexdump.dump(data)
32
34
  end
33
35
 
34
36
  proxy.on_server_connect do |client,server|
@@ -122,7 +122,7 @@ module Ronin
122
122
  # @return [self]
123
123
  #
124
124
  # @see https://rubydoc.info/stdlib/rubygems/Gem/Package/TarWriter/RestrictedStream
125
- #
125
+ #
126
126
  def add_file(name,contents=nil, mode: 0644, &block)
127
127
  if contents
128
128
  super(name,mode) do |io|
@@ -154,7 +154,7 @@ module Ronin
154
154
  # @return [self]
155
155
  #
156
156
  # @see https://rubydoc.info/stdlib/rubygems/Gem/Package/TarWriter/BoundedStream
157
- #
157
+ #
158
158
  def allocate_file(name,size, mode: 0644, &block)
159
159
  add_file_simple(name,mode,size,&block)
160
160
  end
@@ -40,20 +40,20 @@ module Ronin
40
40
  # Tar.new(io, mode: 'w') do |tar|
41
41
  # # add a file
42
42
  # tar.add_file('file1.txt', "...")
43
- #
43
+ #
44
44
  # # add a file and open an output stream
45
45
  # tar.add_file('file2.txt') do |io|
46
46
  # io.write("...")
47
47
  # end
48
- #
48
+ #
49
49
  # # add a symlink 'link' pointing to 'file1.txt'
50
50
  # tar.add_symlink('link','file1.txt')
51
- #
51
+ #
52
52
  # # add a directory
53
53
  # tar.mkdir('foo')
54
54
  # end
55
55
  #
56
- # Opening
56
+ # Opening
57
57
  #
58
58
  # @api public
59
59
  #
@@ -183,7 +183,7 @@ module Ronin
183
183
  end
184
184
 
185
185
  private
186
-
186
+
187
187
  #
188
188
  # Creates an `unzip` command with the additional arguments.
189
189
  #
@@ -256,7 +256,7 @@ module Ronin
256
256
  # The parsed statistics.
257
257
  #
258
258
  def parse_statistics_line(line)
259
- length, size, compression, files, _ = line.lstrip.split(/\s+/,5)
259
+ length, size, compression, files, _rest = line.lstrip.split(/\s+/,5)
260
260
 
261
261
  return Statistics.new(
262
262
  length: length.to_i,
@@ -172,16 +172,13 @@ module Ronin
172
172
  def [](index)
173
173
  offset = index * @type.size
174
174
 
175
- if (index < 0 || offset+@type.size > size)
175
+ if (index < 0) || ((offset + @type.size) > size)
176
176
  raise(IndexError,"index #{index} is out of bounds: 0...#{@length}")
177
177
  end
178
178
 
179
179
  case @type
180
180
  when CTypes::ObjectType
181
- @cache[index] ||= (
182
- slice = byteslice(offset,@type.size)
183
- @type.unpack(slice)
184
- )
181
+ @cache[index] ||= @type.unpack(byteslice(offset,@type.size))
185
182
  else
186
183
  data = super(offset,@type.size)
187
184
  @type.unpack(data)
@@ -207,11 +204,11 @@ module Ronin
207
204
  # array[0] = 0x11111111
208
205
  # array[0]
209
206
  # # => 286331153
210
- #
207
+ #
211
208
  def []=(index,value)
212
209
  offset = index * @type.size
213
210
 
214
- if (index < 0 || offset+@type.size > size)
211
+ if (index < 0) || ((offset + @type.size) > size)
215
212
  raise(IndexError,"index #{index} is out of bounds: 0...#{@length}")
216
213
  end
217
214
 
@@ -32,6 +32,9 @@ module Ronin
32
32
  # @api semipublic
33
33
  #
34
34
  module BitFlip
35
+ #
36
+ # Methods for bit-flipping Integers.
37
+ #
35
38
  module Integer
36
39
  #
37
40
  # Enumerates over every bit flip in the integer.
@@ -101,6 +104,9 @@ module Ronin
101
104
  end
102
105
  end
103
106
 
107
+ #
108
+ # Methods for bit-flipping Strings.
109
+ #
104
110
  module String
105
111
  #
106
112
  # Enumerates over every bit flip of every byte in the string.
@@ -127,7 +133,7 @@ module Ronin
127
133
 
128
134
  bits = (0...8)
129
135
 
130
- string.each_byte.each_with_index do |byte,index|
136
+ string.each_byte.with_index do |byte,index|
131
137
  Integer.each_bit_flip(byte,bits) do |flipped_byte|
132
138
  new_string = string.dup
133
139
  new_string.force_encoding(Encoding::ASCII_8BIT)
@@ -203,8 +203,8 @@ module Ronin
203
203
  def get(type,offset)
204
204
  type = @type_system[type]
205
205
 
206
- if (offset < 0 || offset+type.size > size)
207
- raise(IndexError,"offset #{offset} is out of bounds: 0...#{size-type.size}")
206
+ if (offset < 0) || ((offset + type.size) > size)
207
+ raise(IndexError,"offset #{offset} is out of bounds: 0...#{size - type.size}")
208
208
  end
209
209
 
210
210
  data = @string[offset,type.size]
@@ -270,27 +270,27 @@ module Ronin
270
270
  # The read C string, without the null-byte.
271
271
  #
272
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}")
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
277
  end
278
278
 
279
279
  if length
280
280
  substring = @string[offset,length]
281
281
 
282
- if (null_byte = substring.index("\0"))
283
- substring[0...null_byte]
282
+ if (null_byte_index = substring.index("\0"))
283
+ substring[0...null_byte_index]
284
+ else
285
+ substring
284
286
  end
285
287
  else
286
- if (null_byte = @string.index("\0",offset))
287
- substring = @string[offset...null_byte]
288
+ if (null_byte_index = @string.index("\0",offset))
289
+ @string[offset...null_byte_index]
288
290
  else
289
- substring = @string[offset..]
291
+ @string[offset..]
290
292
  end
291
293
  end
292
-
293
- return substring
294
294
  end
295
295
 
296
296
  #
@@ -707,8 +707,8 @@ module Ronin
707
707
  type = @type_system[type]
708
708
  array_type = type[count]
709
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}")
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
712
  end
713
713
 
714
714
  slice = @string[offset,array_type.size]
@@ -1162,8 +1162,8 @@ module Ronin
1162
1162
  def put(type,offset,value)
1163
1163
  type = @type_system[type]
1164
1164
 
1165
- if (offset < 0 || offset+type.size > size)
1166
- raise(IndexError,"offset #{offset} is out of bounds: 0...#{size-type.size}")
1165
+ if (offset < 0) || ((offset + type.size) > size)
1166
+ raise(IndexError,"offset #{offset} is out of bounds: 0...#{size - type.size}")
1167
1167
  end
1168
1168
 
1169
1169
  data = type.pack(value)
@@ -1222,8 +1222,8 @@ module Ronin
1222
1222
  ascii_string = string.encode(Encoding::ASCII_8BIT)
1223
1223
  cstring = "#{ascii_string}\0"
1224
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}")
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
1227
  end
1228
1228
 
1229
1229
  @string[offset,cstring.bytesize] = cstring
@@ -1605,9 +1605,9 @@ module Ronin
1605
1605
  def put_array_of(type,offset,array)
1606
1606
  type = @type_system[type]
1607
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}")
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
1611
  end
1612
1612
 
1613
1613
  data = array_type.pack(array)
@@ -69,15 +69,15 @@ module Ronin
69
69
 
70
70
  case string
71
71
  when ByteSlice
72
- if (offset < 0) || (offset+length > string.bytesize)
72
+ if (offset < 0) || ((offset + length) > string.bytesize)
73
73
  raise(IndexError,"offset #{offset} or length #{length} is out of bounds: 0...#{string.bytesize}")
74
74
  end
75
75
 
76
76
  @string = string.string
77
- @offset = string.offset+offset
77
+ @offset = string.offset + offset
78
78
  @length = length
79
79
  when String
80
- if (offset < 0) || (offset+length > string.bytesize)
80
+ if (offset < 0) || ((offset + length) > string.bytesize)
81
81
  raise(IndexError,"offset #{offset} or length #{length} is out of bounds: 0...#{string.bytesize}")
82
82
  end
83
83
 
@@ -109,17 +109,17 @@ module Ronin
109
109
  when Range
110
110
  range = index_or_range
111
111
 
112
- @string[@offset+range.begin,range.end-range.begin]
112
+ @string[@offset + range.begin,range.end - range.begin]
113
113
  when Integer
114
114
  index = index_or_range
115
115
 
116
116
  case length
117
117
  when Integer
118
- @string[@offset+index,length]
118
+ @string[@offset + index,length]
119
119
  when nil
120
- @string[@offset+index]
120
+ @string[@offset + index]
121
121
  when Float::INFINITY
122
- @string[@offset+index,@length-index]
122
+ @string[@offset + index,@length - index]
123
123
  else
124
124
  raise(ArgumentError,"invalid length (#{length.inspect}) must be an Integer, nil, or Float::INFINITY")
125
125
  end
@@ -151,17 +151,17 @@ module Ronin
151
151
  when Range
152
152
  range = index_or_range
153
153
 
154
- @string[@offset+range.begin,range.end-range.begin] = value
154
+ @string[@offset + range.begin,range.end - range.begin] = value
155
155
  when Integer
156
156
  index = index_or_range
157
157
 
158
158
  case length
159
159
  when Integer
160
- @string[@offset+index,length] = value
160
+ @string[@offset + index,length] = value
161
161
  when nil
162
- @string[@offset+index] = value
162
+ @string[@offset + index] = value
163
163
  when Float::INFINITY
164
- @string[@offset+index,@length-index] = value
164
+ @string[@offset + index,@length - index] = value
165
165
  else
166
166
  raise(ArgumentError,"invalid length (#{length.inspect}) must be an Integer, nil, or Float::INFINITY")
167
167
  end
@@ -200,7 +200,7 @@ module Ronin
200
200
  # found.
201
201
  #
202
202
  def index(substring,offset=0)
203
- if (index = @string.index(substring,@offset+offset))
203
+ if (index = @string.index(substring,@offset + offset))
204
204
  if index < (@offset + @length)
205
205
  index - @offset
206
206
  end
@@ -211,13 +211,13 @@ module Ronin
211
211
  # Gets the byte at the given index within the byte slice.
212
212
  #
213
213
  # @param [Integer] index
214
- #
214
+ #
215
215
  # @return [Integer, nil]
216
216
  # The byte at the given index, or nil if the index is out of bounds.
217
217
  #
218
218
  def getbyte(index)
219
219
  if index < @length
220
- @string.getbyte(@offset+index)
220
+ @string.getbyte(@offset + index)
221
221
  end
222
222
  end
223
223
 
@@ -235,7 +235,7 @@ module Ronin
235
235
  #
236
236
  def setbyte(index,byte)
237
237
  if index < @length
238
- @string.setbyte(@offset+index,byte)
238
+ @string.setbyte(@offset + index,byte)
239
239
  else
240
240
  raise(IndexError,"index #{index.inspect} is out of bounds")
241
241
  end
@@ -257,7 +257,7 @@ module Ronin
257
257
  def each_byte
258
258
  return enum_for(__method__) unless block_given?
259
259
 
260
- (@offset...(@offset+@length)).each do |index|
260
+ (@offset...(@offset + @length)).each do |index|
261
261
  yield @string.getbyte(index)
262
262
  end
263
263
  end
@@ -288,7 +288,7 @@ module Ronin
288
288
  def each_char
289
289
  return enum_for(__method__) unless block_given?
290
290
 
291
- (@offset...(@offset+@length)).each do |index|
291
+ (@offset...(@offset + @length)).each do |index|
292
292
  yield @string[index]
293
293
  end
294
294
  end
@@ -101,14 +101,15 @@ module Ronin
101
101
  # @return [self]
102
102
  #
103
103
  def concat(value)
104
- value = case value
105
- when Integer then value.chr
106
- else value.to_s
107
- end
104
+ value = case value
105
+ when Integer then value.chr
106
+ else value.to_s
107
+ end
108
108
  value_size = value.bytesize
109
109
 
110
110
  unless value.include?(NULL)
111
111
  value = "#{value}#{NULL}"
112
+
112
113
  value_size += 1
113
114
  end
114
115
 
@@ -153,6 +154,7 @@ module Ronin
153
154
 
154
155
  @string.each_char do |char|
155
156
  break if char == NULL
157
+
156
158
  yield char
157
159
  end
158
160
  end
@@ -185,6 +187,7 @@ module Ronin
185
187
 
186
188
  @string.each_byte do |byte|
187
189
  break if byte == 0x00
190
+
188
191
  yield byte
189
192
  end
190
193
  end
@@ -24,6 +24,10 @@ module Ronin
24
24
  module CTypes
25
25
  module Arch
26
26
  module ARM
27
+ #
28
+ # Represents the C types for the ARM architecture, in big-endian
29
+ # mode.
30
+ #
27
31
  module BigEndian
28
32
  include CTypes::BigEndian
29
33
 
@@ -23,6 +23,9 @@ module Ronin
23
23
  module Binary
24
24
  module CTypes
25
25
  module Arch
26
+ #
27
+ # Represents the C types for the ARM architecture.
28
+ #
26
29
  module ARM
27
30
  include LittleEndian
28
31
 
@@ -24,6 +24,10 @@ module Ronin
24
24
  module CTypes
25
25
  module Arch
26
26
  module ARM64
27
+ #
28
+ # Represents the C types for the ARM64 architecture, in big-endian
29
+ # mode.
30
+ #
27
31
  module BigEndian
28
32
  include CTypes::BigEndian
29
33