Method: Rex::Text.to_vbscript

Defined in:
lib/rex/text.rb

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

Converts a raw string to a vbscript byte array



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/rex/text.rb', line 315

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