mirror of
https://github.com/nmap/nmap.git
synced 2025-12-26 17:39:03 +00:00
Some string optimizations in NSE
Changes fall into these categories: 1. Avoid pathological string building. Loops over x = x .. "foo" can become very slow. Instead, use strbuf.lua, table.concat, or just one continuous concatenation; a = x .. y .. z is one operation, better than a = x .. y; a = a .. z 2. Use hex-escaped strings instead of string.char. I find this more readable in many cases, and it avoids a table lookup and function call. 3. Don't duplicate code. A few libraries and scripts had re-implemented stdnse.generate_random_string or openssl.rand_bytes.
This commit is contained in:
@@ -2459,14 +2459,14 @@ function file_upload(host, localfile, share, remotefile, overrides, encoded)
|
||||
|
||||
local i = 0
|
||||
local data = handle:read(chunk)
|
||||
local new_data = {}
|
||||
while(data ~= nil and #data > 0) do
|
||||
|
||||
if(encoded) then
|
||||
local new_data = ""
|
||||
for j = 1, #data, 1 do
|
||||
new_data = new_data .. string.char(bit.bxor(0xFF, string.byte(data, j)))
|
||||
new_data[j] = string.char(bit.bxor(0xFF, string.byte(data, j)))
|
||||
end
|
||||
data = new_data
|
||||
data = table.concat(new_data, "", 1, #data)
|
||||
end
|
||||
|
||||
status, err = write_file(smbstate, data, i)
|
||||
|
||||
Reference in New Issue
Block a user