1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-08 05:31:31 +00:00

Use string.gsub instead of looped concat to modify strings

This commit is contained in:
dmiller
2015-02-27 14:55:29 +00:00
parent d16772a8a8
commit e275a96c72
5 changed files with 23 additions and 42 deletions

View File

@@ -86,11 +86,8 @@ Util = {
182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195, 182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195,
243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152 }; 243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152 };
local result = "" return 'A' .. string.gsub(password, ".",
for i = 1, #password do function(c) return string.char(shifts[c:byte()+1]) end)
result = result .. string.char(shifts[password:byte(i)+1])
end
return 'A' .. result
end end
} }

View File

@@ -751,13 +751,10 @@ StringUtil =
-- @param ascii string containing the ASCII value -- @param ascii string containing the ASCII value
-- @return string containing the EBCDIC value -- @return string containing the EBCDIC value
toEBCDIC = function( ascii ) toEBCDIC = function( ascii )
local ret = "" return string.gsub(ascii, ".", function(a)
local val = a:byte() + 1
for i=1, #ascii do return a2e_tbl:sub(val, val)
local val = ascii.byte(ascii,i) + 1 end)
ret = ret .. a2e_tbl:sub(val, val)
end
return ret
end, end,
--- Converts an EBCDIC string to ASCII --- Converts an EBCDIC string to ASCII
@@ -765,13 +762,10 @@ StringUtil =
-- @param ebcdic string containing EBCDIC value -- @param ebcdic string containing EBCDIC value
-- @return string containing ASCII value -- @return string containing ASCII value
toASCII = function( ebcdic ) toASCII = function( ebcdic )
local ret = "" return string.gsub(ebcdic, ".", function(e)
local val = e:byte() + 1
for i=1, #ebcdic do return e2a_tbl:sub(val, val)
local val = ebcdic.byte(ebcdic,i) + 1 end)
ret = ret .. e2a_tbl:sub(val, val)
end
return ret
end, end,
--- Pads a string with a character --- Pads a string with a character

View File

@@ -3064,15 +3064,13 @@ Auth = {
-- @return string containing the encrypted password -- @return string containing the encrypted password
TDS7CryptPass = function(password) TDS7CryptPass = function(password)
local xormask = 0x5a5a local xormask = 0x5a5a
local result = ""
for i=1, password:len() do return password:gsub(".", function(i)
local c = bit.bxor( string.byte( password:sub( i, i ) ), xormask ) local c = bit.bxor( string.byte( i ), xormask )
local m1= bit.band( bit.rshift( c, 4 ), 0x0F0F ) local m1= bit.band( bit.rshift( c, 4 ), 0x0F0F )
local m2= bit.band( bit.lshift( c, 4 ), 0xF0F0 ) local m2= bit.band( bit.lshift( c, 4 ), 0xF0F0 )
result = result .. bin.pack("S", bit.bor( m1, m2 ) ) return bin.pack("S", bit.bor( m1, m2 ) )
end end)
return result
end, end,
LmResponse = function( password, nonce ) LmResponse = function( password, nonce )

View File

@@ -101,13 +101,12 @@ function name_decode(encoded_name)
stdnse.debug3("Decoding name '%s'", encoded_name) stdnse.debug3("Decoding name '%s'", encoded_name)
for i = 2, len + 1, 2 do name = name:gsub("(.)(.)", function (a, b)
local ch = 0 local ch = 0
ch = bit.bor(ch, bit.lshift(string.byte(encoded_name, i) - 0x41, 4)) ch = bit.bor(ch, bit.lshift(string.byte(a) - 0x41, 4))
ch = bit.bor(ch, bit.lshift(string.byte(encoded_name, i + 1) - 0x41, 0)) ch = bit.bor(ch, bit.lshift(string.byte(b) - 0x41, 0))
return string.char(ch)
name = name .. string.char(ch) end)
end
-- Decode the scope -- Decode the scope
local pos = 34 local pos = 34

View File

@@ -1156,16 +1156,9 @@ end
-- returns the string with all non-printable chars -- returns the string with all non-printable chars
-- coded as hex -- coded as hex
function makeStringReadable(data) function makeStringReadable(data)
local r = "" return data:gsub("[\x00-\x1f\x7f-\xff]", function (x)
for i=1,#data,1 do return ("\\x%02x"):format(x:byte())
local x = data:byte(i) end)
if x > 31 and x <127 then
r = r .. data:sub(i,i)
else
r = r .. ("\\x%x"):format(x)
end
end
return r
end end
function readNonProxyDesc(dis) function readNonProxyDesc(dis)