From 53a7ba2c6a35f261b5807a514cefc90ca819d2a1 Mon Sep 17 00:00:00 2001 From: pgpickering Date: Fri, 27 Jun 2008 20:27:38 +0000 Subject: [PATCH] added binlib documentation in scripting.xml --- docs/scripting.xml | 91 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/docs/scripting.xml b/docs/scripting.xml index 19cc1a353..ce00ee521 100644 --- a/docs/scripting.xml +++ b/docs/scripting.xml @@ -703,7 +703,7 @@ that. are often useful for low-level network communication, Reuben Thomas' bitwise operation library - for Lua has + for Lua has been integrated into NSE. The arguments to the bitwise operation functions should be integers. The number of bits available for logical operations depends on the data type used to @@ -808,6 +808,95 @@ that. + + Binary Data Handling + + A problem script authors often face is the necessity of encoding values + into binary data. For example after analyzing a protocol the starting + point to write a script could be a hex dump, which serves as a preamble + to every sent packet. Although it is possible work with the + functionality Lua provides, it's not very convenient. Therefore the + BinLib has been added to NSE, based on + lpack + by Luiz Henrique de Figueiredo. + + The BinLib functions take a format string to encode and decode binary + data. The operators of the format string are: + + + BinLib format string operators + + + + + Operator + Description + + + Hhex string + Bbit string + xnull byte + zzero-terminated string + pstring preceded by length byte + Pstring preceded by length word + astring preceded by length size_t + Astring + ffloat + ddouble + nLua number + cchar + Cbyte = unsigned char + sshort + Sunsigned short + iint + Iunsigned int + llong + Lunsigned long + <little endian modifier + >big endian modifier + =native endian modifier +
+ + Note that the endian operators work as modifiers to all that follows. + + + + + bin.pack(fmt, p1, ...) + + + Returns a binary packed string. The format string describes how + the parameters (p1, ...) will be interpreted. Numerical values following + operators stand for operator repetitions and need an according amount of + parameters. Operators expect appropriate parameter types. + + + + + + + + bin.unpack(fmt, data, [init]) + + + Returns values read from the binary data string. + First result is the position, at which unpack stopped. This can + be used as init value for subsequent calls. The following results + are the values according to the format string. Numerical values in + the format string are interpreted as repetitions like in pack, + except if used with A, B or H, in which cases the number tells unpack + how many bytes to read. + + Unpack stops if either the format string or the binary data string + are exhausted. + + + + +
+
+ + Perl Compatible Regular Expressions