move string utils into text

git-svn-id: file:///home/svn/incoming/trunk@3020 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Miller 2005-11-09 04:18:08 +00:00
parent 61456015da
commit 3b79fa0658
9 changed files with 32 additions and 50 deletions

View File

@ -9,7 +9,6 @@ require 'rex/exceptions'
require 'rex/transformer'
require 'rex/text'
require 'rex/time'
require 'rex/string_utils'
require 'rex/job_container'
require 'rex/file'

View File

@ -3,7 +3,7 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
require 'test/unit'
require 'rex/string_utils'
require 'rex/text'
require 'rex/arch/sparc'
class Rex::Arch::Sparc::UnitTest < ::Test::Unit::TestCase

View File

@ -117,7 +117,7 @@ module X86
#
def self.clear(reg, badchars = '')
_check_reg(reg)
opcodes = Rex::StringUtils.remove_badchars("\x29\x2b\x31\x33", badchars)
opcodes = Rex::Text.remove_badchars("\x29\x2b\x31\x33", badchars)
if opcodes.empty?
raise RuntimeError, "Could not find a usable opcode", caller()
end
@ -264,7 +264,7 @@ module X86
end
def self._check_badchars(data, badchars) # :nodoc:
idx = Rex::StringUtils.badchar_index(data, badchars)
idx = Rex::Text.badchar_index(data, badchars)
if idx
raise RuntimeError, "Bad character at #{idx}", caller()
end

View File

@ -3,7 +3,7 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
require 'test/unit'
require 'rex/string_utils'
require 'rex/text'
require 'rex/arch/x86'
class Rex::Arch::X86::UnitTest < ::Test::Unit::TestCase

View File

@ -1,7 +1,7 @@
#!/usr/bin/ruby
require 'rex/encoding/xor/exceptions'
require 'rex/string_utils'
require 'rex/text'
module Rex
module Encoding
@ -26,10 +26,10 @@ class Generic
return _check_key(key, badchars) || _check_encode(data, key, badchars)
end
def Generic._check_key(key, badchars)
return Rex::StringUtils.badchar_index(key, badchars)
return Rex::Text.badchar_index(key, badchars)
end
def Generic._check_encode(data, key, badchars)
return Rex::StringUtils.badchar_index(encode(data, key), badchars)
return Rex::Text.badchar_index(encode(data, key), badchars)
end
def Generic.find_key(data, badchars)

View File

@ -1,23 +0,0 @@
#!/usr/bin/ruby
module Rex
module StringUtils
#
# Return the index of the first badchar in data, otherwise return
# nil if there wasn't any badchar occurences.
#
def self.badchar_index(data, badchars)
badchars.each_byte { |badchar|
pos = data.index(badchar)
return pos if pos
}
return nil
end
def self.remove_badchars(data, badchars)
data.delete(badchars)
end
end end

View File

@ -1,19 +0,0 @@
#!/usr/bin/ruby
$:.unshift(File.join(File.dirname(__FILE__), '..'))
require 'test/unit'
require 'rex/string_utils'
class Rex::StringUtils::UnitTest < ::Test::Unit::TestCase
Klass = Rex::StringUtils
def klass
self.class::Klass
end
def test_badchar_index
assert_equal(nil, klass.badchar_index('abcdef', 'gzk'))
assert_equal(2, klass.badchar_index('123avd', 'ly3'))
end
end

View File

@ -304,5 +304,25 @@ module Text
str.gsub(/\n/m, ' ').gsub(/\s+/, ' ').gsub(/^\s+/, '').gsub(/\s+$/, '')
end
#
# Return the index of the first badchar in data, otherwise return
# nil if there wasn't any badchar occurences.
#
def self.badchar_index(data, badchars)
badchars.each_byte { |badchar|
pos = data.index(badchar)
return pos if pos
}
return nil
end
#
# This method removes bad characters from a string.
#
def self.remove_badchars(data, badchars)
data.delete(badchars)
end
end
end

View File

@ -7,6 +7,11 @@ require 'rex/text'
class Rex::Text::UnitTest < Test::Unit::TestCase
def test_badchar_index
assert_equal(nil, Rex::Text.badchar_index('abcdef', 'gzk'))
assert_equal(2, Rex::Text.badchar_index('123avd', 'ly3'))
end
def test_hexify
str = "\x01\x02\xff"