module Rex::Powershell

Constants

VERSION

Public Class Methods

make_subs(script, subs) click to toggle source

Insert substitutions into the powershell script If script is a path to a file then read the file otherwise treat it as the contents of a file

@param script [String] Script file or path to script @param subs [Array] Substitutions to insert

@return [String] Modified script file

# File lib/rex/powershell.rb, line 36
def self.make_subs(script, subs)
  if ::File.file?(script)
    script = ::File.read(script)
  end

  subs.each do |set|
    script.gsub!(set[0], set[1])
  end

  script
end
process_subs(subs) click to toggle source

Return an array of substitutions for use in make_subs

@param subs [String] A ; seperated list of substitutions

@return [Array] An array of substitutions

# File lib/rex/powershell.rb, line 54
def self.process_subs(subs)
  return [] if subs.nil? or subs.empty?
  new_subs = []
  subs.split(';').each do |set|
    new_subs << set.split(',', 2)
  end

  new_subs
end
read_script(script_path) click to toggle source

Reads script into a Powershell::Script

@param script_path [String] Path to the Script File

@return [Script] Powershell Script object

# File lib/rex/powershell.rb, line 23
def self.read_script(script_path)
  Rex::Powershell::Script.new(script_path)
end
to_powershell(str, name = "buf") click to toggle source

Converts a raw string to a powershell byte array

# File lib/rex/powershell.rb, line 67
def self.to_powershell(str, name = "buf")
  return Rex::Powershell::Script.to_byte_array(str, name)
end