Changeset 5105
- Timestamp:
- 09/13/07 11:15:56 (1 year ago)
- Files:
-
- framework3/tags/framework-3.0/lib/rex/text.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
framework3/tags/framework-3.0/lib/rex/text.rb
r4883 r5105 210 210 # 211 211 def self.to_unicode(str='', type = 'utf-16le', mode = '', size = '') 212 return '' if not str 212 213 case type 213 214 when 'utf-16le' … … 329 330 } 330 331 return string 332 when 'uhwtfms-half' # suggested name from HD :P 333 load_codepage() 334 string = '' 335 # overloading mode as codepage 336 if mode == '' 337 mode = 1252 # ANSI - Latan 1, default for US installs of MS products 338 else 339 raise TypeError, "Invalid codepage #{mode}, only 1252 supported for uhwtfms_half" 340 end 341 str.each_byte {|byte| 342 if ((byte >= 33 && byte <= 63) || (byte >= 96 && byte <= 126)) 343 string += "\xFF" + [byte ^ 32].pack('C') 344 elsif (byte >= 64 && byte <= 95) 345 string += "\xFF" + [byte ^ 96].pack('C') 346 else 347 char = [byte].pack('C') 348 possible = $codepage_map_cache[mode]['data'][char] 349 if possible.nil? 350 raise TypeError, "codepage #{mode} does not provide an encoding for 0x#{char.unpack('H*')[0]}" 351 end 352 string += possible[ rand(possible.length) ] 353 end 354 } 355 return string 331 356 else 332 357 raise TypeError, 'invalid utf type' … … 372 397 end 373 398 return res 399 when 'u-half' 400 return str.gsub(all) { |s| Rex::Text.to_hex(Rex::Text.to_unicode(s, 'uhwtfms-half'), '%u', 2) } 374 401 else 375 402 raise TypeError, 'invalid mode' … … 428 455 429 456 chunk.unpack("C*").each do |c| 430 if (c > 0x1 9and c < 0x80)457 if (c > 0x1f and c < 0x80) 431 458 buf << c.chr 432 459 else … … 631 658 end 632 659 660 # Generate random bytes of numeric data 661 def self.rand_text_numeric(len, bad='') 662 foo = ('0' .. '9').to_a 663 rand_base(len, bad, *foo ) 664 end 665 633 666 # Generate random bytes of english-like data 634 667 def self.rand_text_english(len, bad='') … … 658 691 end 659 692 end 660 693 694 # Maximum permutations reached, but we need more data 695 if (buf.length < length) 696 buf = buf * (length / buf.length.to_f).ceil 697 end 698 661 699 buf[0,length] 662 700 end
