Method: Rex::Text.to_vbscript

Defined in:
lib/rex/text/lang.rb

.to_vbscript(str, name = "buf") ⇒ Object

Converts a raw string to a vbscript byte array



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rex/text/lang.rb', line 102

def self.to_vbscript(str, name = "buf")
  return "#{name}" if str.nil? or str.empty?

  code = str.unpack('C*')
  buff = "#{name}=Chr(#{code[0]})"
  1.upto(code.length-1) do |byte|
    if(byte % 100 == 0)
      buff << "\r\n#{name}=#{name}"
    end
    # exe is an Array of bytes, not a String, thanks to the unpack
    # above, so the following line is not subject to the different
    # treatments of String#[] between ruby 1.8 and 1.9
    buff << "&Chr(#{code[byte]})"
  end

  return buff
end