Nmap Development mailing list archives

Re: [RFC] NSE pack/unpack library


From: Sven Klemm <sven () c3d2 de>
Date: Sun, 03 Aug 2008 17:28:20 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

| I've started working on a NSE library for handling binary data,
| comparable to the perl pack/unpack functions. It's based on the
| lpack library and therefore it differs from perl's pack/unpack.
|
| Basically, there will be two functions, bin.pack and bin.unpack:
|
| bin.pack(template, arg1, arg2, ...)
| ... template is the format string (see below)
| ... argN are the data values, which should be packed, according to
the template
| --> returns a string with the packed data
|
| 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)
|
| The format string which lpack uses is a bit different to perl's,
| some operator characters stand for completely different things,
| but I modified as many as possible to match perl a bit more. Right
| now they are:
|
| 'Z' ... zero-terminated string
| 'p' ... string preceded by length byte
| 'P' ... string preceded by length word
| 'a' ... string preceded by length size_t

I think it's a bad idea to derive the size of the length from C data
types as these are machine dependant. It would probably be better to
use fixed byte sizes for the length. I would propose using 1 byte
length for 'p', 2 byte length for 'P' and 4 byte length for 'a'.

Currently bin.pack('a','') produces different results on 32-bit and
64-bit machines on linux.

Cheers,
Sven


- --
Sven Klemm
http://cthulhu.c3d2.de/~sven/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEUEARECAAYFAkiVzpQACgkQevlgTHEIT4aX/QCdF8XYaDmgVR/KFQMc1lV1/klR
ZeAAmMRsLcs/CmGuK1qcY6/4DhaeEvU=
=pXm0
-----END PGP SIGNATURE-----

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: