ronin-core 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.github/workflows/ruby.yml +41 -0
  4. data/.gitignore +12 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +160 -0
  7. data/.ruby-version +1 -0
  8. data/.yardopts +1 -0
  9. data/COPYING.txt +165 -0
  10. data/ChangeLog.md +11 -0
  11. data/Gemfile +30 -0
  12. data/README.md +299 -0
  13. data/Rakefile +34 -0
  14. data/examples/ruby_shell.rb +11 -0
  15. data/gemspec.yml +28 -0
  16. data/lib/ronin/core/class_registry.rb +246 -0
  17. data/lib/ronin/core/cli/command.rb +87 -0
  18. data/lib/ronin/core/cli/command_shell/command.rb +110 -0
  19. data/lib/ronin/core/cli/command_shell.rb +345 -0
  20. data/lib/ronin/core/cli/generator/options/author.rb +106 -0
  21. data/lib/ronin/core/cli/generator/options/description.rb +54 -0
  22. data/lib/ronin/core/cli/generator/options/reference.rb +60 -0
  23. data/lib/ronin/core/cli/generator/options/summary.rb +54 -0
  24. data/lib/ronin/core/cli/generator.rb +238 -0
  25. data/lib/ronin/core/cli/logging.rb +59 -0
  26. data/lib/ronin/core/cli/options/param.rb +68 -0
  27. data/lib/ronin/core/cli/options/values/arches.rb +45 -0
  28. data/lib/ronin/core/cli/options/values/oses.rb +32 -0
  29. data/lib/ronin/core/cli/printing/arch.rb +71 -0
  30. data/lib/ronin/core/cli/printing/metadata.rb +113 -0
  31. data/lib/ronin/core/cli/printing/os.rb +54 -0
  32. data/lib/ronin/core/cli/printing/params.rb +69 -0
  33. data/lib/ronin/core/cli/ruby_shell.rb +131 -0
  34. data/lib/ronin/core/cli/shell.rb +186 -0
  35. data/lib/ronin/core/git.rb +73 -0
  36. data/lib/ronin/core/home.rb +86 -0
  37. data/lib/ronin/core/metadata/authors/author.rb +241 -0
  38. data/lib/ronin/core/metadata/authors.rb +120 -0
  39. data/lib/ronin/core/metadata/description.rb +100 -0
  40. data/lib/ronin/core/metadata/id.rb +88 -0
  41. data/lib/ronin/core/metadata/references.rb +87 -0
  42. data/lib/ronin/core/metadata/summary.rb +78 -0
  43. data/lib/ronin/core/metadata/version.rb +74 -0
  44. data/lib/ronin/core/params/exceptions.rb +38 -0
  45. data/lib/ronin/core/params/mixin.rb +317 -0
  46. data/lib/ronin/core/params/param.rb +137 -0
  47. data/lib/ronin/core/params/types/boolean.rb +64 -0
  48. data/lib/ronin/core/params/types/enum.rb +107 -0
  49. data/lib/ronin/core/params/types/float.rb +68 -0
  50. data/lib/ronin/core/params/types/integer.rb +100 -0
  51. data/lib/ronin/core/params/types/numeric.rb +106 -0
  52. data/lib/ronin/core/params/types/regexp.rb +67 -0
  53. data/lib/ronin/core/params/types/string.rb +118 -0
  54. data/lib/ronin/core/params/types/type.rb +54 -0
  55. data/lib/ronin/core/params/types/uri.rb +72 -0
  56. data/lib/ronin/core/params/types.rb +62 -0
  57. data/lib/ronin/core/params.rb +19 -0
  58. data/lib/ronin/core/version.rb +24 -0
  59. data/ronin-core.gemspec +59 -0
  60. data/spec/class_registry_spec.rb +224 -0
  61. data/spec/cli/command_shell/command_spec.rb +113 -0
  62. data/spec/cli/command_shell_spec.rb +1114 -0
  63. data/spec/cli/command_spec.rb +16 -0
  64. data/spec/cli/fixtures/irb_command +8 -0
  65. data/spec/cli/fixtures/template/dir/file1.txt +1 -0
  66. data/spec/cli/fixtures/template/dir/file2.txt +1 -0
  67. data/spec/cli/fixtures/template/file.erb +1 -0
  68. data/spec/cli/fixtures/template/file.txt +1 -0
  69. data/spec/cli/generator/options/author_spec.rb +121 -0
  70. data/spec/cli/generator/options/description_spec.rb +45 -0
  71. data/spec/cli/generator/options/reference_spec.rb +53 -0
  72. data/spec/cli/generator/options/summary_spec.rb +45 -0
  73. data/spec/cli/generator_spec.rb +244 -0
  74. data/spec/cli/logging_spec.rb +95 -0
  75. data/spec/cli/options/param_spec.rb +67 -0
  76. data/spec/cli/options/values/arches_spec.rb +62 -0
  77. data/spec/cli/printing/arch_spec.rb +130 -0
  78. data/spec/cli/printing/metadata_spec.rb +211 -0
  79. data/spec/cli/printing/os_spec.rb +64 -0
  80. data/spec/cli/printing/params_spec.rb +63 -0
  81. data/spec/cli/ruby_shell.rb +99 -0
  82. data/spec/cli/shell_spec.rb +211 -0
  83. data/spec/fixtures/example_class_registry/base_class.rb +9 -0
  84. data/spec/fixtures/example_class_registry/classes/loaded_class.rb +9 -0
  85. data/spec/fixtures/example_class_registry/classes/name_mismatch.rb +9 -0
  86. data/spec/fixtures/example_class_registry/classes/no_module.rb +4 -0
  87. data/spec/fixtures/example_class_registry.rb +8 -0
  88. data/spec/git_spec.rb +58 -0
  89. data/spec/home_spec.rb +64 -0
  90. data/spec/metadata/authors/author_spec.rb +335 -0
  91. data/spec/metadata/authors_spec.rb +126 -0
  92. data/spec/metadata/description_spec.rb +74 -0
  93. data/spec/metadata/id_spec.rb +92 -0
  94. data/spec/metadata/references_spec.rb +100 -0
  95. data/spec/metadata/summary_spec.rb +74 -0
  96. data/spec/metadata/version_spec.rb +72 -0
  97. data/spec/params/mixin_spec.rb +484 -0
  98. data/spec/params/param_spec.rb +164 -0
  99. data/spec/params/types/boolean_spec.rb +56 -0
  100. data/spec/params/types/enum_spec.rb +94 -0
  101. data/spec/params/types/float_spec.rb +107 -0
  102. data/spec/params/types/integer_spec.rb +155 -0
  103. data/spec/params/types/numeric_spec.rb +138 -0
  104. data/spec/params/types/regexp_spec.rb +64 -0
  105. data/spec/params/types/string_spec.rb +174 -0
  106. data/spec/params/types/type_spec.rb +14 -0
  107. data/spec/params/types/uri_spec.rb +62 -0
  108. data/spec/spec_helper.rb +11 -0
  109. metadata +252 -0
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core 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-core 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-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module CLI
22
+ module Generator
23
+ module Options
24
+ #
25
+ # Adds the `-S,--summary TEXT` option to the generator command.
26
+ #
27
+ module Summary
28
+ #
29
+ # Defines the `-S,--summary TEXT` option.
30
+ #
31
+ # @param [Class<Comand>] command
32
+ # The command class including {Summary}.
33
+ #
34
+ def self.included(command)
35
+ command.option :summary, short: '-S',
36
+ value: {
37
+ type: String,
38
+ usage: 'TEXT'
39
+ },
40
+ desc: 'One sentence summary' do |text|
41
+ @summary = text
42
+ end
43
+ end
44
+
45
+ # The summary text to output.
46
+ #
47
+ # @return [String, nil]
48
+ attr_reader :summary
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,238 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core 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-core 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-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'ronin/core/cli/command'
20
+
21
+ require 'command_kit/colors'
22
+ require 'fileutils'
23
+ require 'erb'
24
+
25
+ module Ronin
26
+ module Core
27
+ module CLI
28
+ #
29
+ # Adds generator methods to a command.
30
+ #
31
+ # ## Example
32
+ #
33
+ # class Gen < Command
34
+ #
35
+ # include Core::Generator
36
+ #
37
+ # template_dir File.join(ROOT,'data','templates')
38
+ #
39
+ # argument :path, desc: 'The path of the script to genereate'
40
+ #
41
+ # def run(path)
42
+ # erb 'script.rb.erb', path
43
+ # end
44
+ #
45
+ # end
46
+ #
47
+ module Generator
48
+ include CommandKit::Colors
49
+
50
+ #
51
+ # Adds {ClassMethods} to the class.
52
+ #
53
+ # @param [Class] command
54
+ # The command class which is including {Generator}.
55
+ #
56
+ # @api private
57
+ #
58
+ def self.included(command)
59
+ command.extend ClassMethods
60
+ end
61
+
62
+ module ClassMethods
63
+ #
64
+ # Gets or sets the template directory.
65
+ #
66
+ # @param [String, nil] path
67
+ # If a path is given, the template directory will be set.
68
+ #
69
+ # @return [String]
70
+ # The set template directory.
71
+ #
72
+ # @raise [NotImplementedError]
73
+ # The class did not set {template_dir}.
74
+ #
75
+ # @example
76
+ # template_dir File.join(__dir__,'..','..','..','..','data','templates','thing')
77
+ #
78
+ def template_dir(path=nil)
79
+ if path
80
+ @template_dir = File.expand_path(path)
81
+ else
82
+ @template_dir || (superclass.template_dir if superclass.kind_of?(ClassMethods))
83
+ end
84
+ end
85
+ end
86
+
87
+ # The directory to read files from.
88
+ #
89
+ # @return [String]
90
+ attr_reader :template_dir
91
+
92
+ #
93
+ # Initializes the command.
94
+ #
95
+ # @param [Hash{Symbol => Object}] kwargs
96
+ # Additional keyword arguments for `initialize`.
97
+ #
98
+ # @raise [NotImplementedError]
99
+ # The class did not set the {template_dir} path.
100
+ #
101
+ def initialize(**kwargs)
102
+ super(**kwargs)
103
+
104
+ unless (@template_dir = self.class.template_dir)
105
+ raise(NotImplementedError,"#{self.class} did not define template_dir")
106
+ end
107
+ end
108
+
109
+ #
110
+ # Prints an generator action to STDOUT.
111
+ #
112
+ # @param [Symbol] command
113
+ # The command that represents the generator action.
114
+ #
115
+ # @param [String] source
116
+ # The optional source file being copied or rendered.
117
+ #
118
+ # @param [String] dest
119
+ # The file or directory path being created or modified.
120
+ #
121
+ def print_action(command,source=nil,dest)
122
+ line = String.new
123
+ line << "\t" << colors.bold(colors.green(command))
124
+ line << "\t" << colors.green(source) if source
125
+ line << "\t" << colors.green(dest) if dest
126
+
127
+ puts(line)
128
+ end
129
+
130
+ #
131
+ # Creates an empty directory.
132
+ #
133
+ # @param [String] path
134
+ # The relative path of the directory to be created.
135
+ #
136
+ def mkdir(path)
137
+ print_action 'mkdir', path
138
+ FileUtils.mkdir_p(path)
139
+ end
140
+
141
+ #
142
+ # Creates an empty file.
143
+ #
144
+ # @param [String] path
145
+ # The relative path of the empty file to be created.
146
+ #
147
+ def touch(path)
148
+ print_action 'touch', path
149
+ FileUtils.touch(path)
150
+ end
151
+
152
+ #
153
+ # Changes the permissions of a file or directory.
154
+ #
155
+ # @param [String, Integer] mode
156
+ # The chmod String (ex: `"+x"`) or octal mask.
157
+ #
158
+ # @param [String] path
159
+ # The path to the file or directory.
160
+ #
161
+ def chmod(mode,path)
162
+ print_action "chmod", path
163
+ FileUtils.chmod(mode,path)
164
+ end
165
+
166
+ #
167
+ # Copies a file in.
168
+ #
169
+ # @param [String] source
170
+ # The file within the {template_dir} to copy in.
171
+ #
172
+ # @param [String] dest
173
+ # The destination path to copy the file to.
174
+ #
175
+ def cp(source,dest)
176
+ print_action 'cp', source, dest
177
+
178
+ FileUtils.cp(File.join(@template_dir,source),dest)
179
+ end
180
+
181
+ #
182
+ # Copies a directory in.
183
+ #
184
+ # @param [String] source
185
+ # The relative path to the directory within the {template_dir}.
186
+ #
187
+ # @param [String] dest
188
+ # The destination path to copy the directory to.
189
+ #
190
+ def cp_r(source,dest)
191
+ print_action "cp -r", source, dest
192
+
193
+ FileUtils.cp_r(File.join(@template_dir,source),dest)
194
+ end
195
+
196
+ #
197
+ # Renders a file using an `.erb` template in the {template_dir}.
198
+ #
199
+ # @param [String] source
200
+ # The relative path to the file. The `.erb` template will be derived
201
+ # from the file path by appending the `.erb` file extension.
202
+ #
203
+ # @param [String, nil] dest
204
+ # The destination path to write the rendered file to.
205
+ # If no destination path is given, the result of the rendered `.erb`
206
+ # template will be returned.
207
+ #
208
+ def erb(source,dest=nil)
209
+ if dest
210
+ print_action 'erb', source, dest
211
+ end
212
+
213
+ source_path = File.join(@template_dir,source)
214
+
215
+ return super(source_path,dest)
216
+ end
217
+
218
+ #
219
+ # Runs a command.
220
+ #
221
+ # @param [String] command
222
+ # The command name to execute.
223
+ #
224
+ # @param [Array<String>] arguments
225
+ # Additional arguments for the command.
226
+ #
227
+ # @return [Boolean, nil]
228
+ # Indicates whether the command successfully executed or not.
229
+ #
230
+ def sh(command,*arguments)
231
+ print_action "run", [command, *arguments].join(' ')
232
+
233
+ system(command,*arguments)
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core 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-core 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-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'command_kit/colors'
20
+
21
+ module Ronin
22
+ module Core
23
+ module CLI
24
+ module Logging
25
+ include CommandKit::Colors
26
+
27
+ #
28
+ # Prints an info message to STDOUT.
29
+ #
30
+ # @param [String] message
31
+ # The message to print.
32
+ #
33
+ def log_info(message)
34
+ puts("#{colors.bold(colors.bright_green('>>>'))} #{colors.bold(colors.white(message))}")
35
+ end
36
+
37
+ #
38
+ # Prints a warning message to STDOUT.
39
+ #
40
+ # @param [String] message
41
+ # The message to print.
42
+ #
43
+ def log_warn(message)
44
+ puts("#{colors.bold(colors.bright_yellow('***'))} #{colors.bold(colors.white(message))}")
45
+ end
46
+
47
+ #
48
+ # Prints an error message to STDERR.
49
+ #
50
+ # @param [String] message
51
+ # The message to print.
52
+ #
53
+ def log_error(message)
54
+ stderr.puts("#{colors(stderr).bold(colors(stderr).bright_red('!!!'))} #{colors(stderr).bold(colors(stderr).white(message))}")
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # This file is part of ronin-core.
6
+ #
7
+ # ronin-core is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-core is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-core. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Ronin
22
+ module Core
23
+ module CLI
24
+ module Options
25
+ #
26
+ # Adds a `-p,--param NAME=VALUE` option for setting param values.
27
+ #
28
+ module Param
29
+ #
30
+ # Adds a `-p,--param NAME=VALUE` option to the command.
31
+ #
32
+ # @param [Class<Command>] command
33
+ # The command including {Param}.
34
+ #
35
+ def self.included(command)
36
+ command.option :param, short: '-p',
37
+ value: {
38
+ type: /\A[^=]+=.+\z/,
39
+ usage: 'NAME=VALUE',
40
+ },
41
+ desc: 'Sets a param' do |str|
42
+ name, value = str.split('=',2)
43
+
44
+ @params[name.to_sym] = value
45
+ end
46
+ end
47
+
48
+ # The set params.
49
+ #
50
+ # @return [Hash{Symbol => String}]
51
+ attr_reader :params
52
+
53
+ #
54
+ # Initializes the command and {#params}.
55
+ #
56
+ # @param [Hash{Symbol => Object}] kwargs
57
+ # Additional keyword arguments.
58
+ #
59
+ def initialize(**kwargs)
60
+ super(**kwargs)
61
+
62
+ @params = {}
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core 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-core 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-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module CLI
22
+ module Options
23
+ module Values
24
+ # Supported architecture names and their Symbol equivalents
25
+ ARCHES = {
26
+ 'x86' => :x86,
27
+ 'x86-64' => :x86_64,
28
+ 'amd64' => :x86_64,
29
+ 'ia64' => :ia64,
30
+ 'ppc' => :ppc,
31
+ 'ppc64' => :ppc64,
32
+ 'arm' => :arm,
33
+ 'armbe' => :arm_be,
34
+ 'arm64' => :arm64,
35
+ 'arm64be' => :arm64_be,
36
+ 'mips' => :mips,
37
+ 'mipsle' => :mips_le,
38
+ 'mips64' => :mips64,
39
+ 'mips64le' => :mips64_le
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core 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-core 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-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module CLI
22
+ module Options
23
+ module Values
24
+ # Supported Operating Systems (OS)
25
+ OSES = [
26
+ :linux, :macos, :windows, :freebsd, :openbsd, :netbsd
27
+ ]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core 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-core 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-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module CLI
22
+ module Printing
23
+ #
24
+ # Command methods for printing arch IDs.
25
+ #
26
+ module Arch
27
+ # Mapping of architecture IDs to printable names.
28
+ ARCH_NAMES = {
29
+ x86: 'x86',
30
+
31
+ x86_64: 'x86-64',
32
+ ia64: 'IA64',
33
+ amd64: 'x86-64',
34
+
35
+ ppc: 'PPC',
36
+ ppc64: 'PPC64',
37
+
38
+ mips: 'MIPS',
39
+ mips_le: 'MIPS (LE)',
40
+ mips_be: 'MIPS',
41
+
42
+ mips64: 'MIPS64',
43
+ mips64_le: 'MIPS64 (LE)',
44
+ mips64_be: 'MIPS64',
45
+
46
+ arm: 'ARM',
47
+ arm_le: 'ARM',
48
+ arm_be: 'ARM (BE)',
49
+
50
+ arm64: 'ARM64',
51
+ arm64_le: 'ARM64',
52
+ arm64_be: 'ARM64 (BE)'
53
+ }
54
+
55
+ #
56
+ # Converts the architecture ID to a printable name.
57
+ #
58
+ # @param [Symbol] arch
59
+ # The arch ID.
60
+ #
61
+ # @return [String]
62
+ # The arch display name.
63
+ #
64
+ def arch_name(arch)
65
+ ARCH_NAMES.fetch(arch,&:to_s)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core 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-core 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-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'command_kit/options/verbose'
20
+ require 'command_kit/printing/indent'
21
+ require 'command_kit/printing/lists'
22
+
23
+ module Ronin
24
+ module Core
25
+ module CLI
26
+ module Printing
27
+ #
28
+ # Common methods for printing {Core::Metadata} data.
29
+ #
30
+ module Metadata
31
+ include CommandKit::Printing::Indent
32
+ include CommandKit::Printing::Lists
33
+
34
+ #
35
+ # Addss a `-v,--verbose` option to the command class.
36
+ #
37
+ # @param [Class<Command>] command
38
+ # The command class including {Metadata}.
39
+ #
40
+ def self.included(command)
41
+ command.include CommandKit::Options::Verbose
42
+ end
43
+
44
+ #
45
+ # The class which defines the authors.
46
+ #
47
+ # @param [Class<Core::Metadata::Authors>] klass
48
+ #
49
+ def print_authors(klass)
50
+ unless klass.authors.empty?
51
+ puts "Authors:"
52
+ puts
53
+
54
+ if verbose?
55
+ indent do
56
+ klass.authors.each do |author|
57
+ puts "* #{author}"
58
+ puts " * PGP: #{author.pgp}" if author.pgp?
59
+ puts " * Website: #{author.website}" if author.website?
60
+ puts " * Blog: #{author.blog}" if author.blog?
61
+ puts " * GitHub: #{author.github_url}" if author.github?
62
+ puts " * GitLab: #{author.gitlab_url}" if author.gitlab?
63
+ puts " * Twitter: #{author.twitter_url}" if author.twitter?
64
+ puts " * Discord: #{author.discord}" if author.discord?
65
+ end
66
+ end
67
+ else
68
+ indent { print_list(klass.authors) }
69
+ end
70
+
71
+ puts
72
+ end
73
+ end
74
+
75
+ #
76
+ # The class which defines a description.
77
+ #
78
+ # @param [Class<Core::Metadata::Description>] klass
79
+ #
80
+ def print_description(klass)
81
+ if klass.description
82
+ puts 'Description:'
83
+ puts
84
+
85
+ indent do
86
+ klass.description.each_line do |line|
87
+ puts line
88
+ end
89
+ end
90
+
91
+ puts
92
+ end
93
+ end
94
+
95
+ #
96
+ # The class that defines references.
97
+ #
98
+ # @param [Class<Core::Metadata::References>] klass
99
+ #
100
+ def print_references(klass)
101
+ unless klass.references.empty?
102
+ puts "References:"
103
+ puts
104
+
105
+ indent { print_list(klass.references) }
106
+ puts
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end