Module: Ronin::Controls::Helpers::CommandExec

Defined in:
lib/ronin/controls/helpers/command_exec.rb

Instance Method Summary collapse

Instance Method Details

#cd(path) ⇒ String

Changes the current working directory of the shell.

Parameters:

  • path (String)

    The new current directory to use.

Returns:

  • (String)

    The new current directory.

Since:

  • 0.3.0



84
85
86
87
# File 'lib/ronin/controls/helpers/command_exec.rb', line 84

def cd(path)
  exec('cd',path)
  return path
end

#envHash

Returns The environment variables to use in the shell.

Returns:

  • (Hash)

    The environment variables to use in the shell.

Since:

  • 0.3.0



36
37
38
# File 'lib/ronin/controls/helpers/command_exec.rb', line 36

def env
  @env ||= {}
end

#exec(command, *arguments) ⇒ Object

Execute a given command with optional arguments.

Parameters:

  • command (String)

    The command to execute.

  • arguments (Array<String>)

    The additional command-line arguments to use with the command.

Raises:

Since:

  • 0.3.0



51
52
53
# File 'lib/ronin/controls/helpers/command_exec.rb', line 51

def exec(command,*arguments)
  raise(NotImplemented,"the exec method has not been implemented",caller)
end

#ls(*arguments) ⇒ Array

Lists the contents of a given directory or the current working directory.

Parameters:

  • arguments (Array)

    Additional command-line arguments.

Returns:

  • (Array)

    The contents of a directory.

Since:

  • 0.3.0



111
112
113
# File 'lib/ronin/controls/helpers/command_exec.rb', line 111

def ls(*arguments)
  exec('dir',*arguments).split(/\n\r?/)
end

#pwdString

Returns The current working directory of the shell.

Returns:

  • (String)

    The current working directory of the shell.

Since:

  • 0.3.0



95
96
97
# File 'lib/ronin/controls/helpers/command_exec.rb', line 95

def pwd
  exec('pwd').chomp
end

#sh(command, *args) ⇒ nil

Executes the specified command with the given arguments, and prints the output of the command.

Parameters:

  • command (String)

    The command to execute.

  • arguments (Array<String>)

    The additional command-line arguments to use with the command.

Returns:

  • (nil)

Since:

  • 0.3.0



69
70
71
# File 'lib/ronin/controls/helpers/command_exec.rb', line 69

def sh(command,*args)
  puts exec(command,*args)
end

#shellObject

Starts an interactive shell for running commands.



118
119
120
121
122
# File 'lib/ronin/controls/helpers/command_exec.rb', line 118

def shell
  UI::Shell.start(:prompt => '$') do |shell,line|
    sh(line)
  end
end