mirror of
https://github.com/nmap/nmap.git
synced 2026-01-01 12:29:03 +00:00
o [NSE] Use a table to store the output results, and use table.concat()
to concat data instead of classic concatenation. This can have a huge performance boost, check this thread: http://seclists.org/nmap-dev/2011/q3/623
This commit is contained in:
@@ -479,9 +479,9 @@ local function format_output_sub(status, data, indent)
|
||||
-- Used to put 'ERROR: ' in front of all lines on error messages
|
||||
local prefix = ""
|
||||
-- Initialize the output string to blank (or, if we're at the top, add a newline)
|
||||
local output = ""
|
||||
local output = {}
|
||||
if(not(indent)) then
|
||||
output = '\n'
|
||||
insert(output, '\n')
|
||||
end
|
||||
|
||||
if(not(status)) then
|
||||
@@ -501,12 +501,18 @@ local function format_output_sub(status, data, indent)
|
||||
|
||||
if(data['name']) then
|
||||
if(data['warning'] and nmap.debugging() > 0) then
|
||||
output = output .. format("%s%s%s (WARNING: %s)\n", format_get_indent(indent), prefix, data['name'], data['warning'])
|
||||
insert(output, format("%s%s%s (WARNING: %s)\n",
|
||||
format_get_indent(indent), prefix,
|
||||
data['name'], data['warning']))
|
||||
else
|
||||
output = output .. format("%s%s%s\n", format_get_indent(indent), prefix, data['name'])
|
||||
insert(output, format("%s%s%s\n",
|
||||
format_get_indent(indent), prefix,
|
||||
data['name']))
|
||||
end
|
||||
elseif(data['warning'] and nmap.debugging() > 0) then
|
||||
output = output .. format("%s%s(WARNING: %s)\n", format_get_indent(indent), prefix, data['warning'])
|
||||
insert(output, format("%s%s(WARNING: %s)\n",
|
||||
format_get_indent(indent), prefix,
|
||||
data['warning']))
|
||||
end
|
||||
|
||||
for i, value in ipairs(data) do
|
||||
@@ -523,18 +529,20 @@ local function format_output_sub(status, data, indent)
|
||||
insert(new_indent, true)
|
||||
end
|
||||
|
||||
output = output .. format_output_sub(status, value, new_indent)
|
||||
insert(output, format_output_sub(status, value, new_indent))
|
||||
|
||||
elseif(type(value) == 'string') then
|
||||
local lines = splitlines(value)
|
||||
|
||||
for j, line in ipairs(lines) do
|
||||
output = output .. format_get_indent(indent, i == #data and j == #lines) .. " " .. prefix .. line .. "\n"
|
||||
insert(output, format("%s %s%s\n",
|
||||
format_get_indent(indent, i == #data and j == #lines),
|
||||
prefix, line))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return output
|
||||
return concat(output)
|
||||
end
|
||||
|
||||
---Takes a table of output on the commandline and formats it for display to the
|
||||
|
||||
Reference in New Issue
Block a user