Changed the way I do check. Before I forgot to check to make sure there was no bad characters in the key byte, and now I just moved everything over to a _check method, and allowed for some hooks that will be handy in the case of Sparc.pm

git-svn-id: file:///home/svn/incoming/trunk@2526 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Spoon M 2005-05-25 17:40:50 +00:00
parent bbbc15b7db
commit 37f8ef712c
3 changed files with 34 additions and 12 deletions

View File

@ -11,3 +11,4 @@ require 'Rex/Encoding/Xor/Generic.rb.ut'
require 'Rex/Encoding/Xor/Byte.rb.ut'
require 'Rex/Encoding/Xor/Word.rb.ut'
require 'Rex/Encoding/Xor/DWord.rb.ut'
require 'Rex/Encoding/Xor/DWordAdditive.rb.ut'

View File

@ -50,16 +50,6 @@ class DWordAdditive < Generic
# Maybe someday we can revisit this and make it a bit less ghetto...
#
# return nil if no badchars in data, otherwise return the position of
# the first bad character
def DWordAdditive._badchar_index(data, badchars)
badchars.each_byte { |badchar|
pos = data.index(badchar)
return pos if pos
}
return nil
end
def DWordAdditive._find_good_key(data, badkeys, badchars)
ksize = keysize
@ -78,7 +68,7 @@ class DWordAdditive < Generic
loop do
# ok, try to encode it, any bad chars present?
pos = _badchar_index(encode(data, key), badchars)
pos = _check(data, key, badchars)
# yay, no problems, we found a key!
break if !pos

View File

@ -13,6 +13,33 @@ class Generic
return 0
end
#
# return nil if no badchars in data, otherwise return the position of
# the first bad character
#
def Generic.badchar_index(data, badchars)
badchars.each_byte { |badchar|
pos = data.index(badchar)
return pos if pos
}
return nil
end
#
# Now for some internal check methods
#
# hook stylies!
# return index of offending byte or nil
def Generic._check(data, key, badchars)
return _check_key(key, badchars) || _check_encode(data, key, badchars)
end
def Generic._check_key(key, badchars)
return badchar_index(key, badchars)
end
def Generic._check_encode(data, key, badchars)
return badchar_index(encode(data, key), badchars)
end
def Generic.find_key(data, badchars)
return _find_good_key(data, _find_bad_keys(data, badchars), badchars)
end
@ -45,7 +72,6 @@ class Generic
#
# (Hopefully) find a good key, from badkeys and badchars
# this doesn't use data, but others may need it..
#
def Generic._find_good_key(data, badkeys, badchars)
@ -74,6 +100,11 @@ class Generic
strip += 1
end
# ok, we should have a good key now, lets double check...
if ! _check(data, key, badchars)
raise ArgumentError, "FIXME DIFF EXCEPTION", caller
end
return key
end