mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +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:
@@ -125,12 +125,12 @@ local function requestFileScan(filename)
|
||||
local shortfile = filename:match("^.*[\\/](.*)$")
|
||||
local boundary = "----------------------------nmapboundary"
|
||||
local header = { ["Content-Type"] = ("multipart/form-data; boundary=%s"):format(boundary) }
|
||||
local postdata = ("--%s\r\n"):format(boundary)
|
||||
postdata = postdata .. "Content-Disposition: form-data; name=\"apikey\"\r\n\r\n"
|
||||
postdata = postdata .. arg_apiKey .. "\r\n"
|
||||
postdata = postdata .. ("--%s\r\n" ..
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n" ..
|
||||
"Content-Type: text/plain\r\n\r\n%s\r\n--%s--\r\n"):format(boundary, shortfile, str, boundary)
|
||||
local postdata = ("--%s\r\n"
|
||||
.. 'Content-Disposition: form-data; name="apikey"\r\n\r\n'
|
||||
.. "%s\r\n"
|
||||
.. "--%s\r\n"
|
||||
.. 'Content-Disposition: form-data; name="file"; filename="%s"\r\n'
|
||||
.. "Content-Type: text/plain\r\n\r\n%s\r\n--%s--\r\n"):format(boundary, arg_apiKey, boundary, shortfile, str, boundary)
|
||||
|
||||
local host = "www.virustotal.com"
|
||||
local port = { number = 80, protocol = "tcp" }
|
||||
|
||||
Reference in New Issue
Block a user