lib/uirusu/cli/application.rb
def parse_options(args)
				begin
					@options['output']  = :stdout
					@options['verbose'] = false
					@options['rescan']  = false
					@options[:timeout]  = 25
					@options[:directory] = nil

					opt = OptionParser.new do |opt|
						opt.banner = "#{APP_NAME} v#{VERSION}\nJacob Hammack\nhttp://www.arxopia.com\n\n"
						opt.banner << "Usage: #{APP_NAME} <options>"
						opt.separator('')
						opt.separator('File Options')

						opt.on('-h HASH', '--search-hash HASH', 'Searches a single hash on virustotal.com') do |hash|
							@hashes.push(hash)
						end

						opt.on('-r HASH[,HASH]', '--rescan-hash HASH[,HASH]', 'Requests a rescan of a single hash, or multiple hashes (comma separated), by virustotal.com') do |hash|
							@options['rescan'] = true
							@hashes.push(hash)
						end

						opt.on('-f FILE', '--search-hash-file FILE', 'Searches a each hash in a file of hashes on virustotal.com') do |file|
							if File.exists?(file)
								puts "[+] Adding file #{file}" if @options['verbose']
								@files_of_hashes.push(file)
							else
								puts "[!] #{file} does not exist, please check your input!\n"
							end
						end

						opt.on('-u FILE', '--upload-file FILE', 'Uploads a file to virustotal.com for analysis') do |file|
							if File.exists?(file)
								puts "[+] Adding file #{file}" if @options['verbose']
								@uploads.push(file)
							else
								puts "[!] #{file} does not exist, please check your input!\n"
							end
						end

						opt.separator('')
						opt.separator("Url Options")

						opt.on('-s SITE', '--search-site SITE', 'Searches for a single url on virustotal.com') { |site|
							@sites.push(site)
						}

						opt.separator('')
						opt.separator('Output Options')

						opt.on('-j', '--json-output', 'Print results as json to stdout') do
							@options['output'] = :json
						end

						opt.on('-x', '--xml-output', 'Print results as xml to stdout') do
							@options['output'] = :xml
						end

						opt.on('-y', '--yaml-output', 'Print results as yaml to stdout') do
							@options['output'] = :yaml
						end

						opt.on('--stdout-output', 'Print results as normal text line to stdout, this is default') do
							@options['output'] = :stdout
						end

						opt.separator ''
						opt.separator 'Advanced Options'

						opt.on('-c', '--create-config', 'Creates a skeleton config file to use') do
							if File.exists?(File.expand_path(CONFIG_FILE)) == false
								File.open(File.expand_path(CONFIG_FILE), 'w+') do |f|
									f.write("virustotal: \n  api-key: \n  timeout: 25\n\n")
								end

								puts "[*] An empty #{File.expand_path(CONFIG_FILE)} has been created. Please edit and fill in the correct values."
								exit
							else
								puts "[!]  #{File.expand_path(CONFIG_FILE)} already exists. Please delete it if you wish to re-create it."
								exit
							end
						end

						opt.on('-d DIRECTORY', '--directory', 'Scans a directory recursively for files and submits the hashes') do |directory|
							@options[:directory] = directory
						end

						opt.on('-p PROXY', '--proxy-server', 'Uses a specified proxy server') do |proxy|
							@options['proxy'] = proxy
						end

						opt.on('--[no-]verbose', 'Print verbose information') do |v|
							@options['verbose'] = v
						end

						opt.separator ''
						opt.separator 'Other Options'

						opt.on('-v', '--version', 'Shows application version information') do
							puts "#{APP_NAME} - #{VERSION}"
							exit
						end

						opt.on_tail('-?', '--help', 'Show this message') { |help|
							puts opt.to_s + "\n"
							exit
						}
					end

				  if ARGV.length != 0
				    opt.parse!
				  else
				    puts opt.to_s + "\n"
					  exit
					end
				rescue OptionParser::MissingArgument => m
					puts opt.to_s + "\n"
					exit
				end
			end
# Parses the command the line options and returns the parsed options hash
#
# @return [Hash] of the parsed options
Parses the command the line options and returns the parsed options hash
Parses the command the line options and returns the parsed options hash
def parse_options(args)
				begin
					@options['output']  = :stdout
					@options['verbose'] = false
					@options['rescan']  = false
					@options[:timeout]  = 25
					@options[:directory] = nil
					opt = OptionParser.new do |opt|
						opt.banner = "#{APP_NAME} v#{VERSION}\nJacob Hammack\nhttp://www.arxopia.com\n\n"
						opt.banner << "Usage: #{APP_NAME} <options>"
						opt.separator('')
						opt.separator('File Options')
						opt.on('-h HASH', '--search-hash HASH', 'Searches a single hash on virustotal.com') do |hash|
							@hashes.push(hash)
						end
						opt.on('-r HASH[,HASH]', '--rescan-hash HASH[,HASH]', 'Requests a rescan of a single hash, or multiple hashes (comma separated), by virustotal.com') do |hash|
							@options['rescan'] = true
							@hashes.push(hash)
						end
						opt.on('-f FILE', '--search-hash-file FILE', 'Searches a each hash in a file of hashes on virustotal.com') do |file|
							if File.exists?(file)
								puts "[+] Adding file #{file}" if @options['verbose']
								@files_of_hashes.push(file)
							else
								puts "[!] #{file} does not exist, please check your input!\n"
							end
						end
						opt.on('-u FILE', '--upload-file FILE', 'Uploads a file to virustotal.com for analysis') do |file|
							if File.exists?(file)
								puts "[+] Adding file #{file}" if @options['verbose']
								@uploads.push(file)
							else
								puts "[!] #{file} does not exist, please check your input!\n"
							end
						end
						opt.separator('')
						opt.separator("Url Options")
						opt.on('-s SITE', '--search-site SITE', 'Searches for a single url on virustotal.com') { |site|
							@sites.push(site)
						}
						opt.separator('')
						opt.separator('Output Options')
						opt.on('-j', '--json-output', 'Print results as json to stdout') do
							@options['output'] = :json
						end
						opt.on('-x', '--xml-output', 'Print results as xml to stdout') do
							@options['output'] = :xml
						end
						opt.on('-y', '--yaml-output', 'Print results as yaml to stdout') do
							@options['output'] = :yaml
						end
						opt.on('--stdout-output', 'Print results as normal text line to stdout, this is default') do
							@options['output'] = :stdout
						end
						opt.separator ''
						opt.separator 'Advanced Options'
						opt.on('-c', '--create-config', 'Creates a skeleton config file to use') do
							if File.exists?(File.expand_path(CONFIG_FILE)) == false
								File.open(File.expand_path(CONFIG_FILE), 'w+') do |f|
									f.write("virustotal: \n  api-key: \n  timeout: 25\n\n")
								end
								puts "[*] An empty #{File.expand_path(CONFIG_FILE)} has been created. Please edit and fill in the correct values."
								exit
							else
								puts "[!]  #{File.expand_path(CONFIG_FILE)} already exists. Please delete it if you wish to re-create it."
								exit
							end
						end
						opt.on('-d DIRECTORY', '--directory', 'Scans a directory recursively for files and submits the hashes') do |directory|
							@options[:directory] = directory
						end
						opt.on('-p PROXY', '--proxy-server', 'Uses a specified proxy server') do |proxy|
							@options['proxy'] = proxy
						end
						opt.on('--[no-]verbose', 'Print verbose information') do |v|
							@options['verbose'] = v
						end
						opt.separator ''
						opt.separator 'Other Options'
						opt.on('-v', '--version', 'Shows application version information') do
							puts "#{APP_NAME} - #{VERSION}"
							exit
						end
						opt.on_tail('-?', '--help', 'Show this message') { |help|
							puts opt.to_s + "\n"
							exit
						}
					end
				  if ARGV.length != 0
				    opt.parse!
				  else
				    puts opt.to_s + "\n"
					  exit
					end
				rescue OptionParser::MissingArgument => m
					puts opt.to_s + "\n"
					exit
				end
			end
def parse_options ( args ) begin @options [ 'output' ] = :stdout @options [ 'verbose' ] = false @options [ 'rescan' ] = false @options [ :timeout ] = 25 @options [ :directory ] = nil opt = OptionParser . new do | opt | opt . banner = "#{APP_NAME} v#{VERSION}\nJacob Hammack\nhttp://www.arxopia.com\n\n" opt . banner << "Usage: #{APP_NAME} <options>" opt . separator ( '' ) opt . separator ( 'File Options' ) opt . on ( '-h HASH' , '--search-hash HASH' , 'Searches a single hash on virustotal.com' ) do | hash | @hashes . push ( hash ) end opt . on ( '-r HASH[,HASH]' , '--rescan-hash HASH[,HASH]' , 'Requests a rescan of a single hash, or multiple hashes (comma separated), by virustotal.com' ) do | hash | @options [ 'rescan' ] = true @hashes . push ( hash ) end opt . on ( '-f FILE' , '--search-hash-file FILE' , 'Searches a each hash in a file of hashes on virustotal.com' ) do | file | if File . exists? ( file ) puts "[+] Adding file #{file}" if @options [ 'verbose' ] @files_of_hashes . push ( file ) else puts "[!] #{file} does not exist, please check your input!\n" end end opt . on ( '-u FILE' , '--upload-file FILE' , 'Uploads a file to virustotal.com for analysis' ) do | file | if File . exists? ( file ) puts "[+] Adding file #{file}" if @options [ 'verbose' ] @uploads . push ( file ) else puts "[!] #{file} does not exist, please check your input!\n" end end opt . separator ( '' ) opt . separator ( "Url Options" ) opt . on ( '-s SITE' , '--search-site SITE' , 'Searches for a single url on virustotal.com' ) { | site | @sites . push ( site ) } opt . separator ( '' ) opt . separator ( 'Output Options' ) opt . on ( '-j' , '--json-output' , 'Print results as json to stdout' ) do @options [ 'output' ] = :json end opt . on ( '-x' , '--xml-output' , 'Print results as xml to stdout' ) do @options [ 'output' ] = :xml end opt . on ( '-y' , '--yaml-output' , 'Print results as yaml to stdout' ) do @options [ 'output' ] = :yaml end opt . on ( '--stdout-output' , 'Print results as normal text line to stdout, this is default' ) do @options [ 'output' ] = :stdout end opt . separator '' opt . separator 'Advanced Options' opt . on ( '-c' , '--create-config' , 'Creates a skeleton config file to use' ) do if File . exists? ( File . expand_path ( CONFIG_FILE ) ) == false File . open ( File . expand_path ( CONFIG_FILE ) , 'w+' ) do | f | f . write ( "virustotal: \n  api-key: \n  timeout: 25\n\n" ) end puts "[*] An empty #{File.expand_path(CONFIG_FILE)} has been created. Please edit and fill in the correct values." exit else puts "[!]  #{File.expand_path(CONFIG_FILE)} already exists. Please delete it if you wish to re-create it." exit end end opt . on ( '-d DIRECTORY' , '--directory' , 'Scans a directory recursively for files and submits the hashes' ) do | directory | @options [ :directory ] = directory end opt . on ( '-p PROXY' , '--proxy-server' , 'Uses a specified proxy server' ) do | proxy | @options [ 'proxy' ] = proxy end opt . on ( '--[no-]verbose' , 'Print verbose information' ) do | v | @options [ 'verbose' ] = v end opt . separator '' opt . separator 'Other Options' opt . on ( '-v' , '--version' , 'Shows application version information' ) do puts "#{APP_NAME} - #{VERSION}" exit end opt . on_tail ( '-?' , '--help' , 'Show this message' ) { | help | puts opt . to_s + "\n" exit } end if ARGV . length != 0 opt . parse! else puts opt . to_s + "\n" exit end rescue OptionParser :: MissingArgument => m puts opt . to_s + "\n" exit end end
Parses the command the line options and returns the parsed options hash
Parses the command the line options and returns the parsed options hash
of the parsed options
of the parsed options
Hash
args