Class: PWN::Driver::Parser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/pwn/driver.rb

Overview

Add OptionParser options to PWN::Env

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pwn/driver.rb', line 13

def initialize
  super
  @opts = PWN::Env[:driver_opts]
  @auto_opts_help = true

  banner = "USAGE: #{File.basename($PROGRAM_NAME)} [opts]\n"
  on(
    '-YPATH',
    '--pwn_env=PATH',
    '<Optional - PWN::Env YAML file path (Default: ~/.pwn/pwn.yaml)>'
  ) do |o|
    @opts[:pwn_env_path] = o
  end
  on(
    '-ZPATH',
    '--pwn_dec=PATH',
    '<Optional - Out-of-Band YAML file path (Default: ~/.pwn/pwn.decryptor.yaml)>'
  ) do |o|
    @opts[:pwn_dec_path] = o
  end
end

Instance Attribute Details

#auto_opts_helpObject

Returns the value of attribute auto_opts_help.



10
11
12
# File 'lib/pwn/driver.rb', line 10

def auto_opts_help
  @auto_opts_help
end

#optsObject

Returns the value of attribute opts.



10
11
12
# File 'lib/pwn/driver.rb', line 10

def opts
  @opts
end

Instance Method Details

#parse!Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pwn/driver.rb', line 35

def parse!
  super(ARGV, into: @opts)
  # puts @opts

  PWN::Config.refresh_env(
    pwn_env_path: @opts[:pwn_env_path],
    pwn_dec_path: @opts[:pwn_dec_path]
  )

  if @auto_opts_help && @opts.keys.join(' ') == 'pwn_env_path pwn_dec_path'
    puts `#{File.basename($PROGRAM_NAME)} --help`
    exit 1
  end
end