1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-25 00:49:01 +00:00
Files
nmap/nselib/match.lua
david 7e15f259a4 Standardize the @copyright fields of NSE modules; change "See nmaps COPYING for
license" to "Same as Nmap--See http://nmap.org/book/man-legal.html" like
scripts commonly use. I added the field to some modules I know to be under the
Nmap license: bin, datafiles, dns, nmap, unpwdb. I left alone bin, bit, pcre,
and url, which come from outside sources.
2008-10-24 00:44:22 +00:00

54 lines
1.7 KiB
Lua

--- Buffered network I/O helper functions.
-- \n\n
-- The functions in this module can be used for delimiting data received
-- by the receive_buf function in the Network I/O API.
-- @copyright Same as Nmap--See http://nmap.org/book/man-legal.html
module(... or "match", package.seeall)
require "pcre"
--various functions for use with nse's nsock:receive_buf - function
-- e.g.
-- sock:receivebuf(regex("myregexpattern")) - does a match using pcre- regular-
-- - expressions
-- sock:receivebuf(numbytes(80)) - is the buffered version of
-- sock:receive_bytes(80) - i.e. it returns
-- exactly 80 bytes and no more
--- Return a function that allows delimiting with a regular expression.
-- \n\n
-- This function is a wrapper around the exec function of the pcre
-- library. It purpose is to give script developers the ability to use
-- regular expressions for delimiting instead of Lua's string patterns.
-- @param The regex.
-- @usage sock:receivebuf(regex("myregexpattern"))
regex = function(pattern)
local r = pcre.new(pattern, 0,"C")
return function(buf)
s,e = r:exec(buf, 0,0);
return s,e
end
end
--- Return a function that allows delimiting at a certain number of bytes.
-- \n\n
-- This function can be used to get a buffered version of
-- sockobj:receive_bytes(n) in case a script requires more than one
-- fixed-size chunk, as the unbuffered version may return more bytes
-- than requested and thus would require you to do the parsing on your
-- own.
-- @param num Number of bytes.
-- @usage sock:receivebuf(numbytes(80))
numbytes = function(num)
local n = num
return function(buf)
if(string.len(buf) >=n) then
return n, n
end
return nil
end
end