Skip to content

Commit a1a59cf

Browse files
committed
Load from the user's module store
1 parent 233cd61 commit a1a59cf

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

lib/msf/core/modules/metadata/store.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ def init_store
2222
load_metadata
2323
end
2424

25+
def get_user_store
26+
store_dir = ::File.join(Msf::Config.config_directory, "store")
27+
FileUtils.makedirs(store_dir) if !::File.exist?(store_dir)
28+
return ::File.join(store_dir, UserMetaDataFile)
29+
end
30+
31+
2532
#######
2633
private
2734
#######
@@ -107,12 +114,6 @@ def configure_user_store
107114
return copied
108115
end
109116

110-
def get_user_store
111-
store_dir = ::File.join(Msf::Config.config_directory, "store")
112-
FileUtils.makedirs(store_dir) if !::File.exist?(store_dir)
113-
return ::File.join(store_dir, UserMetaDataFile)
114-
end
115-
116117
def load_cache_from_file_store
117118
cache_map = JSON.parse(File.read(@path_to_user_metadata))
118119
cache_map.each {|k,v|

plugins/fzuse.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def commands
4444
#
4545
def cmd_fzuse(*args)
4646
previewer = File.join(Msf::Config.install_root, 'tools', 'modules', 'print.py')
47+
metadata_path = Msf::Modules::Metadata::Cache.instance.get_user_store
4748

4849
module_types = framework.modules.module_types
4950

@@ -52,7 +53,7 @@ def cmd_fzuse(*args)
5253
selection = nil
5354
# alternative preview:
5455
# jq \'to_entries[] | select(.value.fullname == "{1}") | .value\' db/modules_metadata_base.json | bat --language=json --color=always
55-
stdin, stdout, stderr, wait_thr = Open3.popen3('fzf', '--select-1', '--query', query, '--preview', "#{previewer} {1}", '--preview-label', "Module Information") do |stdin, stdout, stderr, wait_thr|
56+
stdin, stdout, stderr, wait_thr = Open3.popen3('fzf', '--select-1', '--query', query, '--preview', "#{previewer} --metadata-path '#{metadata_path}' '{1}'", '--preview-label', "Module Information") do |stdin, stdout, stderr, wait_thr|
5657
module_types
5758
module_types.each do |module_type|
5859
framework.modules.module_names(module_type).each do |module_name|

tools/modules/print.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424

2525
framework_root = pathlib.Path(__file__).parent.parent.parent
26+
default_metadata_path = (framework_root / 'db' / 'modules_metadata_base.json')
2627

2728
def get_notes(module_metadata):
2829
tree = Tree('Notes', hide_root=True)
@@ -64,10 +65,11 @@ def get_bulleted_list(items):
6465
def main():
6566
parser = argparse.ArgumentParser(description='fzuse helper', conflict_handler='resolve')
6667
parser.add_argument('module_name', help='module name to display')
68+
parser.add_argument('--metadata-path', default=default_metadata_path, type=pathlib.Path, help='the path to the module metadata')
6769
parser.add_argument('-v', '--version', action='version', version='%(prog)s Version: ' + __version__)
6870
arguments = parser.parse_args()
6971

70-
with (framework_root / 'db' / 'modules_metadata_base.json').open('r') as file_h:
72+
with arguments.metadata_path.open('r') as file_h:
7173
all_metadata = json.load(file_h)
7274
module_metadata = next((metadata for metadata in all_metadata.values() if metadata['fullname'] == arguments.module_name), None)
7375
if not module_metadata:
@@ -84,7 +86,7 @@ def main():
8486
table.add_row('[bold]Rank[/bold]', RANKS[module_metadata['rank']])
8587
table.add_row('[bold]Disclosed[/bold]', module_metadata['disclosure_date'])
8688

87-
console = Console()
89+
console = Console(color_system='256')
8890
console.print(table)
8991

9092
panel_title = lambda v: f"[bold]{v}[/bold]"
@@ -96,8 +98,13 @@ def main():
9698
if module_metadata.get('references'):
9799
console.print(Panel(get_references(module_metadata), title=panel_title('References'), title_align='left'))
98100
if module_metadata.get('path', ''):
99-
syntax = Syntax.from_path(framework_root / module_metadata['path'][1:], background_color='default', line_numbers=True)
100-
console.print(Panel(syntax, title=panel_title('Source code'), title_align='left'))
101+
if pathlib.Path(module_metadata['path']).is_file():
102+
module_path = pathlib.Path(module_metadata['path'])
103+
elif pathlib.Path(framework_root / module_metadata['path'][1:]).is_file():
104+
module_path = pathlib.Path(framework_root / module_metadata['path'][1:])
105+
if module_path:
106+
syntax = Syntax.from_path(module_path, background_color='default', line_numbers=True)
107+
console.print(Panel(syntax, title=panel_title('Source code'), title_align='left'))
101108

102109
if __name__ == '__main__':
103110
main()

0 commit comments

Comments
 (0)