Nmap Development mailing list archives
Re: [nmap-svn] r33632 - in nmap: nselib scripts
From: Patrick Donnelly <batrick () batbytes com>
Date: Wed, 3 Sep 2014 10:44:34 -0400
On Wed, Sep 3, 2014 at 12:49 AM, <commit-mailer () nmap org> wrote:
Author: dmiller Date: Wed Sep 3 04:49:54 2014 New Revision: 33632 Log: 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
For future reference, Lua 5.2 offers the \z escape sequence which skips all whitespace characters following it in a literal string: http://www.lua.org/manual/5.2/manual.html#3.1 The escape sequence '\z' skips the following span of white-space characters, including line breaks; it is particularly useful to break and indent a long literal string into multiple lines without adding the newlines and spaces into the string contents. So for example:
[...]
Modified: nmap/scripts/db2-das-info.nse
==============================================================================
--- nmap/scripts/db2-das-info.nse (original)
+++ nmap/scripts/db2-das-info.nse Wed Sep 3 04:49:54 2014
@@ -266,12 +266,12 @@
packet.header = {}
- packet.header.raw = string.char(0x00, 0x00, 0x00, 0x00, 0x44, 0x42, 0x32, 0x44, 0x41, 0x53, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20)
- packet.header.raw = packet.header.raw .. string.char(0x01, 0x04, 0x00, 0x00, 0x00, 0x10, 0x39, 0x7a, 0x00, 0x05,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
- packet.header.raw = packet.header.raw .. string.char(0x00, 0x00, 0x00, 0x00 )
- packet.header.raw = packet.header.raw .. bin.pack("C", magic)
- packet.header.raw = packet.header.raw .. bin.pack("S", data_len)
- packet.header.raw = packet.header.raw .. string.char(0x00, 0x00)
+ packet.header.raw = "\x00\x00\x00\x00\x44\x42\x32\x44\x41\x53\x20\x20\x20\x20\x20\x20"
+ .. "\x01\x04\x00\x00\x00\x10\x39\x7a\x00\x05\x00\x00\x00\x00\x00\x00"
+ .. "\x00\x00\x00\x00"
+ .. bin.pack("C", magic)
+ .. bin.pack("S", data_len)
+ .. "\x00\x00"
packet.header.data_len = data_len
packet.data = data
could be:
packet.header.raw =
"\x00\x00\x00\x00\x44\x42\x32\x44\x41\x53\x20\x20\x20\x20\x20\x20\z
\x01\x04\x00\x00\x00\x10\x39\x7a\x00\x05\x00\x00\x00\x00\x00\x00\z
\x00\x00\x00\x00"
..bin.pack("C", magic)
..bin.pack("S", data_len)
.."\x00\x00"
[Unfortunately those bin.packs add some concatenations anyway but you
get the idea.]
--
Patrick Donnelly
_______________________________________________
Sent through the dev mailing list
http://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: [nmap-svn] r33632 - in nmap: nselib scripts Patrick Donnelly (Sep 03)
- Re: [nmap-svn] r33632 - in nmap: nselib scripts Daniel Miller (Sep 03)
