Home page logo

nmap-dev logo Nmap Development mailing list archives

Re: [RFC] NSE pack/unpack library
From: "Philip Pickering" <pgpickering () gmail com>
Date: Fri, 20 Jun 2008 02:08:19 +0200

2008/6/20 Brandon Enright <bmenrigh () ucsd edu>:
bin.unpack(bindata, template)
... bindata is a string with the packed binary data
... template is, again, the format string
--> returns the position where it stopped as first value and
the unpacked data values as the following return values
(the position can be used to subsequently fetch more data
by using it as a third parameter)

If I'm to understand this we'll have to unpack in a loop rather than
something like:

local a, b, c, d
(a, b, c, d) bin.unpack("C C C C", somestring)

you can still do

local a, b, c, d
_, a, b, c, d = bin.unpack(somestring, "C C C C")

but, for example, if your data begins with a short value for the
length of a following string you can do

pos, len = bin.unpack(somestring, "s")
_, newstring = bin.unpack(somestring, "A" .. len, pos)

Another thing I just realized is that bin.unpack's parameters are (data, format)
whereas perl's are (format, data). I guess I should adapt to Perl's way of
ordering it, because many people probably will be used to it (and I think it
doesn't really make a difference, which way round it is). It seems more
consistent, too, if the first parameter is the format string in both functions.

It sure would be nice to be able to get a list back rather than having
to do it in a loop.

Unpacking into a table could be an additional feature.

I like all your ideas here and I think this will be very useful.


Sent through the nmap-dev mailing list
Archived at http://SecLists.Org

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]