metasploit-model 0.28.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +3 -1
  3. data/config/locales/en.yml +0 -171
  4. data/lib/metasploit/model.rb +0 -2
  5. data/lib/metasploit/model/spec.rb +0 -130
  6. data/lib/metasploit/model/version.rb +1 -1
  7. data/spec/support/shared/examples/metasploit/model/search/operator/help.rb +4 -6
  8. data/spec/support/shared/examples/metasploit/model/translation.rb +1 -1
  9. data/spec/support/shared/examples/search_association.rb +1 -1
  10. data/spec/support/shared/examples/search_with.rb +4 -2
  11. metadata +3 -349
  12. data/app/models/metasploit/model/module/ancestor/spec/template.rb +0 -125
  13. data/app/models/metasploit/model/module/class/spec/template.rb +0 -92
  14. data/app/models/metasploit/model/module/instance/spec/template.rb +0 -97
  15. data/app/models/metasploit/model/spec/template.rb +0 -277
  16. data/app/validators/derivation_validator.rb +0 -17
  17. data/app/validators/dynamic_length_validator.rb +0 -45
  18. data/lib/metasploit/model/architecture.rb +0 -342
  19. data/lib/metasploit/model/author.rb +0 -54
  20. data/lib/metasploit/model/authority.rb +0 -141
  21. data/lib/metasploit/model/authority/bid.rb +0 -10
  22. data/lib/metasploit/model/authority/cve.rb +0 -10
  23. data/lib/metasploit/model/authority/msb.rb +0 -10
  24. data/lib/metasploit/model/authority/osvdb.rb +0 -10
  25. data/lib/metasploit/model/authority/pmasa.rb +0 -10
  26. data/lib/metasploit/model/authority/secunia.rb +0 -10
  27. data/lib/metasploit/model/authority/us_cert_vu.rb +0 -10
  28. data/lib/metasploit/model/authority/waraxe.rb +0 -31
  29. data/lib/metasploit/model/authority/zdi.rb +0 -10
  30. data/lib/metasploit/model/derivation.rb +0 -109
  31. data/lib/metasploit/model/derivation/full_name.rb +0 -19
  32. data/lib/metasploit/model/email_address.rb +0 -124
  33. data/lib/metasploit/model/module.rb +0 -20
  34. data/lib/metasploit/model/module/action.rb +0 -52
  35. data/lib/metasploit/model/module/ancestor.rb +0 -491
  36. data/lib/metasploit/model/module/ancestor/spec.rb +0 -6
  37. data/lib/metasploit/model/module/architecture.rb +0 -34
  38. data/lib/metasploit/model/module/author.rb +0 -40
  39. data/lib/metasploit/model/module/class.rb +0 -403
  40. data/lib/metasploit/model/module/class/spec.rb +0 -6
  41. data/lib/metasploit/model/module/handler.rb +0 -29
  42. data/lib/metasploit/model/module/instance.rb +0 -622
  43. data/lib/metasploit/model/module/instance/spec.rb +0 -6
  44. data/lib/metasploit/model/module/path.rb +0 -159
  45. data/lib/metasploit/model/module/platform.rb +0 -32
  46. data/lib/metasploit/model/module/rank.rb +0 -85
  47. data/lib/metasploit/model/module/reference.rb +0 -32
  48. data/lib/metasploit/model/module/stance.rb +0 -16
  49. data/lib/metasploit/model/module/target.rb +0 -78
  50. data/lib/metasploit/model/module/target/architecture.rb +0 -34
  51. data/lib/metasploit/model/module/target/platform.rb +0 -34
  52. data/lib/metasploit/model/module/type.rb +0 -38
  53. data/lib/metasploit/model/platform.rb +0 -246
  54. data/lib/metasploit/model/real_pathname.rb +0 -16
  55. data/lib/metasploit/model/reference.rb +0 -104
  56. data/spec/app/models/metasploit/model/module/ancestor/spec/template_spec.rb +0 -174
  57. data/spec/app/models/metasploit/model/module/class/spec/template_spec.rb +0 -222
  58. data/spec/app/models/metasploit/model/module/instance/spec/template_spec.rb +0 -201
  59. data/spec/app/models/metasploit/model/search/operator/deprecated/app_spec.rb +0 -62
  60. data/spec/app/models/metasploit/model/search/operator/deprecated/author_spec.rb +0 -197
  61. data/spec/app/models/metasploit/model/search/operator/deprecated/authority_spec.rb +0 -135
  62. data/spec/app/models/metasploit/model/search/operator/deprecated/platform_spec.rb +0 -124
  63. data/spec/app/models/metasploit/model/search/operator/deprecated/ref_spec.rb +0 -387
  64. data/spec/app/models/metasploit/model/search/operator/deprecated/text_spec.rb +0 -399
  65. data/spec/app/models/metasploit/model/spec/template_spec.rb +0 -23
  66. data/spec/app/validators/derivation_validator_spec.rb +0 -92
  67. data/spec/app/validators/dynamic_length_validator_spec.rb +0 -293
  68. data/spec/dummy/app/models/dummy/architecture.rb +0 -92
  69. data/spec/dummy/app/models/dummy/author.rb +0 -15
  70. data/spec/dummy/app/models/dummy/authority.rb +0 -130
  71. data/spec/dummy/app/models/dummy/email_address.rb +0 -27
  72. data/spec/dummy/app/models/dummy/module/action.rb +0 -25
  73. data/spec/dummy/app/models/dummy/module/ancestor.rb +0 -67
  74. data/spec/dummy/app/models/dummy/module/architecture.rb +0 -19
  75. data/spec/dummy/app/models/dummy/module/author.rb +0 -28
  76. data/spec/dummy/app/models/dummy/module/class.rb +0 -69
  77. data/spec/dummy/app/models/dummy/module/instance.rb +0 -209
  78. data/spec/dummy/app/models/dummy/module/path.rb +0 -64
  79. data/spec/dummy/app/models/dummy/module/platform.rb +0 -19
  80. data/spec/dummy/app/models/dummy/module/rank.rb +0 -44
  81. data/spec/dummy/app/models/dummy/module/reference.rb +0 -19
  82. data/spec/dummy/app/models/dummy/module/target.rb +0 -62
  83. data/spec/dummy/app/models/dummy/module/target/architecture.rb +0 -19
  84. data/spec/dummy/app/models/dummy/module/target/platform.rb +0 -19
  85. data/spec/dummy/app/models/dummy/platform.rb +0 -58
  86. data/spec/dummy/app/models/dummy/reference.rb +0 -31
  87. data/spec/dummy/spec/factories/dummy/architectures.rb +0 -13
  88. data/spec/dummy/spec/factories/dummy/authorities.rb +0 -32
  89. data/spec/dummy/spec/factories/dummy/authors.rb +0 -8
  90. data/spec/dummy/spec/factories/dummy/email_addresses.rb +0 -8
  91. data/spec/dummy/spec/factories/dummy/module/actions.rb +0 -13
  92. data/spec/dummy/spec/factories/dummy/module/ancestors.rb +0 -45
  93. data/spec/dummy/spec/factories/dummy/module/architectures.rb +0 -35
  94. data/spec/dummy/spec/factories/dummy/module/authors.rb +0 -10
  95. data/spec/dummy/spec/factories/dummy/module/classes.rb +0 -40
  96. data/spec/dummy/spec/factories/dummy/module/instances.rb +0 -86
  97. data/spec/dummy/spec/factories/dummy/module/paths.rb +0 -16
  98. data/spec/dummy/spec/factories/dummy/module/platforms.rb +0 -35
  99. data/spec/dummy/spec/factories/dummy/module/ranks.rb +0 -14
  100. data/spec/dummy/spec/factories/dummy/module/references.rb +0 -17
  101. data/spec/dummy/spec/factories/dummy/module/target/architectures.rb +0 -40
  102. data/spec/dummy/spec/factories/dummy/module/target/platforms.rb +0 -41
  103. data/spec/dummy/spec/factories/dummy/module/targets.rb +0 -46
  104. data/spec/dummy/spec/factories/dummy/platforms.rb +0 -3
  105. data/spec/dummy/spec/factories/dummy/references.rb +0 -26
  106. data/spec/factories/metasploit/model/architectures.rb +0 -6
  107. data/spec/factories/metasploit/model/authorities.rb +0 -28
  108. data/spec/factories/metasploit/model/authors.rb +0 -9
  109. data/spec/factories/metasploit/model/email_addresses.rb +0 -14
  110. data/spec/factories/metasploit/model/module/actions.rb +0 -9
  111. data/spec/factories/metasploit/model/module/ancestors.rb +0 -180
  112. data/spec/factories/metasploit/model/module/architectures.rb +0 -15
  113. data/spec/factories/metasploit/model/module/classes.rb +0 -47
  114. data/spec/factories/metasploit/model/module/handlers.rb +0 -3
  115. data/spec/factories/metasploit/model/module/instances.rb +0 -83
  116. data/spec/factories/metasploit/model/module/paths.rb +0 -51
  117. data/spec/factories/metasploit/model/module/platforms.rb +0 -15
  118. data/spec/factories/metasploit/model/module/ranks.rb +0 -9
  119. data/spec/factories/metasploit/model/module/references.rb +0 -11
  120. data/spec/factories/metasploit/model/module/stances.rb +0 -3
  121. data/spec/factories/metasploit/model/module/targets.rb +0 -22
  122. data/spec/factories/metasploit/model/module/types.rb +0 -5
  123. data/spec/factories/metasploit/model/references.rb +0 -88
  124. data/spec/lib/metasploit/model/architecture_spec.rb +0 -52
  125. data/spec/lib/metasploit/model/author_spec.rb +0 -6
  126. data/spec/lib/metasploit/model/authority/bid_spec.rb +0 -17
  127. data/spec/lib/metasploit/model/authority/cve_spec.rb +0 -17
  128. data/spec/lib/metasploit/model/authority/msb_spec.rb +0 -17
  129. data/spec/lib/metasploit/model/authority/osvdb_spec.rb +0 -17
  130. data/spec/lib/metasploit/model/authority/pmasa_spec.rb +0 -17
  131. data/spec/lib/metasploit/model/authority/secunia_spec.rb +0 -17
  132. data/spec/lib/metasploit/model/authority/us_cert_vu_spec.rb +0 -17
  133. data/spec/lib/metasploit/model/authority/waraxe_spec.rb +0 -51
  134. data/spec/lib/metasploit/model/authority/zdi_spec.rb +0 -21
  135. data/spec/lib/metasploit/model/authority_spec.rb +0 -10
  136. data/spec/lib/metasploit/model/derivation/full_name_spec.rb +0 -75
  137. data/spec/lib/metasploit/model/derivation_spec.rb +0 -217
  138. data/spec/lib/metasploit/model/email_address_spec.rb +0 -19
  139. data/spec/lib/metasploit/model/module/action_spec.rb +0 -6
  140. data/spec/lib/metasploit/model/module/ancestor_spec.rb +0 -6
  141. data/spec/lib/metasploit/model/module/architecture_spec.rb +0 -9
  142. data/spec/lib/metasploit/model/module/author_spec.rb +0 -6
  143. data/spec/lib/metasploit/model/module/class_spec.rb +0 -19
  144. data/spec/lib/metasploit/model/module/handler_spec.rb +0 -61
  145. data/spec/lib/metasploit/model/module/instance_spec.rb +0 -183
  146. data/spec/lib/metasploit/model/module/path_spec.rb +0 -6
  147. data/spec/lib/metasploit/model/module/platform_spec.rb +0 -9
  148. data/spec/lib/metasploit/model/module/rank_spec.rb +0 -29
  149. data/spec/lib/metasploit/model/module/reference_spec.rb +0 -9
  150. data/spec/lib/metasploit/model/module/stance_spec.rb +0 -30
  151. data/spec/lib/metasploit/model/module/target/architecture_spec.rb +0 -9
  152. data/spec/lib/metasploit/model/module/target/platform_spec.rb +0 -9
  153. data/spec/lib/metasploit/model/module/target_spec.rb +0 -9
  154. data/spec/lib/metasploit/model/module/type_spec.rb +0 -125
  155. data/spec/lib/metasploit/model/platform_spec.rb +0 -100
  156. data/spec/lib/metasploit/model/reference_spec.rb +0 -21
  157. data/spec/support/shared/contexts/metasploit/model/module/ancestor/contents/metasploit_module.rb +0 -12
  158. data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents.rb +0 -10
  159. data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents/metasploit_module.rb +0 -15
  160. data/spec/support/shared/examples/derives.rb +0 -115
  161. data/spec/support/shared/examples/metasploit/model/architecture.rb +0 -425
  162. data/spec/support/shared/examples/metasploit/model/architecture/seed.rb +0 -25
  163. data/spec/support/shared/examples/metasploit/model/author.rb +0 -27
  164. data/spec/support/shared/examples/metasploit/model/authority.rb +0 -124
  165. data/spec/support/shared/examples/metasploit/model/authority/seed.rb +0 -49
  166. data/spec/support/shared/examples/metasploit/model/email_address.rb +0 -220
  167. data/spec/support/shared/examples/metasploit/model/module/action.rb +0 -26
  168. data/spec/support/shared/examples/metasploit/model/module/ancestor.rb +0 -2004
  169. data/spec/support/shared/examples/metasploit/model/module/ancestor/payload_factory.rb +0 -63
  170. data/spec/support/shared/examples/metasploit/model/module/architecture.rb +0 -36
  171. data/spec/support/shared/examples/metasploit/model/module/author.rb +0 -29
  172. data/spec/support/shared/examples/metasploit/model/module/class.rb +0 -1514
  173. data/spec/support/shared/examples/metasploit/model/module/handler.rb +0 -21
  174. data/spec/support/shared/examples/metasploit/model/module/instance.rb +0 -1384
  175. data/spec/support/shared/examples/metasploit/model/module/instance/class_methods.rb +0 -537
  176. data/spec/support/shared/examples/metasploit/model/module/instance/is_not_stanced_with_module_type.rb +0 -22
  177. data/spec/support/shared/examples/metasploit/model/module/instance/is_stanced_with_module_type.rb +0 -38
  178. data/spec/support/shared/examples/metasploit/model/module/instance/validates/dynamic_length_of.rb +0 -131
  179. data/spec/support/shared/examples/metasploit/model/module/path.rb +0 -493
  180. data/spec/support/shared/examples/metasploit/model/module/platform.rb +0 -36
  181. data/spec/support/shared/examples/metasploit/model/module/rank.rb +0 -92
  182. data/spec/support/shared/examples/metasploit/model/module/reference.rb +0 -16
  183. data/spec/support/shared/examples/metasploit/model/module/target.rb +0 -29
  184. data/spec/support/shared/examples/metasploit/model/module/target/architecture.rb +0 -56
  185. data/spec/support/shared/examples/metasploit/model/module/target/platform.rb +0 -56
  186. data/spec/support/shared/examples/metasploit/model/platform.rb +0 -213
  187. data/spec/support/shared/examples/metasploit/model/real_pathname.rb +0 -29
  188. data/spec/support/shared/examples/metasploit/model/reference.rb +0 -410
  189. data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/app.rb +0 -44
  190. data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/authority.rb +0 -72
  191. data/spec/support/templates/metasploit/model/module/ancestors/_attributes.rb.erb +0 -9
  192. data/spec/support/templates/metasploit/model/module/ancestors/_methods.rb.erb +0 -8
  193. data/spec/support/templates/metasploit/model/module/ancestors/_validations.rb.erb +0 -6
  194. data/spec/support/templates/metasploit/model/module/ancestors/base.rb.erb +0 -3
  195. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_auxiliary.rb.erb +0 -1
  196. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_encoder.rb.erb +0 -1
  197. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_exploit.rb.erb +0 -1
  198. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_non_payload.rb.erb +0 -5
  199. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_nop.rb.erb +0 -1
  200. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_payload.rb.erb +0 -4
  201. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_post.rb.erb +0 -1
  202. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_handled.rb.erb +0 -20
  203. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_single.rb.erb +0 -1
  204. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stage.rb.erb +0 -0
  205. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stager.rb.erb +0 -1
  206. data/spec/support/templates/metasploit/model/module/classes/_methods.rb.erb +0 -9
@@ -1,125 +0,0 @@
1
- # Writes templates for the {#module_ancestor} to disk.
2
- #
3
- # @example Update files after changing
4
- # module_ancestor = FactoryGirl.build(
5
- # :dummy_module_ancestor
6
- # )
7
- # # factory already wrote template when build returned
8
- #
9
- # # update
10
- # module_ancestor.module_type = FactoryGirl.generate :metasploit_model_module_type
11
- #
12
- # # Now the template on disk is different than the module_ancestor, so regenerate the template
13
- # Metasploit::Model::Module::Ancestor::Spec::Template.write(module_ancestor: module_ancestor)
14
- class Metasploit::Model::Module::Ancestor::Spec::Template < Metasploit::Model::Spec::Template
15
- extend Metasploit::Model::Spec::Template::Write
16
-
17
- #
18
- # CONSTANTS
19
- #
20
-
21
- # Default value for {#search_pathnames}.
22
- DEFAULT_SEARCH_PATHNAMES = [
23
- Pathname.new('module/ancestors')
24
- ]
25
- # Default value for {#source_relative_name}.
26
- DEFAULT_SOURCE_RELATIVE_NAME = 'base'
27
-
28
- #
29
- # Attributes
30
- #
31
-
32
- # @!attribute [rw] metasploit_module_relative_name
33
- # The name of the Class/Module in the template. Defaults to
34
- # `FactoryGirl.generate :metasploit_model_module_ancestor_metasploit_module_relative_name`.
35
- #
36
- # @return [String]
37
- attr_writer :metasploit_module_relative_name
38
-
39
- # @!attribute [rw] module_ancestor
40
- # The module ancestor to write.
41
- #
42
- # @return [Metasploit::Model::Module::Ancestor]
43
- attr_accessor :module_ancestor
44
-
45
- #
46
- # Validations
47
- #
48
-
49
- validates :module_ancestor,
50
- presence: true
51
-
52
- #
53
- # Methods
54
- #
55
-
56
- # The pathname where to {#write} to template results.
57
- #
58
- # @return [Pathname] `Metasploit::Model::Module::Ancestor#real_pathname.
59
- # @return [nil] if {#module_ancestor} is `nil`.
60
- # @return [nil] if {#module_ancestor #module_ancestor's} `Metasploit::Model::Module::Ancestor#real_pathname` is `nil`
61
- # after derivation.
62
- def destination_pathname
63
- unless instance_variable_defined? :@destination_pathname
64
- @destination_pathname = nil
65
-
66
- if module_ancestor
67
- destination_pathname = module_ancestor.real_pathname
68
-
69
- unless destination_pathname
70
- # validate to derive real_path and therefore real_pathname
71
- module_ancestor.valid?
72
-
73
- destination_pathname = module_ancestor.real_pathname
74
- end
75
-
76
- @destination_pathname = destination_pathname
77
- end
78
- end
79
-
80
- @destination_pathname
81
- end
82
-
83
- # Local variables exposed to partials.
84
- #
85
- # @return [Hash{Symbol => Object}] {#metasploit_module_relative_name} as :metasploit_module_relative_name and
86
- # {#module_ancestor} at :module_ancestor.
87
- def locals
88
- @locals ||= {
89
- metasploit_module_relative_name: metasploit_module_relative_name,
90
- module_ancestor: module_ancestor
91
- }
92
- end
93
-
94
- # Name of the Class/Module declared in the template file.
95
- #
96
- # @return [String]
97
- def metasploit_module_relative_name
98
- @metasploit_module_relative_name ||= FactoryGirl.generate :metasploit_model_module_ancestor_metasploit_module_relative_name
99
- end
100
-
101
- # Whether to overwrite a pre-existing file.
102
- #
103
- # @return [Boolean] Defaults to `false` since nothing should write the template before the ancestor.
104
- def overwrite
105
- unless instance_variable_defined? :@overwrite
106
- @overwrite = false
107
- end
108
-
109
- @overwrite
110
- end
111
-
112
- # Pathnames to search for partials.
113
- #
114
- # @return [Array<Pathname>] {DEFAULT_SEARCH_PATHNAMES}
115
- def search_pathnames
116
- @search_pathnames ||= DEFAULT_SEARCH_PATHNAMES.dup
117
- end
118
-
119
- # Name of template under {#search_pathnames} without {EXTENSION}.
120
- #
121
- # @return [String] Defaults to {DEFAULT_SOURCE_RELATIVE_NAME}.
122
- def source_relative_name
123
- @source_relative_name ||= DEFAULT_SOURCE_RELATIVE_NAME
124
- end
125
- end
@@ -1,92 +0,0 @@
1
- # Writes templates for the {#module_class #module_class's} {Metasploit::Model::Module::Class#ancestors} to disk.
2
- #
3
- # @example Update files after changing associations
4
- # module_class = FactoryGirl.build(
5
- # :dummy_module_class
6
- # )
7
- # # factory already wrote template when build returned
8
- #
9
- # # update associations
10
- # rank = FactoryGirl.generate :dummy_rank
11
- # module_class.rank = rank
12
- #
13
- # # Now the template on disk is different than the module_class, so regenerate the template
14
- # Metasploit::Model::Module::Class::Spec::Template.write(module_class: module_class)
15
- class Metasploit::Model::Module::Class::Spec::Template < Metasploit::Model::Base
16
- extend Metasploit::Model::Spec::Template::Write
17
-
18
- #
19
- # Attributes
20
- #
21
-
22
- # @!attribute [rw] module_class
23
- # The {Metasploit::Model::Module::Class} whose {Metasploit::Model::Module::Class#ancestors} need to be templated in
24
- # {#ancestor_templates}.
25
- #
26
- # @return [Metasploit::Model::Module::Class]
27
- attr_accessor :module_class
28
-
29
- #
30
- # Validations
31
- #
32
-
33
- validates :module_class,
34
- presence: true
35
- validate :ancestor_templates_valid
36
-
37
- #
38
- # Methods
39
- #
40
-
41
- # Template for {#module_class} {Metasploit::Model::Module::Class#ancestors} with the addition of {#module_class} to
42
- # the {Metasploit::Model::Spec::Template#locals} and adding 'module/classes' to the front of the
43
- # {Metasploit::Model::Spec::Template#search_pathnames}.
44
- #
45
- # @return [Array<Metasploit::Model::Module::Ancestor::Spec::Template>]
46
- # @return [[]] if {#module_class} is `nil`.
47
- def ancestor_templates
48
- unless instance_variable_defined? :@ancestor_templates
49
- if module_class
50
- @ancestor_templates = module_class.ancestors.collect { |module_ancestor|
51
- Metasploit::Model::Module::Ancestor::Spec::Template.new(
52
- module_ancestor: module_ancestor
53
- ).tap { |module_ancestor_template|
54
- module_ancestor_template.locals[:module_class] = module_class
55
- module_ancestor_template.overwrite = true
56
-
57
- module_ancestor_template.search_pathnames.unshift(
58
- Pathname.new('module/classes')
59
- )
60
- }
61
- }
62
- end
63
-
64
- @ancestor_templates ||= []
65
- end
66
-
67
- @ancestor_templates
68
- end
69
-
70
- # Writes {#ancestor_templates} to disk.
71
- #
72
- # @return [void]
73
- # @raise (see Metasploit::Model::Spec::Template)
74
- def write
75
- ancestor_templates.each(&:write)
76
- end
77
-
78
- private
79
-
80
- # Validates that all {#ancestor_templates} are valid.
81
- #
82
- # @return [void]
83
- def ancestor_templates_valid
84
- # can't use ancestor_templates.all?(&:valid?) as it will short-circuit and want all ancestor_templates to have
85
- # validation errors
86
- valids = ancestor_templates.map(&:valid?)
87
-
88
- unless valids.all?
89
- errors.add(:ancestor_templates, :invalid, value: ancestor_templates)
90
- end
91
- end
92
- end
@@ -1,97 +0,0 @@
1
- # Writes templates for the {#module_instance #module_instance's}
2
- # {Metasploit::Model::Module::Instance#module_class #module_class's} {Metasploit::Model::Module::Class#ancestors} to
3
- # disk.
4
- #
5
- # @example Update files after changing associations
6
- # module_instance = FactoryGirl.build(
7
- # :dummy_module_instance,
8
- # module_architectures_length: 0
9
- # )
10
- # # factory already wrote template when build returned
11
- #
12
- # # update associations
13
- # architecture = FactoryGirl.generate :dummy_architecture
14
- # module_instance.module_architectures = FactoryGirl.build_list(
15
- # :dummy_module_architecture,
16
- # 1,
17
- # architecture: architecture
18
- # )
19
- #
20
- # # Now the template on disk is different than the module_instance, so regenerate the template
21
- # Metasploit::Model::Module::Instance::Spec::Template.write(module_instance: module_instance)
22
- class Metasploit::Model::Module::Instance::Spec::Template < Metasploit::Model::Base
23
- extend Metasploit::Model::Spec::Template::Write
24
-
25
- #
26
- # Attributes
27
- #
28
-
29
- # @!attribute [rw] module_instance
30
- # The {Metasploit::Model::Module::Instance} whose {Metasploit::Model::Module::Instance#module_class} needs to be
31
- # templated in {#class_template}.
32
- #
33
- # @return [Metasploit::Model::Module::Instance]
34
- attr_accessor :module_instance
35
-
36
- #
37
- # Validations
38
- #
39
-
40
- validates :class_template,
41
- presence: true
42
- validates :module_instance,
43
- presence: true
44
- validate :class_template_valid
45
-
46
- #
47
- # Methods
48
- #
49
-
50
- # Template for {#module_instance} {Metasploit::Model::Module::Instance#module_class} with the addition of
51
- # {#module_instance} to the {Metasploit::Model::Spec::Template#locals} and adding 'module/instances' to the front of
52
- # the {Metasploit::Model::Spec::Template#search_pathnames}.
53
- #
54
- # @return [Metasploit::Model::Module::Class::Spec::Template] if {#module_instance} present.
55
- # @return [nil] if {#module_instance} is `nil`.
56
- def class_template
57
- unless instance_variable_defined? :@class_template
58
- if module_instance
59
- class_template = Metasploit::Model::Module::Class::Spec::Template.new(
60
- module_class: module_instance.module_class
61
- )
62
- class_template.ancestor_templates.each do |ancestor_template|
63
- ancestor_template.locals[:module_instance] = module_instance
64
-
65
- ancestor_template.search_pathnames.unshift(
66
- Pathname.new('module/instances')
67
- )
68
- end
69
-
70
- @class_template = class_template
71
- else
72
- @class_template = nil
73
- end
74
- end
75
-
76
- @class_template
77
- end
78
-
79
- # @!method write
80
- # Writes {#class_template} to disk.
81
- #
82
- # @return [void]
83
- # @raise (see Metasploit::Model::Spec::Template)
84
- delegate :write,
85
- to: :class_template
86
-
87
- private
88
-
89
- # Validates that {#class_template} is valid when present.
90
- #
91
- # @return [void]
92
- def class_template_valid
93
- if class_template && !class_template.valid?
94
- errors.add(:class_template, :invalid, value: class_template)
95
- end
96
- end
97
- end
@@ -1,277 +0,0 @@
1
- # Processes {EXTENSION '.rb.erb'} templates to create {Metasploit::Model::Module::Ancestor#contents} that contain the
2
- # same metadata as the {Metasploit::Model::Module::Ancestor},
3
- # {Metasploit::Model::Module::Class}, {Metasploit::Model::Module::Instance} and associations for those contents. This
4
- # ensures that when the {Metasploit::Model::Module::Ancestor#contents} are loaded in metasploit-framework, the same
5
- # metadata instances are derived from the contents ensuring idempotency of the contents and metadata parsing loop.
6
- class Metasploit::Model::Spec::Template < Metasploit::Model::Base
7
- extend ActiveSupport::Autoload
8
- extend ActiveModel::Callbacks
9
-
10
- include ActiveModel::Validations::Callbacks
11
-
12
- autoload :Write
13
-
14
- #
15
- # CONSTANTS
16
- #
17
-
18
- # Regular expression to parse file from backtrace line
19
- BACKTRACE_FILE_REGEXP = /(?<file>.*):\d+:in .*/
20
- # Trim mode for ERB templates so that lines using <%- -%> will be trimmed of new lines
21
- EXPLICIT_TRIM_MODE = '-'
22
- # File extension for templates.
23
- EXTENSION = '.rb.erb'
24
-
25
- #
26
- # Attributes
27
- #
28
-
29
- # @!attribute [rw] destination_pathname
30
- # The pathname where to {#write} the template results.
31
- #
32
- # @return [String]
33
- attr_accessor :destination_pathname
34
-
35
- # @!attribute [rw] locals
36
- # Local variables to exposed to partials.
37
- #
38
- # @return [Hash{Symbol => Object}]
39
- attr_accessor :locals
40
-
41
- # @!attribute [rw] overwrite
42
- # Whether to overwrite a pre-existing file.
43
- #
44
- # @return [Boolean]
45
- attr_accessor :overwrite
46
-
47
- # @!attribute [rw] search_pathnames
48
- # Pathnames to search for partials. First item is search first, etc.
49
- #
50
- # @return [Array<Pathname>]
51
- attr_accessor :search_pathnames
52
-
53
- # @!attribute [rw] source_relative_name
54
- # Name of template under {#search_pathnames} without {EXTENSION} similar to how to refer to partials.
55
- #
56
- # @return [String]
57
- attr_accessor :source_relative_name
58
-
59
-
60
- #
61
- # Callbacks
62
- #
63
-
64
- before_validation :search_real_pathnames
65
-
66
- #
67
- # Validations
68
- #
69
-
70
- validates :destination_pathname,
71
- presence: true
72
- validates :overwrite,
73
- inclusion: {
74
- in: [
75
- false,
76
- true
77
- ]
78
- }
79
- validates :search_pathnames,
80
- length: {
81
- minimum: 1
82
- }
83
- validates :source_pathname,
84
- presence: true
85
-
86
- #
87
- # Methods
88
- #
89
-
90
- # Converts the `partial_relative_path` to a real (absolute) pathname that can be passed to {#result} by finding the
91
- # corresponding file in the {#search_pathnames}.
92
- #
93
- # @param partial_relative_path [String] partial path name as used in Rails, so no search_pathname prefix and no '_'
94
- # or file extension in the basename.
95
- # @return (see #find_pathname)
96
- def partial_pathname(partial_relative_path)
97
- partial_relative_pathname = Pathname.new(partial_relative_path)
98
- relative_directory = partial_relative_pathname.dirname
99
- raw_basename = partial_relative_pathname.basename
100
- partial_basename = "_#{raw_basename}#{EXTENSION}"
101
- relative_pathname = relative_directory.join(partial_basename)
102
-
103
- find_pathname(relative_pathname)
104
- end
105
-
106
- # Renders partial in templates.
107
- #
108
- # @param partial_relative_path [String] relative path to partial without extension and no leading '_' to match
109
- # Rails convention.
110
- # @param options (see #result)
111
- # @option (see #result)
112
- # @return [String, nil] result of rendering partial.
113
- def render(partial_relative_path, options={})
114
- pathname = partial_pathname(partial_relative_path)
115
- result(pathname, options)
116
- end
117
-
118
- # Renders the super template of the current template by searching for the template of the same name under super
119
- # {#search_pathnames} (those that have a higher index).
120
- #
121
- # @return [String, nil] result of rendering super partial.
122
- # @raise [IOError] if super template can't be found on super search pathnames.
123
- # @raise [RegexpError] if file can't be parsed from backtrace.
124
- def render_super
125
- super_pathname = nil
126
- backtrace = caller
127
- match = BACKTRACE_FILE_REGEXP.match(backtrace[0])
128
-
129
- if match
130
- real_path = match[:file]
131
- current_search_pathname_found = false
132
- relative_pathname = nil
133
-
134
- search_pathnames.each do |search_pathname|
135
- # find the current index
136
- unless current_search_pathname_found
137
- if real_path.starts_with?(search_pathname.to_path)
138
- current_search_pathname_found = true
139
-
140
- real_pathname = Pathname.new(real_path)
141
- relative_pathname = real_pathname.relative_path_from(search_pathname)
142
- end
143
- # then switch to finding the next (super) index
144
- else
145
- real_pathname = search_pathname.join(relative_pathname)
146
-
147
- if real_pathname.exist?
148
- super_pathname = real_pathname
149
- break
150
- end
151
- end
152
- end
153
-
154
- unless super_pathname
155
- raise IOError, "Couldn't find super template"
156
- end
157
- else
158
- raise RegexpError, "Can't parse file from backtrace to determine current search path"
159
- end
160
-
161
- result(super_pathname)
162
- end
163
-
164
- # @note Must be an instance method
165
- # @param pathname [Pathname] pathname to template
166
- # @param options [Hash{Symbol => Object}]
167
- # @option options [Hash{Symbol => Object}] :locals Maps name of locals to their value for this result. Can override
168
- # {#locals}.
169
- def result(pathname, options={})
170
- options.assert_valid_keys(:locals)
171
-
172
- if pathname
173
- content = pathname.read
174
- safe_level = nil
175
- template = ERB.new content, safe_level, EXPLICIT_TRIM_MODE
176
- template.filename = pathname.to_path
177
-
178
- erb_binding = binding.dup
179
- locals = self.locals || {}
180
- result_locals = options[:locals] || {}
181
- merged_locals = locals.merge(result_locals)
182
-
183
- merged_locals.each do |name, value|
184
- erb_binding.eval("#{name} = nil; lambda { |value| #{name} = value }").call(value)
185
- end
186
-
187
- # use current binding to allow templates to call {#render} and then use {#method_missing} to allow access to
188
- # locals
189
- template.result(erb_binding)
190
- else
191
- ''
192
- end
193
- end
194
-
195
- class << self
196
- # The root of all relative {#search_pathnames}. By changing {root} you can use your own set of templates.
197
- #
198
- # @return [Pathname] Defaults to 'spec/support/templates/metasploit/model' under Metasploit::Model.root.
199
- def root
200
- @@root ||= Metasploit::Model::Engine.root.join('spec', 'support', 'templates', 'metasploit', 'model')
201
- end
202
-
203
- # Sets the {root} pathname for all {#search_pathnames}, including those on subclasses.
204
- #
205
- # @param root [Pathname]
206
- # @return [Pathname]
207
- def root=(root)
208
- @@root = root
209
- end
210
- end
211
-
212
- # Converts {#source_relative_name} to a real (absolute) pathname.
213
- #
214
- # @return (see #find_pathname)
215
- def source_pathname
216
- unless instance_variable_defined? :@source_pathname
217
- relative_path = "#{source_relative_name}#{EXTENSION}"
218
- @source_pathname = find_pathname(relative_path)
219
- end
220
-
221
- @source_pathname
222
- end
223
-
224
- # Writes result of template to {#destination_pathname}.
225
- #
226
- # @return [void]
227
- # @raise [Metasploit::Model::Spec::PathnameCollision] if {#overwrite} is false and {#destination_pathname} already
228
- # exists.
229
- def write
230
- unless overwrite
231
- Metasploit::Model::Spec::PathnameCollision.check!(destination_pathname)
232
- end
233
-
234
- result = self.result(source_pathname)
235
-
236
- # make directory
237
- destination_pathname.parent.mkpath
238
-
239
- destination_pathname.open('wb') do |f|
240
- f.write(result)
241
- end
242
- end
243
-
244
- private
245
-
246
- # Finds relative_path under {#search_pathnames}
247
- #
248
- # @return [Pathname] if relative_path exists under a search path.
249
- # @return [nil] if `relative_path` does not exist under a search path.
250
- def find_pathname(relative_path)
251
- found_pathname = nil
252
-
253
- search_pathnames.each do |search_pathname|
254
- real_pathname = search_pathname.join(relative_path)
255
-
256
- if real_pathname.exist?
257
- found_pathname = real_pathname
258
- break
259
- end
260
- end
261
-
262
- found_pathname
263
- end
264
-
265
- # Makes sure all {#search_pathnames} are real (absolute). Relative pathnames are resolved against {root}.
266
- #
267
- # @return [void]
268
- def search_real_pathnames
269
- search_pathnames.collect! { |search_pathname|
270
- if search_pathname.relative?
271
- self.class.root.join(search_pathname)
272
- else
273
- search_pathname
274
- end
275
- }
276
- end
277
- end