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



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rex/text/lang.rb', line 160

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