Method: Rex::Text.to_dword
- Defined in:
- lib/rex/text.rb
.to_dword(str, wrap = DefaultWrap) ⇒ Object
Creates a comma separated list of dwords
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/rex/text.rb', line 197 def self.to_dword(str, wrap = DefaultWrap) code = str alignnr = str.length % 4 if (alignnr > 0) code << "\x00" * (4 - alignnr) end codevalues = Array.new code.split("").each_slice(4) do |chars4| chars4 = chars4.join("") dwordvalue = chars4.unpack('*V') codevalues.push(dwordvalue[0]) end buff = "" 0.upto(codevalues.length-1) do |byte| if(byte % 8 == 0) and (buff.length > 0) buff << "\r\n" end buff << sprintf('0x%.8x, ', codevalues[byte]) end # strip , at the end buff = buff.chomp(', ') buff << "\r\n" return buff end |