From 5f23151c22f085603854d104ea498e71f573c33a Mon Sep 17 00:00:00 2001 From: HD Moore Date: Sun, 9 May 2010 02:58:55 +0000 Subject: [PATCH] Replace the core of the text generation methods; previously, these could result in an oddball string result that would not auto-convert into ASCII-8BIT. Looks like a strange corner case in Ruby 1.9 git-svn-id: file:///home/svn/framework3/trunk@9254 4d416f70-5f16-0410-b530-b9f4589650da --- lib/rex/text.rb | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/lib/rex/text.rb b/lib/rex/text.rb index 2f39ec7c6f..72b06a0540 100644 --- a/lib/rex/text.rb +++ b/lib/rex/text.rb @@ -463,7 +463,7 @@ module Text coords = [] (1 << str.size).times { |i| coords << ("%0#{str.size}b" % i) } mixed = [] - coords.each do |coord| + coords.each do |coord| c = coord.scan(/./).map {|x| x.to_i} this_str = "" c.each_with_index { |d,i| this_str << letters[i][d] } @@ -626,22 +626,11 @@ module Text # Base text generator method def self.rand_base(len, bad, *foo) - # Remove restricted characters - (bad || '').split('').each { |c| foo.delete(c) } - - # Return nil if all bytes are restricted - return nil if foo.length == 0 - - buff = "" - - # Generate a buffer from the remaining bytes - if foo.length >= 256 - len.times { buff << Kernel.rand(256) } - else - len.times { buff << foo[ rand(foo.length) ] } - end - - return buff + cset = (foo.join.unpack("C*") - bad.to_s.unpack("C*")).uniq + return if cset.length == 0 + outp = [] + len.times { outp << cset[rand(cset.length)] } + outp.pack("C*") end # Generate random bytes of data