Module: PWN::Plugins::FileFu
- Defined in:
- lib/pwn/plugins/file_fu.rb
Overview
This plugin is primarily used for interacting with files and directories in addition to the capabilities already built within the File and FileUtils built-in ruby classes (e.g. contains an easy to use recursion method that uses yield to interact with each entry on the fly).
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
-
0day Inc.
-
.help ⇒ Object
Display Usage for this Module.
-
.recurse_dir(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::FileFu.recurse_dir( dir_path: ‘optional path to dir defaults to .’ ).
-
.recurse_in_dir(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::FileFu.recurse_in_dir( dir_path: ‘optional path to dir defaults to .’ ).
-
.untar_gz_file(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::FileFu.untar_gz_file( tar_gz_file: ‘required - path to .tar.gz file’, destination: ‘required - destination folder to save extracted contents’ ).
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
71 72 73 74 75 |
# File 'lib/pwn/plugins/file_fu.rb', line 71 public_class_method def self. "AUTHOR(S): 0day Inc. <[email protected]> " end |
.help ⇒ Object
Display Usage for this Module
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/pwn/plugins/file_fu.rb', line 79 public_class_method def self.help puts "USAGE: #{self}.recurse_in_dir(dir_path: 'optional path to dir defaults to .') {|entry| puts entry} #{self}.recurse_dir(dir_path: 'optional path to dir defaults to .') {|entry| puts entry} #{self}.untar_gz_file( tar_gz_file: 'required - path to .tar.gz file', destination: 'required - destination folder to save extracted contents' ) #{self}.authors " end |
.recurse_dir(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::FileFu.recurse_dir(
dir_path: 'optional path to dir defaults to .'
)
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pwn/plugins/file_fu.rb', line 41 public_class_method def self.recurse_dir(opts = {}) dir_path = opts[:dir_path] ||= '.' dir_path = dir_path.to_s.scrub unless dir_path.is_a?(String) raise "PWN Error: Invalid Directory #{dir_path}" unless Dir.exist?(dir_path) # Execute this like this: # recurse_dir(:dir_path => 'path to dir') {|entry| puts entry} Dir.glob("#{dir_path}/**/*").each { |entry| yield Shellwords.escape(entry) } rescue StandardError => e raise e end |
.recurse_in_dir(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::FileFu.recurse_in_dir(
dir_path: 'optional path to dir defaults to .'
)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pwn/plugins/file_fu.rb', line 20 public_class_method def self.recurse_in_dir(opts = {}) dir_path = opts[:dir_path] ||= '.' dir_path = dir_path.to_s.scrub unless dir_path.is_a?(String) raise "PWN Error: Invalid Directory #{dir_path}" unless Dir.exist?(dir_path) previous_dir = Dir.pwd Dir.chdir(dir_path) # Execute this like this: # recurse_in_dir(:dir_path => 'path to dir') {|entry| puts entry} Dir.glob('./**/*').each { |entry| yield Shellwords.escape(entry) } rescue StandardError => e raise e ensure Dir.chdir(previous_dir) if Dir.exist?(previous_dir) end |
.untar_gz_file(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::FileFu.untar_gz_file(
tar_gz_file: 'required - path to .tar.gz file', destination: 'required - destination folder to save extracted contents'
)
59 60 61 62 63 64 65 66 67 |
# File 'lib/pwn/plugins/file_fu.rb', line 59 public_class_method def self.untar_gz_file(opts = {}) tar_gz_file = opts[:tar_gz_file].to_s.scrub if File.exist?(opts[:tar_gz_file].to_s.scrub) destination = opts[:destination].to_s.scrub if Dir.exist?(File.dirname(tar_gz_file)) puts `tar -xzvf #{tar_gz_file} -C #{destination}` nil rescue StandardError => e raise e end |