Files
metasploit-gs/lib/msf/util/document_generator.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.3 KiB
Ruby
Raw Normal View History

###
#
# This provides methods to generate documentation for a module.
#
###
module Msf
module Util
module DocumentGenerator
2016-02-18 11:44:14 -06:00
# Spawns a module document with a browser locally.
#
# @param mod [Msf::Module] Module to create document for.
2016-06-15 07:44:32 -04:00
# @param out_file [Rex::Quickfile] File handle to write the document to.
2016-02-18 11:44:14 -06:00
# @return [void]
2016-06-15 07:44:32 -04:00
def self.spawn_module_document(mod, out_file)
2016-02-18 15:02:24 -06:00
md = get_module_document(mod)
2016-06-15 07:44:32 -04:00
out_file.write(md)
Rex::Compat.open_webrtc_browser("file://#{out_file.path}")
2016-02-18 00:39:12 -06:00
end
2016-02-18 11:44:14 -06:00
# Returns a module document in HTML.
#
# @param mod [Msf::Module] Module to create document for.
# @return [void]
def self.get_module_document(mod)
2018-02-05 11:13:05 -05:00
kb_path = nil
2016-02-18 15:02:24 -06:00
kb = ''
2018-09-07 11:47:29 -05:00
user_path = File.join(PullRequestFinder::USER_MANUAL_BASE_PATH, "#{mod.fullname}.md")
global_path = File.join(PullRequestFinder::MANUAL_BASE_PATH, "#{mod.fullname}.md")
if File.exist?(user_path)
2018-09-07 11:47:29 -05:00
kb_path = user_path
elsif File.exist?(global_path)
2018-09-07 11:47:29 -05:00
kb_path = global_path
2018-02-05 11:13:05 -05:00
end
unless kb_path.nil?
2016-02-18 15:02:24 -06:00
File.open(kb_path, 'rb') { |f| kb = f.read }
end
2016-02-18 15:02:24 -06:00
begin
pr_finder = PullRequestFinder.new
pr = pr_finder.search(mod)
rescue PullRequestFinder::Exception => e
pr = e
end
n = DocumentNormalizer.new
items = {
mod_description: mod.description,
mod_authors: mod.send(:module_info)['Author'],
mod_fullname: mod.fullname,
mod_name: mod.name,
mod_pull_requests: pr,
mod_refs: mod.references,
mod_rank: mod.rank,
2020-07-24 18:09:52 -04:00
mod_rank_name: Msf::RankingName[mod.rank].capitalize,
mod_platforms: mod.send(:module_info)['Platform'],
2016-02-17 14:27:29 -06:00
mod_options: mod.options,
2018-10-03 23:35:30 -05:00
mod_side_effects: mod.side_effects,
mod_reliability: mod.reliability,
mod_stability: mod.stability,
mod_demo: mod
2016-02-18 15:02:24 -06:00
}
2016-02-18 15:02:24 -06:00
if mod.respond_to?(:targets) && mod.targets
items[:mod_targets] = mod.targets
end
2020-05-18 16:30:13 +08:00
n.get_md_content(items, kb).force_encoding('UTF-8')
end
end
end
end